diff --git a/device/templates/details.html b/device/templates/details.html index 980b28a..c889d45 100644 --- a/device/templates/details.html +++ b/device/templates/details.html @@ -122,7 +122,6 @@ {% trans 'Created on' %} - @@ -131,14 +130,49 @@ {{ a.key }} {{ a.value }} {{ a.created }} - - + +
+ + + + +
+ {% endfor %} + +{% for a in object.get_user_properties %} + +{% endfor %} + +
diff --git a/device/urls.py b/device/urls.py index 05a2988..dc7fddc 100644 --- a/device/urls.py +++ b/device/urls.py @@ -8,6 +8,8 @@ urlpatterns = [ path("edit//", views.EditDeviceView.as_view(), name="edit"), path("/", views.DetailsView.as_view(), name="details"), path("/user_property/add", views.AddUserPropertyView.as_view(), name="add_user_property"), + path("user_property//delete", views.DeleteUserPropertyView.as_view(), name="delete_user_property"), + path("user_property//update", views.AddUserPropertyView.as_view(), name="update_user_property"), path("/document/add", views.AddDocumentView.as_view(), name="add_document"), path("/public/", views.PublicDeviceWebView.as_view(), name="device_web"), diff --git a/device/views.py b/device/views.py index 80c2e46..76905f5 100644 --- a/device/views.py +++ b/device/views.py @@ -3,12 +3,14 @@ from django.http import JsonResponse from django.http import Http404 from django.urls import reverse_lazy -from django.shortcuts import get_object_or_404, Http404 +from django.contrib import messages +from django.shortcuts import get_object_or_404, redirect, Http404 from django.utils.translation import gettext_lazy as _ from django.views.generic.edit import ( CreateView, UpdateView, FormView, + DeleteView, ) from django.views.generic.base import TemplateView from dashboard.mixins import DashboardView, Http403 @@ -199,6 +201,26 @@ class AddUserPropertyView(DashboardView, CreateView): kwargs = super().get_form_kwargs() return kwargs +class DeleteUserPropertyView(DashboardView, DeleteView): + model = UserProperty + + def post(self, request, *args, **kwargs): + self.pk = kwargs['pk'] + referer = request.META.get('HTTP_REFERER') + if not referer: + raise Http404("No referer header found") + + self.object = get_object_or_404( + self.model, + pk=self.pk, + owner=self.request.user.institution + ) + self.object.delete() + messages.success(self.request, _("User property deleted successfully.")) + + # Redirect back to the original URL + return redirect(referer) + class AddDocumentView(DashboardView, CreateView): template_name = "new_annotation.html"