From 25d7a0de6372deab4960e7286fd51b5f73eb90ad Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Thu, 31 Oct 2024 01:55:20 -0300 Subject: [PATCH] added action orm models and route --- admin/urls.py | 1 + evidence/models.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/admin/urls.py b/admin/urls.py index 9a26cbf..5d39a37 100644 --- a/admin/urls.py +++ b/admin/urls.py @@ -10,4 +10,5 @@ urlpatterns = [ path("users/edit/", views.EditUserView.as_view(), name="edit_user"), path("users/delete/", views.DeleteUserView.as_view(), name="delete_user"), path("institution/", views.InstitutionView.as_view(), name="institution"), + path("reserved", views.AddReservedAnnotationView.as_view(), name="reserved"), ] diff --git a/evidence/models.py b/evidence/models.py index fef6a92..8e9a9ef 100644 --- a/evidence/models.py +++ b/evidence/models.py @@ -15,6 +15,7 @@ class Annotation(models.Model): USER = 1, "User" DOCUMENT = 2, "Document" ERASE_SERVER = 3, "EraseServer" + ADMIN = 4, "Admin" created = models.DateTimeField(auto_now_add=True) uuid = models.UUIDField() @@ -28,7 +29,32 @@ class Annotation(models.Model): constraints = [ models.UniqueConstraint(fields=["type", "key", "uuid"], name="unique_type_key_uuid") ] + #TODO: check if this works properly + def clean(self): + super().clean() + if self.type == self.Type.ADMIN: + if Annotation.objects.filter(type=self.Type.ADMIN, key=self.key).exists(): + raise ValidationError(f"The key '{self.key}' is already reserved by admin.") + else: + if Annotation.objects.filter(type=self.Type.ADMIN, key=self.key).exists(): + raise ValidationError(f"The key '{self.key}' is reserved by admin and cannot be used.") +class AllowedValue(models.Model): + annotation = models.ForeignKey(Annotation, on_delete=models.CASCADE, limit_choices_to={'type': Annotation.Type.ADMIN}) + value = models.CharField(max_length=50) + + + def __str__(self): + return self.value + +#This represents a change on a System-type Annotation +class Action(models.Model): + + annotation = models.ForeignKey(Annotation, on_delete=models.CASCADE, limit_choices_to={'type': Annotation.Type.ADMIN}) + created = models.DateTimeField(auto_now_add=True) + owner = models.ForeignKey(Institution, on_delete=models.CASCADE) + user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True) + comment = models.CharField(max_length=250) class Evidence: def __init__(self, uuid):