From 479cc816351cebbe4bc0ac91379ccd9078019d81 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Mon, 12 Aug 2024 12:24:25 -0400 Subject: [PATCH 1/8] Add boolean field to override setting birth/death date from viaf on save ref #824 --- mep/people/models.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mep/people/models.py b/mep/people/models.py index 21c009bd..8efafb07 100644 --- a/mep/people/models.py +++ b/mep/people/models.py @@ -449,6 +449,12 @@ class Person(TrackChangesModel, Notable, DateRange, ModelIndexable): birth_year = AliasIntegerField(db_column="start_year", blank=True, null=True) #: death year death_year = AliasIntegerField(db_column="end_year", blank=True, null=True) + #: override for setting dates from viaf + viaf_date_override = models.BooleanField( + "VIAF override", + default=False, + help_text="Do not set birth/death date from VIAF on save", + ) #: flag to indicate organization instead of person is_organization = models.BooleanField( default=False, From 0c308b56758b253dde26cece32e0d62195aeed9f Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Mon, 12 Aug 2024 12:26:33 -0400 Subject: [PATCH 2/8] Make viaf override checkbox available in admin ref #824 --- mep/people/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mep/people/admin.py b/mep/people/admin.py index 3db29116..3e6ee7bd 100644 --- a/mep/people/admin.py +++ b/mep/people/admin.py @@ -231,7 +231,7 @@ class PersonAdmin(admin.ModelAdmin): ("slug", "mep_id"), ("has_account", "in_logbooks", "has_card", "is_creator"), "viaf_id", - ("birth_year", "death_year"), + ("birth_year", "death_year", "viaf_date_override"), "gender", "profession", "nationalities", From e4c11241960d71a1d76998526c122c83236031c9 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Mon, 12 Aug 2024 13:17:57 -0400 Subject: [PATCH 3/8] Skip setting dates from viaf when override flag is set ref #824 --- mep/people/models.py | 7 ++++++- mep/people/tests/test_models.py | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/mep/people/models.py b/mep/people/models.py index 8efafb07..a9ffb521 100644 --- a/mep/people/models.py +++ b/mep/people/models.py @@ -543,13 +543,18 @@ class Meta: def save(self, *args, **kwargs): """Adds birth and death dates if they aren't already set - and there's a viaf id for the record""" + and there's a viaf id for the record; keep a record of + past person slugs when a person slug has changed""" + # set birth and death date if VIAF id is set and birth year and death + # year are NOT set; UNLESS skip viaf lookup config or + # viaf date override are true if ( not getattr(settings, "SKIP_VIAF_LOOKUP", False) and self.viaf_id and not self.birth_year and not self.death_year + and not self.viaf_date_override ): self.set_birth_death_years() diff --git a/mep/people/tests/test_models.py b/mep/people/tests/test_models.py index a48607a3..4cb2fc16 100644 --- a/mep/people/tests/test_models.py +++ b/mep/people/tests/test_models.py @@ -191,6 +191,15 @@ def test_save(self): pers.save() mock_setbirthdeath.assert_called_with() + # viaf set, no dates, and date override set to true + # - should NOT call + pers.viaf_date_override = True + pers.birth_year = None + pers.death_year = None + mock_setbirthdeath.reset_mock() + pers.save() + mock_setbirthdeath.assert_not_called() + # should lookup normally, but configured to skip with override_settings(SKIP_VIAF_LOOKUP=True): mock_setbirthdeath.reset_mock() From b91ace8efa32dc960a1ab19b3028841f7f065fa1 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Tue, 13 Aug 2024 11:06:21 -0400 Subject: [PATCH 4/8] Use pyproject for python requirements so dev versions don't override --- README.rst | 5 +-- dev-requirements.txt | 9 ----- mep/__init__.py | 8 +--- pyproject.toml | 88 ++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 37 ------------------- 5 files changed, 91 insertions(+), 56 deletions(-) delete mode 100644 dev-requirements.txt create mode 100644 pyproject.toml delete mode 100644 requirements.txt diff --git a/README.rst b/README.rst index 7ab8ddcf..c8a56bed 100644 --- a/README.rst +++ b/README.rst @@ -58,9 +58,8 @@ Initial setup and installation: - Install required python dependencies:: - # install requirements - pip install -r dev-requirements.txt - pip install -r requirements.txt + # install python dependencies, including dev dependencies + pip install -e '.[dev]' - Install javascript dependencies:: diff --git a/dev-requirements.txt b/dev-requirements.txt deleted file mode 100644 index aa23140e..00000000 --- a/dev-requirements.txt +++ /dev/null @@ -1,9 +0,0 @@ -pytest>=5 -pytest-django>=3.4.7 -pytest-cov -pytest-ordering -django-debug-toolbar -sphinx -wheel -pre-commit -wagtail-factories \ No newline at end of file diff --git a/mep/__init__.py b/mep/__init__.py index 7d413e1a..c99688b4 100644 --- a/mep/__init__.py +++ b/mep/__init__.py @@ -1,10 +1,4 @@ -__version_info__ = (1, 7, 0, "dev") - - -# Dot-connect all but the last. Last is dash-connected if not None. -__version__ = ".".join([str(i) for i in __version_info__[:-1]]) -if __version_info__[-1] is not None: - __version__ += "-%s" % (__version_info__[-1],) +__version__ = "1.7.0.dev0" # context processor to add version to the template environment diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..4fd3b490 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,88 @@ +[build-system] +requires = ["setuptools", "setuptools-scm"] +build-backend = "setuptools.build_meta" + +[project] +name = "mep-django" +description = "Shakespeare and Company Project - Python/Django web application" +requires-python = ">=3.9" +license = {text = "Apache-2"} +classifiers = [ + "Programming Language :: Python :: 3", +] +dependencies = [ + "Django>=3.2.4,<4.0", + "django-grappelli>=3.0", + "cached_property", + "django-cas-ng", + "pucas>=0.8", + "eulxml>=1.1.3", + "viapy>=0.3", + "wagtail>=5.1,<5.2", + "django-autocomplete-light>=3.9", + "python-dateutil", + "django-apptemplates", + "py-flags", + "django-tabular-export", + "django-webpack-loader<=2.0", + "parasolr>=0.9.2", + "django-widget-tweaks", + # pymarc api changes significantly in 5.0 + "pymarc<5.0", + "progressbar2", + "rdflib>=6.0", + "djiffy>=0.6", + "django-csp", + "bleach", + "django-fullurl", + "unidecode", + "stop_words", + # as of 2024-05-08 django-markdownify==0.9.4 causes an error with bleach + "django-markdownify==0.9.3", + "tweepy", + # specify bs4 version to avoid wagtail version conflict + "beautifulsoup4<4.9", + "psycopg2-binary", + # TODO: unpin piffle from 0.4 once breaking changes with piffle.iiif are handled in djiffy + "piffle==0.4", + # 4.0 is not compatible with django 3.2, so pin to pre 4.0 + "django-import-export<4.0", + "django-adminlogentries" +] +dynamic = ["version", "readme"] + +[tool.setuptools] +packages = ["mep"] + +[tool.setuptools.dynamic] +version = {attr = "mep.__version__"} +readme = {file = ["README.rst"]} + +[project.optional-dependencies] +dev = [ + "pytest>=5", + "pytest-django>=3.4.7", + "pytest-cov", + "pytest-ordering", + # pin to pre 4.4, which forces django 4.2 + "django-debug-toolbar<=4.4", + "sphinx", + "wheel", + "pre-commit", + "wagtail-factories<4.1", +] + +[tool.pytest.ini_options] +DJANGO_SETTINGS_MODULE="mep.settings" +# look for tests in standard django test location +python_files = ["mep/**/tests.py", "mep/**/tests/*.py"] +addopts = "-p parasolr.django.disconnect_indexing" +# limit testpath to speed up collecting step +testpaths = "mep" +markers = ["last", "second_to_last"] + +[tool.black] +line-length = 88 +target-version = ['py39'] +# include = '' +# extend-exclude = '' diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 021c841f..00000000 --- a/requirements.txt +++ /dev/null @@ -1,37 +0,0 @@ -Django>=3.2.4,<4.0 -django-grappelli>=3.0 -cached_property -django-cas-ng -pucas>=0.8 -eulxml>=1.1.3 -viapy>=0.3 -wagtail>=5.1,<5.2 -django-autocomplete-light>=3.9 -python-dateutil -django-apptemplates -py-flags -django-tabular-export -django-webpack-loader<=2.0 -parasolr>=0.9.2 -django-widget-tweaks -# pymarc api changes significantly in 5.0 -pymarc<5.0 -progressbar2 -rdflib>=6.0 -djiffy>=0.6 -django-csp -bleach -django-fullurl -unidecode -stop_words -# as of 2024-05-08 django-markdownify==0.9.4 causes an error with bleach -django-markdownify==0.9.3 -tweepy -# specify bs4 version to avoid wagtail version conflict -beautifulsoup4<4.9 -psycopg2-binary -# TODO: unpin piffle from 0.4 once breaking changes with piffle.iiif are handled in djiffy -piffle==0.4 -# 4.0 is not compatible with django 3.2, so pin to pre 4.0 -django-import-export<4.0 -django-adminlogentries \ No newline at end of file From ce7ea1233672208edca56494b3510d07ef1cd409 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Tue, 13 Aug 2024 11:06:52 -0400 Subject: [PATCH 5/8] Moved pytest configuration to pyproject --- pytest.ini | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 7640c94c..00000000 --- a/pytest.ini +++ /dev/null @@ -1,10 +0,0 @@ -[pytest] -DJANGO_SETTINGS_MODULE=mep.settings -# look for tests in standard django test location -python_files = "mep/**/tests.py" "mep/**/tests/*.py" -addopts = -p parasolr.django.disconnect_indexing -# limit testpath to speed up collecting step -testpaths = mep -markers = - last - second_to_last From ba50c3c4bb422245b99ddfbc814a8abfa097a7ac Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Tue, 13 Aug 2024 11:26:32 -0400 Subject: [PATCH 6/8] Clean up readme --- README.rst | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/README.rst b/README.rst index c8a56bed..9a94b9fe 100644 --- a/README.rst +++ b/README.rst @@ -36,25 +36,13 @@ Development instructions Initial setup and installation: -- recommended: create and activate a python 3.9 virtual environment. Using pyenv: +- Recommended: create and activate a python virtual environment using the +python version in `.python-version` using `pyenv `_. - # if pyenv is not installed - curl https://pyenv.run | bash - - # get recommended python version - vnum=$(cat .python-version) - - # install that version - pyenv install $vnum - - # activate it - pyenv shell $num - - # create virtual environmnt - python -m venv venv - - # activate virtual environment - . venv/bin/activate + - `pyenv install` will install the specified version of python, if needed; + `pyenv local` will report the configured version + - Run `python -m venv env` to create a new virtual environment named `env` + - `source env/bin/activate` to activate the virtual environment - Install required python dependencies:: @@ -82,7 +70,7 @@ Remember to add a ``SECRET_KEY`` setting! The manage command will automatically reload the core to ensure schema changes take effect. -- Run the migrations +- Run the migrations:: python manage.py migrate @@ -117,7 +105,6 @@ docs `_. If you make changes to js or scss files and need to rebuild static assets:: - npm run build:qa This will compile and minify all assets to ``static/`` with sourcemaps. @@ -128,7 +115,6 @@ Alternatively, to run a production build without sourcemaps, you can use:: Finally, for iterative frontend development, you can activate a webpack dev server with hot reload using:: - npm start Switching between the webpack dev server and serving from ``static/`` requires a @@ -161,11 +147,11 @@ You will also need to configure Django to use the Solr instance in Unit Tests ---------- -Python unit tests are written with `py.test `__ but use +Python unit tests are written with `py.test `_ but use Django fixture loading and convenience testing methods when that makes things easier. To run them, first install development requirements:: - pip install -r dev-requirements.txt + pip install -e '.[dev]' Run tests using py.test:: @@ -197,17 +183,17 @@ debug toolbar, so you'll probably want to turn it off. Setup pre-commit hooks ~~~~~~~~~~~~~~~~~~~~~~ -If you plan to contribute to this repository, please run the following command: +If you plan to contribute to this repository, please run the following command:: pre-commit install This will add a pre-commit hook to automatically format python code with `black `_. -Because these styling conventions were instituted after multiple releases of development on this project, ``git blame`` may not reflect the true author of a given line. In order to see a more accurate ``git blame`` execute the following command: +Because these styling conventions were instituted after multiple releases of development on this project, ``git blame`` may not reflect the true author of a given line. In order to see a more accurate ``git blame`` execute the following command:: git blame --ignore-revs-file .git-blame-ignore-revs -Or configure your git to always ignore styling revision commits: +Or configure your git to always ignore styling revision commits:: git config blame.ignoreRevsFile .git-blame-ignore-revs @@ -238,4 +224,4 @@ License ------- This project is licensed under the `Apache 2.0 License `_. -©2020 Trustees of Princeton University. Permission granted via Princeton Docket #21-3743-1 for distribution online under a standard Open Source license. \ No newline at end of file +©2024 Trustees of Princeton University. Permission granted via Princeton Docket #21-3743-1 for distribution online under a standard Open Source license. \ No newline at end of file From e5c408d5a680b5bfcb2b1758c40fce6f95edd7b4 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Tue, 13 Aug 2024 11:29:23 -0400 Subject: [PATCH 7/8] Update pip install for unit tests to use pyproject.toml --- .github/workflows/unit_tests.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index e0792eab..9435af81 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -115,16 +115,14 @@ jobs: uses: actions/cache@v4 with: path: ~/.cache/pip - key: pip-${{ matrix.python }}-${{ hashFiles('requirements.txt') }} + key: pip-${{ matrix.python }}-${{ hashFiles('pyproject.toml') }} restore-keys: | - pip-${{ matrix.python }}-${{ hashFiles('requirements.txt') }} + pip-${{ matrix.python }}-${{ hashFiles('pyproject.toml') }} pip-${{ matrix.python }} pip- - - name: Install dependencies - run: | - pip install -r requirements.txt - pip install -r dev-requirements.txt + - name: Install python dependencies + run: pip install -e '.[dev]' - name: Download webpack stats uses: actions/download-artifact@v4 From f9d7889739c3f10fb249b586a13d59e1274f2387 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Tue, 13 Aug 2024 11:34:56 -0400 Subject: [PATCH 8/8] Add migration for viaf date override to version control --- .../0023_person_viaf_date_override.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 mep/people/migrations/0023_person_viaf_date_override.py diff --git a/mep/people/migrations/0023_person_viaf_date_override.py b/mep/people/migrations/0023_person_viaf_date_override.py new file mode 100644 index 00000000..d0931965 --- /dev/null +++ b/mep/people/migrations/0023_person_viaf_date_override.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.20 on 2024-08-12 15:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("people", "0022_populate_birth_death_dates_from_viaf"), + ] + + operations = [ + migrations.AddField( + model_name="person", + name="viaf_date_override", + field=models.BooleanField( + default=False, + help_text="Check this to disable VIAF birth/death date lookup on save", + ), + ), + ]