Skip to content

Commit

Permalink
Upgrade core to 0.27.0
Browse files Browse the repository at this point in the history
related to #144

WIP upgrading to the newest relations

chore: poetry update
  • Loading branch information
gythaogg committed Oct 14, 2024
1 parent dd19767 commit 3608a5f
Show file tree
Hide file tree
Showing 23 changed files with 364 additions and 393 deletions.
43 changes: 43 additions & 0 deletions apis_ontology/management/commands/find-subject-usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from django.core.management.base import BaseCommand
from apis_ontology.models import Subject, TibScholRelationMixin, TibScholEntityMixin


class Command(BaseCommand):
help = "Get a list entities and subjects that have a FK to a particular subject"

def add_arguments(self, parser):
parser.add_argument(
"subject_ids", nargs="+", type=int, help="list of subject IDs"
)

def handle(self, *args, **kwargs):
subject_ids = kwargs["subject_ids"]
if not subject_ids:
print("No subject IDs to investigate")

models = [
m
for m in (
TibScholRelationMixin.__subclasses__()
+ TibScholEntityMixin.__subclasses__()
)
if hasattr(m, "subject_vocab") or hasattr(m, "subject_of_teaching_vocab")
]
for subject_id in subject_ids:
try:
subject = Subject.objects.get(id=subject_id)
print(f"Subject: {subject_id}, {subject}")
for m in models:
field_name = (
"subject_vocab"
if hasattr(m, "subject_vocab")
else "subject_of_teaching_vocab"
)
# find instances of models that have subject in the "field_name" field
instances = m.objects.filter(**{field_name: subject})
for instance in instances:
print("\t", instance.pk, type(instance), instance)
except Subject.DoesNotExist:
self.stdout.write(
self.style.ERROR(f"Cannot find subject with ID - {subject_id}")
)
14 changes: 7 additions & 7 deletions apis_ontology/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def with_author(self):
return self.annotate(
# Subquery to get the Person ID related to the Work through PersonAuthorOfWork
author_id=Subquery(
PersonAuthorOfWork.objects.filter(obj_id=OuterRef("id")).values(
"subj_id"
PersonAuthorOfWork.objects.filter(obj_object_id=OuterRef("id")).values(
"subj_object_id"
)[:1]
),
# Subquery to get the Person's name based on the person_id from above
Expand Down Expand Up @@ -206,13 +206,13 @@ def with_author(self):
# Subquery to get the Person ID related to the Work through PersonAuthorOfWork
work_id=Subquery(
WorkHasAsAnInstanceInstance.objects.filter(
obj_id=OuterRef("id")
).values("subj_id")[:1]
obj_object_id=OuterRef("id")
).values("subj_object_id")[:1]
),
author_id=Subquery(
PersonAuthorOfWork.objects.filter(obj_id=OuterRef("work_id")).values(
"subj_id"
)[:1]
PersonAuthorOfWork.objects.filter(
obj_object_id=OuterRef("work_id")
).values("subj_object_id")[:1]
),
# Subquery to get the Person's name based on the person_id from above
author_name=Subquery(
Expand Down
2 changes: 0 additions & 2 deletions apis_ontology/settings/server_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
]

INSTALLED_APPS += [
"apis_highlighter",
"django.contrib.postgres",
"apis_core.collections",
"apis_core.history",
"django_action_logger",
"django_acdhch_functions",
"django_select2",
]
Expand Down
2 changes: 1 addition & 1 deletion apis_ontology/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class Meta(GenericTable.Meta):
"edit",
"delete",
]
exclude = ["view", "desc"]
exclude = ["desc"]

def render_support_notes(self, record):
notes = parse_comment(render_list_field(record.support_notes))
Expand Down
File renamed without changes.
File renamed without changes.
94 changes: 0 additions & 94 deletions apis_ontology/templatetags/relationsng.py

This file was deleted.

Loading

0 comments on commit 3608a5f

Please sign in to comment.