Skip to content

Commit

Permalink
Merge branch 'release/v202309.1113'
Browse files Browse the repository at this point in the history
  • Loading branch information
mpasternak committed Sep 10, 2023
2 parents ae043a9 + 7f4600c commit b41f0cd
Show file tree
Hide file tree
Showing 29 changed files with 849 additions and 251 deletions.
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
name: install postgresql-client
command: |
sudo apt install -y postgresql-client
psql --version
- run:
name: install stuff required to build python-ldap
Expand Down Expand Up @@ -59,6 +60,11 @@ jobs:
set | grep PG
createdb bpp
- run:
name: create pg_trgm extension
command: |
echo "create extension pg_trgm with schema pg_catalog;" | psql bpp
- checkout

- restore_cache:
Expand Down
9 changes: 9 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ Historia zmian

.. towncrier release notes start
Bpp 202309.1113 (2023-09-10)
============================

Usprawnienie
------------

- obsługa API v2 dla dyscyplin PBN (nowe-dyscypliny-pbn)


Bpp 202308.1112 (2023-08-31)
============================

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bpp-iplweb",
"version": "v202308.1112",
"version": "v202309.1113",
"devDependencies": {
"grunt": ">=1.5.2",
"grunt-contrib-qunit": "^2.0.0",
Expand Down
398 changes: 212 additions & 186 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bpp_iplweb"
version = "202308.1112"
version = "202309.1113"
description = ""
authors = ["Michał Pasternak <michal.dtz@gmail.com>"]
license = "MIT"
Expand Down Expand Up @@ -87,7 +87,7 @@ vcrpy = "4.4.0"
towncrier = "^22.8.0"

[tool.bumpver]
current_version = "v202308.1112"
current_version = "v202309.1113"
version_pattern = "vYYYY0M.BUILD[-TAGNUM][GITHASH]"
commit_message = "bump version {old_version} -> {new_version}"
commit = true
Expand Down Expand Up @@ -245,7 +245,7 @@ build-backend = "poetry.core.masonry.api"

[tool.towncrier]
package = "bpp"
version = "202308.1112"
version = "202309.1113"
package_dir = "src"
filename = "HISTORY.rst"

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def requirements(fn="requirements.txt"):

setup(
name="bpp-iplweb",
version="202308.1112",
version="202309.1113",
description="System informatyczny do zarządzania bibliografią publikacji pracowników naukowych",
long_description=readme,
long_description_content_type="text/x-rst",
Expand Down
32 changes: 22 additions & 10 deletions src/bpp/admin/dyscyplina_naukowa.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
# -*- encoding: utf-8 -*-

# -*- encoding: utf-8 -*-
from .core import RestrictDeletionToAdministracjaGroupMixin

from django.contrib import admin

from bpp.models import Dyscyplina_Naukowa
from .core import RestrictDeletionToAdministracjaGroupMixin


class Dyscyplina_NaukowaAdmin(RestrictDeletionToAdministracjaGroupMixin, admin.ModelAdmin):
list_display = ('kod', 'nazwa', 'dziedzina', 'widoczna') # Sane defaults.
class Dyscyplina_NaukowaAdmin(
RestrictDeletionToAdministracjaGroupMixin, admin.ModelAdmin
):
list_display = (
"kod",
"nazwa",
"dziedzina",
"widoczna",
"pbn_uid",
) # Sane defaults.

fields = None
search_fields = ('nazwa', 'kod',)
list_filter = ('widoczna',)

fields = ["nazwa", "kod", "widoczna", ]
search_fields = (
"nazwa",
"kod",
)
list_filter = ("widoczna",)

fields = [
"nazwa",
"kod",
"widoczna",
]
mptt_level_indent = 40


Expand Down
25 changes: 25 additions & 0 deletions src/bpp/migrations/0341_dyscyplina_naukowa_pbn_uid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.3 on 2023-09-10 09:51

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("pbn_api", "0037_alter_discipline_options_and_more"),
("bpp", "0340_skasuj_anonimowe_zdarzenia"),
]

operations = [
migrations.AddField(
model_name="dyscyplina_naukowa",
name="pbn_uid",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="pbn_api.discipline",
verbose_name="Odpowiednik w PBN",
),
),
]
8 changes: 8 additions & 0 deletions src/bpp/models/dyscyplina_naukowa.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ class Dyscyplina_Naukowa(models.Model):
nazwa = models.CharField(max_length=200, unique=True)
widoczna = models.BooleanField(default=True)

