diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 76b21f04c..9435af816 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -18,7 +18,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} - name: Cache node modules @@ -34,12 +34,12 @@ jobs: - name: Run webpack build run: npm run build:prod - name: Upload built files - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: bundles path: bundles/ - name: Upload stats file - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: webpack-stats.json path: webpack-stats.json @@ -67,7 +67,7 @@ jobs: - name: Run Jest run: npx jest --collectCoverage - name: Upload test coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: flags: typescript @@ -115,19 +115,17 @@ 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@v3 + uses: actions/download-artifact@v4 with: name: webpack-stats.json @@ -140,7 +138,7 @@ jobs: run: py.test --cov=./ --cov-report=xml - name: Upload test coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: flags: python diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d7dace8b8..8562cb684 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,12 @@ CHANGELOG ========= +1.6.2 +----- + +* bugfix: add an option to prevent VIAF birth/death dates from being populated + on person record save when blank, so incorrect VIAF dates can be removed + 1.6.1 ----- diff --git a/README.rst b/README.rst index 7ab8ddcfa..9a94b9fec 100644 --- a/README.rst +++ b/README.rst @@ -36,31 +36,18 @@ 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:: - # 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:: @@ -83,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 @@ -118,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. @@ -129,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 @@ -162,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:: @@ -198,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 @@ -239,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 diff --git a/dev-requirements.txt b/dev-requirements.txt deleted file mode 100644 index aa23140ec..000000000 --- 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 c55be1bc0..f758ca7c7 100644 --- a/mep/__init__.py +++ b/mep/__init__.py @@ -1,10 +1,4 @@ -__version_info__ = (1, 6, 1, None) - - -# 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.6.2" # context processor to add version to the template environment diff --git a/mep/people/admin.py b/mep/people/admin.py index 3db29116b..3e6ee7bda 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", 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 000000000..d0931965d --- /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", + ), + ), + ] diff --git a/mep/people/models.py b/mep/people/models.py index 21c009bd2..a9ffb521c 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, @@ -537,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 a48607a3a..4cb2fc162 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() diff --git a/package-lock.json b/package-lock.json index 6cd5373f3..cb81498d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3603,11 +3603,11 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -5228,9 +5228,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -11500,9 +11500,9 @@ } }, "node_modules/ws": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.14.2.tgz", - "integrity": "sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==", + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", + "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", "dev": true, "engines": { "node": ">=10.0.0" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..4fd3b490c --- /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/pytest.ini b/pytest.ini deleted file mode 100644 index 7640c94cd..000000000 --- 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 diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 021c841f2..000000000 --- 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 diff --git a/srcmedia/scss/common/_header.scss b/srcmedia/scss/common/_header.scss index f1fe1dfe2..25f43a509 100644 --- a/srcmedia/scss/common/_header.scss +++ b/srcmedia/scss/common/_header.scss @@ -78,7 +78,7 @@ @include responsive-banner('/static/img/headers/SCo_banner_about'); } - &.analysis { + &.analysis, &.discoveries { @include responsive-banner('/static/img/headers/SCo_banner_anlys'); }