From 71a8a8fbab4f1346daeb8a61f562ef6ab0772fea Mon Sep 17 00:00:00 2001 From: nickmwangemi Date: Wed, 1 Nov 2023 20:06:44 +0300 Subject: [PATCH 1/2] Switch indigo api from v2 to v3 --- peachjam/adapters/adapters.py | 5 +++-- peachjam/views/legislation.py | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/peachjam/adapters/adapters.py b/peachjam/adapters/adapters.py index d672f4da7..7b8b91c23 100644 --- a/peachjam/adapters/adapters.py +++ b/peachjam/adapters/adapters.py @@ -395,8 +395,9 @@ def fetch_relationships(self, imported_document, created_document): object_work=amending_work, ) - if imported_document["commencements"]: - for commencement in imported_document["commencements"]: + commencements = created_document.commencements_json + if commencements: + for commencement in commencements: if ( commencement["commencing_frbr_uri"] and commencement["commencing_title"] diff --git a/peachjam/views/legislation.py b/peachjam/views/legislation.py index ae34da318..043d79a72 100644 --- a/peachjam/views/legislation.py +++ b/peachjam/views/legislation.py @@ -235,8 +235,7 @@ def get_timeline(self): # set publication_url publication_date = work.get("publication_date") if publication_date: - # TODO: update to v3 throughout - api_url = "https://api.laws.africa/v2/" + api_url = "https://api.laws.africa/v3/" commons_url = "https://commons.laws.africa/" publication_url = (work.get("publication_document") or {}).get("url") if publication_url and api_url in publication_url: From fb29f03b77b463b473762d7526f8ec045889b1f6 Mon Sep 17 00:00:00 2001 From: nickmwangemi Date: Thu, 2 Nov 2023 16:25:13 +0300 Subject: [PATCH 2/2] Data migration to update ingestor api url --- .../0108_update_ingestor_api_url.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 peachjam/migrations/0108_update_ingestor_api_url.py diff --git a/peachjam/migrations/0108_update_ingestor_api_url.py b/peachjam/migrations/0108_update_ingestor_api_url.py new file mode 100644 index 000000000..b170b3eea --- /dev/null +++ b/peachjam/migrations/0108_update_ingestor_api_url.py @@ -0,0 +1,26 @@ +# Generated by Django 3.2.19 on 2023-11-02 13:24 +from django.db import migrations + + +def update_ingestor_api_url(apps, schema_editor): + """Update the ingestor API URL to use the new API indigo v3.""" + Ingestor = apps.get_model("peachjam", "Ingestor") + IngestorSetting = apps.get_model("peachjam", "IngestorSetting") + + for ingestor in Ingestor.objects.all(): + setting = IngestorSetting.objects.filter( + ingestor=ingestor, name="api_url" + ).first() + if setting: + setting.value = "https://api.laws.africa/v3" + setting.save() + + +class Migration(migrations.Migration): + dependencies = [ + ("peachjam", "0107_delete_stubs_without_publication_documents"), + ] + + operations = [ + migrations.RunPython(update_ingestor_api_url, migrations.RunPython.noop) + ]