pbn_uid = models.ForeignKey(
"pbn_api.Discipline",
on_delete=models.SET_NULL,
verbose_name="Odpowiednik w PBN",
null=True,
blank=True,
)

def kod_dla_pbn(self):
a, b = (int(x) for x in self.kod.split(".", 1))
return int("%i%.2i" % (a, b))
Expand Down
2 changes: 2 additions & 0 deletions src/django_bpp/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
("Wydawcy", "/admin/pbn_api/publisher"),
("Naukowcy", "/admin/pbn_api/scientist"),
("Publikacje", "/admin/pbn_api/publication"),
("Słowniki dyscyplin", "/admin/pbn_api/disciplinegroup"),
("Dyscypliny", "/admin/pbn_api/discipline"),
# Chowamy publikacjie instytucji z menu - niech sobie zostaną dostępne z innego
# miejsca, ale nie są one generalnie potrzebne (mpasternak, 1.09.2021)
# ("Publikacje instytucji", "/admin/pbn_api/publikacjainstytucji"),
Expand Down
2 changes: 1 addition & 1 deletion src/django_bpp/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "202308.1112"
VERSION = "202309.1113"

if __name__ == "__main__":
import sys
Expand Down
93 changes: 79 additions & 14 deletions src/fixtures/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import os
import random
import time
from datetime import datetime
from datetime import datetime, timedelta
from uuid import uuid4

import django_webtest
import pytest
Expand All @@ -12,7 +13,10 @@
from rest_framework.test import APIClient
from splinter.driver import DriverAPI

from pbn_api.models import Language
from pbn_api.models import Discipline, Language
from pbn_api.models.discipline import DisciplineGroup

from django.utils import timezone

from bpp.models.szablondlaopisubibliograficznego import SzablonDlaOpisuBibliograficznego
from bpp.util import get_fixture
Expand Down Expand Up @@ -71,39 +75,100 @@ def rok():


@pytest.fixture
def dyscyplina1(db):
def pbn_discipline_group(db):
n = timezone.now().date()
return DisciplineGroup.objects.get_or_create(
uuid=uuid4(), validityDateTo=None, validityDateFrom=n - timedelta(days=7)
)[0]


@pytest.fixture
def pbn_dyscyplina1(db, pbn_discipline_group):
return Discipline.objects.get_or_create(
parent_group=pbn_discipline_group,
uuid=uuid4(),
code="301",
name="memetyka stosowana",
scientificFieldName="Dziedzina memetyk",
)[0]


@pytest.fixture
def dyscyplina1(db, pbn_dyscyplina1):
return Dyscyplina_Naukowa.objects.get_or_create(
nazwa="memetyka stosowana", kod="3.1"
nazwa="memetyka stosowana", kod="3.1", pbn_uid=pbn_dyscyplina1
)[0]


@pytest.fixture
def pbn_dyscyplina1_hst(db, pbn_discipline_group):
return Discipline.objects.get_or_create(
parent_group=pbn_discipline_group,
uuid=uuid4(),
code="701",
name="nauka teologiczna",
scientificFieldName="Dziedzina nauk teologicznych",
)[0]


@pytest.fixture
def dyscyplina1_hst(db):
def dyscyplina1_hst(db, pbn_dyscyplina1_hst):
return Dyscyplina_Naukowa.objects.get_or_create(
nazwa="nauka teologiczna",
kod="7.1",
nazwa="nauka teologiczna", kod="7.1", pbn_uid=pbn_dyscyplina1_hst
)[0]


@pytest.fixture
def dyscyplina2(db):
def pbn_dyscyplina2(db, pbn_discipline_group):
return Discipline.objects.get_or_create(
parent_group=pbn_discipline_group,
uuid=uuid4(),
code="202",
name="druga dyscyplina",
scientificFieldName="Dziedzina drugich dyscyplin",
)[0]


@pytest.fixture
def dyscyplina2(db, pbn_dyscyplina2):
return Dyscyplina_Naukowa.objects.get_or_create(
nazwa="druga dyscyplina", kod="2.2"
nazwa="druga dyscyplina", kod="2.2", pbn_uid=pbn_dyscyplina2
)[0]


