Skip to content

Commit

Permalink
Bugfix: add subjects to the vocab field
Browse files Browse the repository at this point in the history
in relations
  • Loading branch information
gythaogg committed Jul 3, 2024
1 parent b92121b commit 08c6574
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 10 deletions.
30 changes: 20 additions & 10 deletions apis_ontology/management/commands/transfer_subjects_to_vocab.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.core.management.base import BaseCommand

from apis_ontology.models import Subject, Work
from apis_core.relations.models import Relation
import re
from tqdm.auto import tqdm
from django.apps import apps

DELIMITERS = [",", ";", "+", "/"]
PATTERN = "|".join(map(re.escape, DELIMITERS))
Expand All @@ -27,15 +27,25 @@ def split_subjects(old_subject_field):
w.subject_vocab.add(new_sub)

rels_updated = 0
for rel in tqdm(Relation.objects.all()):
if hasattr(rel, "subject_of_teaching"):
if rel.subject_of_teaching:
subject_list = split_subjects(rel.subject_of_teaching)
for si in subject_list:
new_sub, _ = Subject.objects.get_or_create(name=si)
rel.skip_history_when_saving = True
rel.subject_vocab.add(new_sub)
rels_updated += 1
relation_models = [
"PersonDirectPredecessorInLineageOfPerson",
"PersonDiscipleOfPerson",
"PersonRefersWithNameToTheViewsOfPerson",
"PersonRefersWithoutNameToTheViewsOfPerson",
"PersonRequestorOfPerson",
"PersonStudentOfPerson",
]
for rel_model in relation_models:
model_class = apps.get_model("apis_ontology", rel_model)
for rel in model_class.objects.all():
if hasattr(rel, "subject_of_teaching"):
if rel.subject_of_teaching:
subject_list = split_subjects(rel.subject_of_teaching)
for si in subject_list:
new_sub, _ = Subject.objects.get_or_create(name=si)
rel.skip_history_when_saving = True
rel.subject_of_teaching_vocab.add(new_sub)
rels_updated += 1

self.stdout.write(
self.style.SUCCESS(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Generated by Django 4.2.13 on 2024-07-03 09:03

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
(
"apis_ontology",
"0021_persondirectpredecessorinlineageofperson_subject_of_teaching_vocab_and_more",
),
]

operations = [
migrations.AddField(
model_name="personstudentofperson",
name="subject_of_teaching_vocab",
field=models.ManyToManyField(
blank=True,
to="apis_ontology.subject",
verbose_name="Subject of teaching",
),
),
migrations.AlterField(
model_name="persondirectpredecessorinlineageofperson",
name="subject_of_teaching",
field=models.CharField(
blank=True,
max_length=255,
null=True,
verbose_name="subject of teaching",
),
),
migrations.AlterField(
model_name="persondiscipleofperson",
name="subject_of_teaching",
field=models.CharField(
blank=True,
max_length=255,
null=True,
verbose_name="subject of teaching",
),
),
migrations.AlterField(
model_name="personreferswithnametotheviewsofperson",
name="subject_of_teaching",
field=models.CharField(
blank=True,
max_length=255,
null=True,
verbose_name="subject of teaching",
),
),
migrations.AlterField(
model_name="personreferswithoutnametotheviewsofperson",
name="subject_of_teaching",
field=models.CharField(
blank=True,
max_length=255,
null=True,
verbose_name="subject of teaching",
),
),
migrations.AlterField(
model_name="personstudentofperson",
name="subject_of_teaching",
field=models.CharField(
blank=True,
max_length=255,
null=True,
verbose_name="subject of teaching",
),
),
]
3 changes: 3 additions & 0 deletions apis_ontology/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,9 @@ class PersonStudentOfPerson(TibScholRelationMixin):
editable=False,
)
)
subject_of_teaching_vocab = models.ManyToManyField(
Subject, verbose_name="Subject of teaching", blank=True
)


class PersonStudiedWork(TibScholRelationMixin):
Expand Down

0 comments on commit 08c6574

Please sign in to comment.