Skip to content

Commit

Permalink
Merge pull request #50 from acdh-oeaw/48-bulk-delete-legacy_id-via-pe…
Browse files Browse the repository at this point in the history
…r-conceptscheme

48 bulk delete legacy id via per conceptscheme
  • Loading branch information
csae8092 authored Nov 10, 2022
2 parents 23512a5 + 34ef339 commit 6e97995
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vocabs/templates/vocabs/skosconceptscheme_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,11 @@ <h2 style="text-align: center;">
</li>
{% endfor %}
</div>

</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>
{% endif %}
{% endif %}
{% endif %}
<!--change history ends here-->
Expand Down
3 changes: 3 additions & 0 deletions vocabs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
path(
'scheme/update/<int:pk>', views.SkosConceptSchemeUpdate.as_view(),
name='skosconceptscheme_update'),
path(
'scheme/remove-keys/<int:pk>', views.delete_legacy_id_view,
name='skosconceptscheme_remove_keys'),
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 @@ -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"
9 changes: 9 additions & 0 deletions vocabs/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions vocabseditor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
'drf_yasg',
# 'django_extensions',
]
if DEBUG:
INSTALLED_APPS = INSTALLED_APPS + ['django_extensions']

SWAGGER_SETTINGS = {
'LOGOUT_URL': '/logout/',
Expand Down

0 comments on commit 6e97995

Please sign in to comment.