@pytest.fixture
def pbn_dyscyplina2_hst(db, pbn_discipline_group):
return Discipline.objects.get_or_create(
parent_group=pbn_discipline_group,
uuid=uuid4(),
code="101",
name="nauka humanistyczna",
scientificFieldName="Dziedzina nauk humanistycznych",
)[0]


@pytest.fixture
def dyscyplina2_hst(db):
def dyscyplina2_hst(db, pbn_dyscyplina2_hst):
return Dyscyplina_Naukowa.objects.get_or_create(
nazwa="nauka humanistyczna",
kod="1.1",
nazwa="nauka humanistyczna", kod="1.1", pbn_uid=pbn_dyscyplina2_hst
)[0]


@pytest.fixture
def pbn_dyscyplina3(db, pbn_discipline_group):
return Discipline.objects.get_or_create(
parent_group=pbn_discipline_group,
uuid=uuid4(),
code="403",
name="trzecia dyscyplina",
scientificFieldName="Dziedzina trzecich dyscyplin",
)[0]


@pytest.fixture
def dyscyplina3(db):
def dyscyplina3(db, pbn_dyscyplina3):
return Dyscyplina_Naukowa.objects.get_or_create(
nazwa="trzecia dyscyplina", kod="4.3"
nazwa="trzecia dyscyplina", kod="4.3", pbn_uid=pbn_dyscyplina3
)[0]


Expand Down
39 changes: 35 additions & 4 deletions src/import_common/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ def matchuj_autora(
# aktualną...

if jednostka:

queries = [
Q(
Q(autor__nazwisko__iexact=nazwisko.strip())
Expand Down Expand Up @@ -284,7 +283,6 @@ def matchuj_wydawce(nazwa, pbn_uid_id=None, similarity=0.9):
pass

if pbn_uid_id is not None:

try:
return Wydawca.objects.get(pbn_uid_id=pbn_uid_id)
except Wydawca.DoesNotExist:
Expand Down Expand Up @@ -360,7 +358,6 @@ def matchuj_publikacje(
isbn_matchuj_tylko_nadrzedne=True,
doi_matchuj_tylko_nadrzedne=True,
):

if doi is not None:
doi = normalize_doi(doi)
if doi:
Expand Down Expand Up @@ -469,7 +466,6 @@ def matchuj_publikacje(
)
fail_if_seq_scan(res, DEBUG_MATCHOWANIE)
if res.exists():

if res.first().podobienstwo >= MATCH_SIMILARITY_THRESHOLD:
return res.first()

Expand Down Expand Up @@ -504,3 +500,38 @@ def matchuj_publikacje(
if res.exists():
if res.first().podobienstwo >= MATCH_SIMILARITY_THRESHOLD_LOW:
return res.first()


def normalize_kod_dyscypliny_pbn(kod):
if kod is None:
raise ValueError("kod = None")

if kod.find(".") == -1:
# Nie ma kropki, wiec juz znormalizowany
return kod

k1, k2 = (int(x) for x in kod.split(".", 2))
return f"{k1}{k2:02}"


def matchuj_dyscypline_pbn(kod, nazwa):
kod = normalize_kod_dyscypliny_pbn(kod)

from pbn_api.models import Discipline

from django.utils import timezone

d = timezone.now().date()
parent_group_args = Q(parent_group__validityDateFrom__lte=d), Q(
parent_group__validityDateTo=None
) | Q(parent_group__validityDateTo__gt=d)

try:
return Discipline.objects.get(*parent_group_args, code=kod)
except Discipline.DoesNotExist:
pass

try:
return Discipline.objects.get(*parent_group_args, name=nazwa)
except Discipline.DoesNotExist:
pass
1 change: 1 addition & 0 deletions src/pbn_api/adapters/wydawnictwo_autor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def pbn_get_json(self):

if self.original.dyscyplina_naukowa_id is not None and self.original.przypieta:
ret["disciplineId"] = self.original.dyscyplina_naukowa.kod_dla_pbn()
ret["disciplineUuid"] = str(self.original.dyscyplina_naukowa.pbn_uid.uuid)
else:
return

Expand Down
1 change: 1 addition & 0 deletions src/pbn_api/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .conference import * # noqa
from .discipline import * # noqa
from .institution import * # noqa
from .journal import * # noqa
from .monkeypatch_nowrap_foreignkey_admin import * # noqa
Expand Down

0 comments on commit b41f0cd

Please sign in to comment.