Skip to content

Commit

Permalink
Merge pull request #55 from acdh-oeaw/53-deactivatingdeleting-automat…
Browse files Browse the repository at this point in the history
…ic-creation-of-notations

53 deactivatingdeleting automatic creation of notations
  • Loading branch information
csae8092 authored Nov 23, 2022
2 parents 4759c4d + 058007f commit 0ac3d37
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 12 deletions.
18 changes: 9 additions & 9 deletions vocabs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion vocabs/rdf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
3 changes: 2 additions & 1 deletion vocabs/templates/vocabs/skosconceptscheme_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ <h2 style="text-align: center;">

</div>
{% if user.is_authenticated %}
<a href="{% url 'vocabs:skosconceptscheme_remove_keys' pk=object.id %}" class="btn btn-outline-danger" type="button">Remove legacy ids</a>
<a href="{% url 'vocabs:skosconceptscheme_remove_keys' pk=object.id %}" class="btn btn-outline-danger" type="button" style="margin: 5px;">Remove legacy ids</a>
<a href="{% url 'vocabs:skosconceptscheme_remove_notations' pk=object.id %}" class="btn btn-outline-danger" type="button" style="margin: 5px;">Remove Skos Notations</a>
{% endif %}
{% endif %}
{% endif %}
Expand Down
7 changes: 7 additions & 0 deletions vocabs/tests/test_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions vocabs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
path(
'scheme/remove-keys/<int:pk>', views.delete_legacy_id_view,
name='skosconceptscheme_remove_keys'),
path(
'scheme/remove-notations/<int:pk>', views.delete_notation_view,
name='skosconceptscheme_remove_notations'),
path(
'scheme/delete/<int:pk>',
views.SkosConceptSchemeDelete.as_view(),
Expand Down
7 changes: 7 additions & 0 deletions vocabs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 8 additions & 1 deletion vocabs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0ac3d37

Please sign in to comment.