Skip to content

Commit

Permalink
Merge pull request #1512 from laws-africa/taxonomytopic
Browse files Browse the repository at this point in the history
Taxonomy topics from indigo adapter
  • Loading branch information
actlikewill authored Sep 13, 2023
2 parents 364b60b + 94a6114 commit d788cb2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions peachjam/adapters/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
Author,
CoreDocument,
DocumentNature,
DocumentTopic,
GenericDocument,
LegalInstrument,
Legislation,
Locality,
Predicate,
Relationship,
Taxonomy,
Work,
)
from peachjam.plugins import plugins
Expand Down Expand Up @@ -87,6 +89,7 @@ def __init__(self, settings):
}
)
self.api_url = self.settings["api_url"]
self.taxonomy_topic_root = self.settings.get("taxonomy_topic_root")

def check_for_updates(self, last_refreshed):
"""Checks for documents updated since last_refreshed (which may be None), and returns a list
Expand Down Expand Up @@ -290,6 +293,28 @@ def update_document(self, url):
# the source file is the PDF version
self.download_source_file(f"{url}.pdf", created_doc, title)

if self.taxonomy_topic_root:
# clear any existing taxonomies
created_doc.taxonomies.filter(
topic__slug__startswith=self.taxonomy_topic_root
).delete()

if document["taxonomy_topics"]:
# get topics beginning with "subject-areas"
topics = [
t
for t in document["taxonomy_topics"]
if t.startswith(self.taxonomy_topic_root)
]
if topics:
taxonomies = Taxonomy.objects.filter(slug__in=topics)
for taxonomy in taxonomies:
DocumentTopic.objects.create(
document=created_doc,
topic=taxonomy,
)
logger.info(f"Added {len(taxonomies)} taxonomies to {created_doc}")

self.set_parent(document, created_doc)
self.fetch_relationships(document, created_doc)

Expand Down

0 comments on commit d788cb2

Please sign in to comment.