Skip to content

Commit

Permalink
auto-ingest system vocabs
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Nov 8, 2023
1 parent c64444a commit b4492c1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
6 changes: 5 additions & 1 deletion share/apps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from django.apps import AppConfig
from django.core import checks
from django.db.models.signals import post_migrate
from share.signals import post_migrate_load_sources
from share.signals import (
post_migrate_load_sources,
post_migrate_ingest_vocabs,
)
from share.checks import check_all_index_strategies_current


Expand All @@ -10,4 +13,5 @@ class ShareConfig(AppConfig):

def ready(self):
post_migrate.connect(post_migrate_load_sources, sender=self)
post_migrate.connect(post_migrate_ingest_vocabs, sender=self)
checks.register(check_all_index_strategies_current)
4 changes: 4 additions & 0 deletions share/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ def post_migrate_load_sources(sender, **kwargs):
except ProgrammingError:
return
management.call_command('loadsources')


def post_migrate_ingest_vocabs(sender, **kwargs):
management.call_command('ingest_rdf_vocabs')
20 changes: 13 additions & 7 deletions trove/management/commands/ingest_rdf_vocabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
from share.models import ShareUser
from share.management.commands import BaseShareCommand
from trove import digestive_tract
from trove import models as trove_db
from trove.vocab import VOCAB_SET


def ingest_vocabs(system_user: ShareUser):
for _vocab in VOCAB_SET:
digestive_tract.swallow(
from_user=system_user,
record=_vocab.turtle(),
record_identifier=_vocab.turtle_filename,
record_mediatype='text/turtle',
focus_iri=_vocab.turtle_focus_iri,
)
if not ( # if any system vocabs are updated, need to change this
trove_db.ResourceIdentifier.objects
.queryset_for_iri(_vocab.turtle_focus_iri)
.exists()
):
digestive_tract.swallow(
from_user=system_user,
record=_vocab.turtle(),
record_identifier=_vocab.turtle_filename,
record_mediatype='text/turtle',
focus_iri=_vocab.turtle_focus_iri,
)


class Command(BaseShareCommand):
Expand Down

0 comments on commit b4492c1

Please sign in to comment.