diff --git a/vocabs/templates/vocabs/skosconceptscheme_detail.html b/vocabs/templates/vocabs/skosconceptscheme_detail.html index fbc6b23..7264394 100644 --- a/vocabs/templates/vocabs/skosconceptscheme_detail.html +++ b/vocabs/templates/vocabs/skosconceptscheme_detail.html @@ -287,7 +287,11 @@

{% endfor %} + + {% if user.is_authenticated %} + Remove legacy ids + {% endif %} {% endif %} {% endif %} diff --git a/vocabs/urls.py b/vocabs/urls.py index 13ed9be..09d75f1 100644 --- a/vocabs/urls.py +++ b/vocabs/urls.py @@ -21,6 +21,9 @@ path( 'scheme/update/', views.SkosConceptSchemeUpdate.as_view(), name='skosconceptscheme_update'), + path( + 'scheme/remove-keys/', views.delete_legacy_id_view, + name='skosconceptscheme_remove_keys'), path( 'scheme/delete/', views.SkosConceptSchemeDelete.as_view(), diff --git a/vocabs/utils.py b/vocabs/utils.py index 5f020eb..c81c1fb 100644 --- a/vocabs/utils.py +++ b/vocabs/utils.py @@ -53,3 +53,10 @@ def handle_uploaded_file(file): for chunk in file.chunks(): destination.write(chunk) return full_file_name + + +def delete_legacy_ids(concept_scheme): + for x in concept_scheme.has_concepts.all(): + x.legacy_id = "" + x.save() + return "done" diff --git a/vocabs/views.py b/vocabs/views.py index d19da20..deeccc4 100644 --- a/vocabs/views.py +++ b/vocabs/views.py @@ -1,5 +1,6 @@ import time import datetime +from django.shortcuts import get_object_or_404, redirect from guardian.shortcuts import get_objects_for_user from django.contrib.auth.decorators import login_required from reversion.models import Version @@ -41,6 +42,7 @@ SkosCollectionListFilter ) from vocabs.rdf_utils import graph_construct_qs, RDF_FORMATS +from vocabs.utils import delete_legacy_ids class BaseDetailView(DetailView): @@ -124,6 +126,13 @@ def get_context_data(self, **kwargs): return context +@login_required +def delete_legacy_id_view(request, pk): + obj = get_object_or_404(SkosConceptScheme, pk=pk) + delete_legacy_ids(obj) + return redirect(obj) + + class SkosConceptSchemeCreate(BaseCreateView): model = SkosConceptScheme form_class = SkosConceptSchemeForm diff --git a/vocabseditor/settings.py b/vocabseditor/settings.py index 73ee2b8..6876c80 100644 --- a/vocabseditor/settings.py +++ b/vocabseditor/settings.py @@ -64,6 +64,8 @@ 'drf_yasg', # 'django_extensions', ] +if DEBUG: + INSTALLED_APPS = INSTALLED_APPS + ['django_extensions'] SWAGGER_SETTINGS = { 'LOGOUT_URL': '/logout/',