Compare commits
2 Commits
10f2f6dc16
...
ca047f4e8b
Author | SHA1 | Date |
---|---|---|
Thomas Nahuel Rusiecki | ca047f4e8b | |
Thomas Nahuel Rusiecki | 04099d31a6 |
|
@ -122,7 +122,6 @@
|
||||||
{% trans 'Created on' %}
|
{% trans 'Created on' %}
|
||||||
</th>
|
</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th></th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -131,14 +130,49 @@
|
||||||
<td>{{ a.key }}</td>
|
<td>{{ a.key }}</td>
|
||||||
<td>{{ a.value }}</td>
|
<td>{{ a.value }}</td>
|
||||||
<td>{{ a.created }}</td>
|
<td>{{ a.created }}</td>
|
||||||
<td></td>
|
<td>
|
||||||
<td></td>
|
<div class="btn-group float-end">
|
||||||
|
<a href="{% url 'device:update_user_property' a.id %}" class="btn btn-sm btn-secondary">
|
||||||
|
<i class="bi bi-pencil"></i>
|
||||||
|
</a>
|
||||||
|
<button type="button" class="btn btn-sm btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal{{ a.id }}">
|
||||||
|
<i class="bi bi-trash"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- pop up modal for delete confirmation -->
|
||||||
|
{% for a in object.get_user_properties %}
|
||||||
|
<div class="modal fade" id="deleteModal{{ a.id }}" tabindex="-1" aria-labelledby="deleteModalLabel{{ a.id }}" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="deleteModalLabel{{ a.id }}">{% trans "Confirm Deletion" %}</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p><strong>{% trans "Key:" %}</strong> {{ a.key }}</p>
|
||||||
|
<p><strong>{% trans "Value:" %}</strong> {{ a.value }}</p>
|
||||||
|
<p><strong>{% trans "Created on:" %}</strong> {{ a.created }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans "Cancel" %}</button>
|
||||||
|
<form method="post" action="{% url 'device:delete_user_property' a.id %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button type="submit" class="btn btn-danger">{% trans "Delete" %}</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
<div class="tab-pane fade" id="documents">
|
<div class="tab-pane fade" id="documents">
|
||||||
<div class="btn-group mt-1 mb-3">
|
<div class="btn-group mt-1 mb-3">
|
||||||
<a href="{% url 'device:add_document' object.pk %}" class="btn btn-primary">
|
<a href="{% url 'device:add_document' object.pk %}" class="btn btn-primary">
|
||||||
|
|
|
@ -8,6 +8,8 @@ urlpatterns = [
|
||||||
path("edit/<str:pk>/", views.EditDeviceView.as_view(), name="edit"),
|
path("edit/<str:pk>/", views.EditDeviceView.as_view(), name="edit"),
|
||||||
path("<str:pk>/", views.DetailsView.as_view(), name="details"),
|
path("<str:pk>/", views.DetailsView.as_view(), name="details"),
|
||||||
path("<str:pk>/user_property/add", views.AddUserPropertyView.as_view(), name="add_user_property"),
|
path("<str:pk>/user_property/add", views.AddUserPropertyView.as_view(), name="add_user_property"),
|
||||||
|
path("user_property/<int:pk>/delete", views.DeleteUserPropertyView.as_view(), name="delete_user_property"),
|
||||||
|
path("user_property/<int:pk>/update", views.AddUserPropertyView.as_view(), name="update_user_property"),
|
||||||
path("<str:pk>/document/add", views.AddDocumentView.as_view(), name="add_document"),
|
path("<str:pk>/document/add", views.AddDocumentView.as_view(), name="add_document"),
|
||||||
path("<str:pk>/public/", views.PublicDeviceWebView.as_view(), name="device_web"),
|
path("<str:pk>/public/", views.PublicDeviceWebView.as_view(), name="device_web"),
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,14 @@ from django.http import JsonResponse
|
||||||
|
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.urls import reverse_lazy
|
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.utils.translation import gettext_lazy as _
|
||||||
from django.views.generic.edit import (
|
from django.views.generic.edit import (
|
||||||
CreateView,
|
CreateView,
|
||||||
UpdateView,
|
UpdateView,
|
||||||
FormView,
|
FormView,
|
||||||
|
DeleteView,
|
||||||
)
|
)
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
from dashboard.mixins import DashboardView, Http403
|
from dashboard.mixins import DashboardView, Http403
|
||||||
|
@ -199,6 +201,26 @@ class AddUserPropertyView(DashboardView, CreateView):
|
||||||
kwargs = super().get_form_kwargs()
|
kwargs = super().get_form_kwargs()
|
||||||
return 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):
|
class AddDocumentView(DashboardView, CreateView):
|
||||||
template_name = "new_annotation.html"
|
template_name = "new_annotation.html"
|
||||||
|
|
|
@ -28,10 +28,7 @@ class Property(models.Model):
|
||||||
value = models.CharField(max_length=STR_EXTEND_SIZE)
|
value = models.CharField(max_length=STR_EXTEND_SIZE)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
constraints = [
|
#Only for shared behaviour, it is not a table
|
||||||
models.UniqueConstraint(
|
|
||||||
fields=["type", "key", "uuid"], name="unique_type_key_uuid")
|
|
||||||
]
|
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
class SystemProperty(Property):
|
class SystemProperty(Property):
|
||||||
|
@ -43,6 +40,12 @@ class SystemProperty(Property):
|
||||||
name='property_cannot_be_user'
|
name='property_cannot_be_user'
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
#Django orm wont inherit constraints to child
|
||||||
|
#TODO: check if this is needed
|
||||||
|
constraints = [
|
||||||
|
models.UniqueConstraint(
|
||||||
|
fields=["type", "key", "uuid"], name="system_unique_type_key_uuid")
|
||||||
|
]
|
||||||
|
|
||||||
class UserProperty(Property):
|
class UserProperty(Property):
|
||||||
|
|
||||||
|
@ -55,6 +58,10 @@ class UserProperty(Property):
|
||||||
name='property_needs_to_be_user'
|
name='property_needs_to_be_user'
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
constraints = [
|
||||||
|
models.UniqueConstraint(
|
||||||
|
fields=["type", "key", "uuid"], name="user_unique_type_key_uuid")
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,5 +20,4 @@ urlpatterns = [
|
||||||
path("<uuid:pk>", views.EvidenceView.as_view(), name="details"),
|
path("<uuid:pk>", views.EvidenceView.as_view(), name="details"),
|
||||||
path("<uuid:pk>/eraseserver", views.EraseServerView.as_view(), name="erase_server"),
|
path("<uuid:pk>/eraseserver", views.EraseServerView.as_view(), name="erase_server"),
|
||||||
path("<uuid:pk>/download", views.DownloadEvidenceView.as_view(), name="download"),
|
path("<uuid:pk>/download", views.DownloadEvidenceView.as_view(), name="download"),
|
||||||
path('user_property/<int:pk>/del', views.UserPropertyDeleteView.as_view(), name='delete_user_property'),
|
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue