Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to override setting birth/death dates from VIAF #826

Merged
merged 8 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 15 additions & 30 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/pyenv/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::

Expand All @@ -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

Expand Down Expand Up @@ -118,7 +105,6 @@ docs <http://django-admin-tools.readthedocs.io/en/latest/dashboard.html#>`_.

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.
Expand All @@ -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
Expand Down Expand Up @@ -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 <http://doc.pytest.org/>`__ but use
Python unit tests are written with `py.test <http://doc.pytest.org/>`_ 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::

Expand Down Expand Up @@ -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 <https://github.com/psf/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 <FILE> --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

Expand Down Expand Up @@ -239,4 +224,4 @@ License
-------
This project is licensed under the `Apache 2.0 License <https://github.com/Princeton-CDH/mep-django/blob/main/LICENSE>`_.

©2020 Trustees of Princeton University. Permission granted via Princeton Docket #21-3743-1 for distribution online under a standard Open Source license.
©2024 Trustees of Princeton University. Permission granted via Princeton Docket #21-3743-1 for distribution online under a standard Open Source license.
9 changes: 0 additions & 9 deletions dev-requirements.txt

This file was deleted.

8 changes: 1 addition & 7 deletions mep/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion mep/people/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 20 additions & 0 deletions mep/people/migrations/0023_person_viaf_date_override.py
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
13 changes: 12 additions & 1 deletion mep/people/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand Down
9 changes: 9 additions & 0 deletions mep/people/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
88 changes: 88 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = ''
10 changes: 0 additions & 10 deletions pytest.ini

This file was deleted.

37 changes: 0 additions & 37 deletions requirements.txt

This file was deleted.

Loading