From 7f0adbfba604db269be973e364307115778e15ec Mon Sep 17 00:00:00 2001 From: csae8092 Date: Wed, 23 Nov 2022 16:11:30 +0100 Subject: [PATCH 1/2] wip: for #53 the save method of SkosConcepts was changed * which so far created a generic notation if the notation was empty --- vocabs/models.py | 18 +++++++++--------- vocabs/rdf_utils.py | 3 ++- vocabs/tests/test_import_export.py | 7 +++++++ vocabs/utils.py | 7 +++++++ 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/vocabs/models.py b/vocabs/models.py index 3e6395a..8dd336d 100644 --- a/vocabs/models.py +++ b/vocabs/models.py @@ -618,15 +618,15 @@ def get_vocabs_uri(self): return "{}{}".format("https://whatever", self.get_absolute_url) def save(self, *args, **kwargs): - if self.notation == "": - temp_notation = slugify(self.pref_label, allow_unicode=True) - concepts = len(SkosConcept.objects.filter(notation=temp_notation)) - if concepts < 1: - self.notation = temp_notation - else: - self.notation = "{}-{}".format(temp_notation, concepts) - else: - pass + # if self.notation == "": + # temp_notation = slugify(self.pref_label, allow_unicode=True) + # concepts = len(SkosConcept.objects.filter(notation=temp_notation)) + # if concepts < 1: + # self.notation = temp_notation + # else: + # self.notation = "{}-{}".format(temp_notation, concepts) + # else: + # pass if not self.id: self.date_created = timezone.now() diff --git a/vocabs/rdf_utils.py b/vocabs/rdf_utils.py index 90d3d36..7f4bd42 100644 --- a/vocabs/rdf_utils.py +++ b/vocabs/rdf_utils.py @@ -95,7 +95,8 @@ def graph_construct_qs(results): concept = URIRef(obj.create_uri()) g.add((concept, RDF.type, SKOS.Concept)) g.add((concept, SKOS.prefLabel, Literal(obj.pref_label, lang=obj.pref_label_lang))) - g.add((concept, SKOS.notation, Literal(obj.notation))) + if obj.notation: + g.add((concept, SKOS.notation, Literal(obj.notation))) # each concept must have skos:inScheme main_concept_scheme g.add((concept, SKOS.inScheme, main_concept_scheme)) if obj.collection.all(): diff --git a/vocabs/tests/test_import_export.py b/vocabs/tests/test_import_export.py index d5a4154..66edca0 100644 --- a/vocabs/tests/test_import_export.py +++ b/vocabs/tests/test_import_export.py @@ -8,6 +8,7 @@ from ..models import SkosConceptScheme, SkosCollection, SkosConcept from ..skos_import import SkosImporter from ..rdf_utils import graph_construct_qs +from ..utils import delete_legacy_ids, delete_skos_notations EXAMPLE_SKOS_IMPORT = os.path.join(os.path.dirname(__file__), "example_skos_import.rdf") @@ -43,6 +44,12 @@ def test_related_concepts(self): exact_match__contains='https://d-nb.info/gnd/1197273174' ) self.assertEqual(item.count(), 1) + concept_scheme = item.first().scheme + delete_legacy_ids(concept_scheme) + delete_skos_notations(concept_scheme) + for x in concept_scheme.has_concepts.all(): + self.assertEqual(x.legacy_id, "") + self.assertEqual(x.notation, "") class TestSkosExport(TestCase): diff --git a/vocabs/utils.py b/vocabs/utils.py index c81c1fb..dedcb9e 100644 --- a/vocabs/utils.py +++ b/vocabs/utils.py @@ -60,3 +60,10 @@ def delete_legacy_ids(concept_scheme): x.legacy_id = "" x.save() return "done" + + +def delete_skos_notations(concept_scheme): + for x in concept_scheme.has_concepts.all(): + x.notation = "" + x.save() + return "done" From 058007f14b0dabb2acdfcb4bf64bba187a82c503 Mon Sep 17 00:00:00 2001 From: csae8092 Date: Wed, 23 Nov 2022 16:34:47 +0100 Subject: [PATCH 2/2] view and button to delete notations per scheme #53 --- vocabs/rdf_utils.py | 2 +- vocabs/templates/vocabs/skosconceptscheme_detail.html | 3 ++- vocabs/urls.py | 3 +++ vocabs/views.py | 9 ++++++++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/vocabs/rdf_utils.py b/vocabs/rdf_utils.py index 7f4bd42..d902528 100644 --- a/vocabs/rdf_utils.py +++ b/vocabs/rdf_utils.py @@ -95,7 +95,7 @@ def graph_construct_qs(results): concept = URIRef(obj.create_uri()) g.add((concept, RDF.type, SKOS.Concept)) g.add((concept, SKOS.prefLabel, Literal(obj.pref_label, lang=obj.pref_label_lang))) - if obj.notation: + if obj.notation != "": g.add((concept, SKOS.notation, Literal(obj.notation))) # each concept must have skos:inScheme main_concept_scheme g.add((concept, SKOS.inScheme, main_concept_scheme)) diff --git a/vocabs/templates/vocabs/skosconceptscheme_detail.html b/vocabs/templates/vocabs/skosconceptscheme_detail.html index 7264394..721a2bb 100644 --- a/vocabs/templates/vocabs/skosconceptscheme_detail.html +++ b/vocabs/templates/vocabs/skosconceptscheme_detail.html @@ -290,7 +290,8 @@

{% if user.is_authenticated %} - Remove legacy ids + Remove legacy ids + Remove Skos Notations {% endif %} {% endif %} {% endif %} diff --git a/vocabs/urls.py b/vocabs/urls.py index 09d75f1..7ca0137 100644 --- a/vocabs/urls.py +++ b/vocabs/urls.py @@ -24,6 +24,9 @@ path( 'scheme/remove-keys/', views.delete_legacy_id_view, name='skosconceptscheme_remove_keys'), + path( + 'scheme/remove-notations/', views.delete_notation_view, + name='skosconceptscheme_remove_notations'), path( 'scheme/delete/', views.SkosConceptSchemeDelete.as_view(), diff --git a/vocabs/views.py b/vocabs/views.py index deeccc4..95a3487 100644 --- a/vocabs/views.py +++ b/vocabs/views.py @@ -42,7 +42,7 @@ SkosCollectionListFilter ) from vocabs.rdf_utils import graph_construct_qs, RDF_FORMATS -from vocabs.utils import delete_legacy_ids +from vocabs.utils import delete_legacy_ids, delete_skos_notations class BaseDetailView(DetailView): @@ -133,6 +133,13 @@ def delete_legacy_id_view(request, pk): return redirect(obj) +@login_required +def delete_notation_view(request, pk): + obj = get_object_or_404(SkosConceptScheme, pk=pk) + delete_skos_notations(obj) + return redirect(obj) + + class SkosConceptSchemeCreate(BaseCreateView): model = SkosConceptScheme form_class = SkosConceptSchemeForm