From 21722ef1fcec7650c7daa65b78207511b219d9eb Mon Sep 17 00:00:00 2001 From: novdamme Date: Sun, 21 May 2023 18:21:34 +0200 Subject: [PATCH 1/4] vervangen templates kunnen niet verwijderd worden Signed-off-by: novdamme --- backend/planning/views.py | 5 +++++ backend/trashtemplates/views.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/backend/planning/views.py b/backend/planning/views.py index 1da17ef1..d1597229 100644 --- a/backend/planning/views.py +++ b/backend/planning/views.py @@ -13,6 +13,7 @@ SuperstudentPermission, StudentPermission, SyndicusPermission, \ BewonerPermission from .util import * +from exceptions.exceptionHandler import ExceptionHandler class StudentDayPlan(generics.RetrieveAPIView): @@ -531,6 +532,10 @@ def delete(self, request, *args, **kwargs): template = StudentTemplate.objects.get(id=kwargs["template_id"]) planning = get_current_week_planning() + handler = ExceptionHandler() + handler.check_vervangen(template) + handler.check() + if template.status == Status.EENMALIG: # template was eenmalig dus de originele template moet terug actief gemaakt worden original = StudentTemplate.objects.get( diff --git a/backend/trashtemplates/views.py b/backend/trashtemplates/views.py index 8e66b112..68d73455 100644 --- a/backend/trashtemplates/views.py +++ b/backend/trashtemplates/views.py @@ -118,6 +118,11 @@ def delete(self, request, *args, **kwargs): was terug actief gezet worden. """ template = TrashContainerTemplate.objects.get(id=kwargs["template_id"]) + + handler = ExceptionHandler() + handler.check_vervangen(template) + handler.check() + current_year, current_week = get_current_time() planning = get_current_week_planning() if template.status == Status.EENMALIG: From df2f801375c676b61076060bb82e7b3f125431df Mon Sep 17 00:00:00 2001 From: novdamme Date: Sun, 21 May 2023 19:42:28 +0200 Subject: [PATCH 2/4] rondes worden in template van beide even/oneven aangepast wanneer verwijderd/aangepast Signed-off-by: novdamme --- backend/ronde/views.py | 57 ++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/backend/ronde/views.py b/backend/ronde/views.py index d6a35145..304e06fd 100644 --- a/backend/ronde/views.py +++ b/backend/ronde/views.py @@ -8,7 +8,8 @@ from users.permissions import StudentReadOnly, AdminPermission, \ SuperstudentPermission, SyndicusPermission, AllowAnyReadOnly from trashtemplates.util import update -from planning.util import get_current_week_planning, make_copy +from planning.util import get_current_week_planning, make_copy, get_current_time +from planning.views import get_student_templates from .models import * from .serializers import * @@ -265,22 +266,46 @@ def patch(self, request, *args, **kwargs): old.is_active = False old.save() - student_templates = get_current_week_planning().student_templates + current_year, current_week = get_current_time() + student_templates = get_current_week_planning().student_templates.all() | get_student_templates(current_year, current_week + 1) - template = None - for student_template in student_templates.all(): + for student_template in student_templates: for ronde in student_template.rondes.all(): if ronde.id == id: - template = student_template - - if template is not None: - update( - template, - "rondes", - old, - new_ronde, - True, - student_templates, - copy_template=make_copy - ) + update( + student_template, + "rondes", + old, + new_ronde, + True, + student_templates, + copy_template=make_copy + ) + + return Response({"message": "success"}) + + def delete(self, request, *args, **kwargs): + + id = kwargs["pk"] + old = Ronde.objects.get(id=id) + + old.is_active = False + old.save() + current_year, current_week = get_current_time() + + student_templates = get_current_week_planning().student_templates.all() | get_student_templates(current_year, current_week + 1) + + for student_template in student_templates: + for ronde in student_template.rondes.all(): + if ronde.id == id: + update( + student_template, + "rondes", + old, + None, + True, + get_current_week_planning().student_templates, + copy_template=make_copy + ) + return Response({"message": "success"}) From 8c8bd55c1b49111e49a640818fdf539a2031236d Mon Sep 17 00:00:00 2001 From: novdamme Date: Sun, 21 May 2023 19:51:32 +0200 Subject: [PATCH 3/4] check of template niet inactive is in backend Signed-off-by: novdamme --- backend/planning/views.py | 20 ++++++++++++++++++++ backend/trashtemplates/views.py | 22 +++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/backend/planning/views.py b/backend/planning/views.py index d1597229..3f2cdee7 100644 --- a/backend/planning/views.py +++ b/backend/planning/views.py @@ -534,6 +534,7 @@ def delete(self, request, *args, **kwargs): handler = ExceptionHandler() handler.check_vervangen(template) + handler.check_not_inactive(template, "template") handler.check() if template.status == Status.EENMALIG: @@ -564,6 +565,9 @@ def patch(self, request, *args, **kwargs): Neemt een copy van de template om de geschiedenis te behouden als dit nodig is. """ template = StudentTemplate.objects.get(id=kwargs["template_id"]) + handler = ExceptionHandler() + handler.check_not_inactive(template, "template") + handler.check() current_year, current_week = get_current_time() data = request.data @@ -625,6 +629,9 @@ def post(self, request, *args, **kwargs): Voegt een nieuwe Ronde toe aan de template. """ template = StudentTemplate.objects.get(id=kwargs["template_id"]) + handler = ExceptionHandler() + handler.check_not_inactive(template, "template") + handler.check() data = request.data current_year, current_week = get_current_time() handler = ExceptionHandler() @@ -671,6 +678,9 @@ def delete(self, request, *args, **kwargs): Verwijderd een ronde en al zijn dagplanningen uit de template. """ template = StudentTemplate.objects.get(id=kwargs["template_id"]) + handler = ExceptionHandler() + handler.check_not_inactive(template, "template") + handler.check() ronde = Ronde.objects.get(id=kwargs["ronde_id"]) current_year, current_week = get_current_time() to_remove = template.dag_planningen.filter(ronde=ronde) @@ -709,6 +719,9 @@ def post(self, request, *args, **kwargs): """ data = request.data template = StudentTemplate.objects.get(id=kwargs["template_id"]) + handler = ExceptionHandler() + handler.check_not_inactive(template, "template") + handler.check() ronde_id = kwargs["ronde_id"] data["ronde"] = ronde_id @@ -743,6 +756,9 @@ def delete(self, request, *args, **kwargs): """ template = StudentTemplate.objects.get(id=kwargs["template_id"]) + handler = ExceptionHandler() + handler.check_not_inactive(template, "template") + handler.check() dag_planning = DagPlanning.objects.get(id=kwargs["dag_id"]) permanent = kwargs["permanent"] response = update( @@ -763,6 +779,10 @@ def put(self, request, *args, **kwargs): def patch(self, request, *args, **kwargs): data = request.data template = StudentTemplate.objects.get(id=kwargs["template_id"]) + handler = ExceptionHandler() + handler.check_not_inactive(template, "template") + handler.check() + dag_planning = DagPlanning.objects.get(id=kwargs["dag_id"]) permanent = kwargs["permanent"] data_copy = dict(data) diff --git a/backend/trashtemplates/views.py b/backend/trashtemplates/views.py index 68d73455..a453f4c7 100644 --- a/backend/trashtemplates/views.py +++ b/backend/trashtemplates/views.py @@ -121,6 +121,7 @@ def delete(self, request, *args, **kwargs): handler = ExceptionHandler() handler.check_vervangen(template) + handler.check_not_inactive(template, "template") handler.check() current_year, current_week = get_current_time() @@ -166,6 +167,9 @@ def post(self, request, *args, **kwargs): Voegt de nieuwe TrashContainer toe aan de template adhv een TrashContainerIdWrapper. """ template = TrashContainerTemplate.objects.get(id=kwargs["template_id"]) + handler = ExceptionHandler() + handler.check_not_inactive(template, "template") + handler.check() permanent = kwargs["permanent"] data = request.data @@ -206,6 +210,9 @@ def patch(self, request, *args, **kwargs): Neemt een copy van de template om de geschiedenis te behouden als dit nodig is. """ template = TrashContainerTemplate.objects.get(id=kwargs["template_id"]) + handler = ExceptionHandler() + handler.check_not_inactive(template, "template") + handler.check() tc_id_wrapper = template.trash_containers.get(extra_id=kwargs[ "extra_id"]) permanent = kwargs["permanent"] @@ -245,6 +252,9 @@ def delete(self, request, *args, **kwargs): Neemt een copy van de template om de geschiedenis te behouden als dit nodig is. """ template = TrashContainerTemplate.objects.get(id=kwargs["template_id"]) + handler = ExceptionHandler() + handler.check_not_inactive(template, "template") + handler.check() tc_id_wrapper = template.trash_containers.get(extra_id=kwargs[ "extra_id"]) permanent = kwargs["permanent"] @@ -279,8 +289,11 @@ def post(self, request, *args, **kwargs): data = request.data template = TrashContainerTemplate.objects.get(id=kwargs[ "template_id"]) + handler = ExceptionHandler() + handler.check_not_inactive(template, "template") + handler.check() + permanent = kwargs["permanent"] - # checks building = Building.objects.get(id=data["building"]) new_building_list = BuildingTrashContainerList.objects.create( building=building @@ -322,6 +335,9 @@ def delete(self, request, *args, **kwargs): Neemt een copy van de template om de geschiedenis te behouden als dit nodig is. """ template = TrashContainerTemplate.objects.get(id=kwargs["template_id"]) + handler = ExceptionHandler() + handler.check_not_inactive(template, "template") + handler.check() building_list = template.buildings.get(building=kwargs["building_id"]) permanent = kwargs["permanent"] update( @@ -343,6 +359,10 @@ def patch(self, request, *args, **kwargs): """ data = request.data template = TrashContainerTemplate.objects.get(id=kwargs["template_id"]) + handler = ExceptionHandler() + handler.check_not_inactive(template, "template") + handler.check() + building_list = template.buildings.get(building=kwargs["building_id"]) permanent = kwargs["permanent"] new_building_list = make_new_building_list(kwargs["building_id"], From 999a5d32749765610da6f59aac0a8f5f669f6f0d Mon Sep 17 00:00:00 2001 From: novdamme Date: Sun, 21 May 2023 19:54:14 +0200 Subject: [PATCH 4/4] beter error message Signed-off-by: novdamme --- backend/exceptions/exceptionHandler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/exceptions/exceptionHandler.py b/backend/exceptions/exceptionHandler.py index 658ca1d5..ab4b4c8c 100644 --- a/backend/exceptions/exceptionHandler.py +++ b/backend/exceptions/exceptionHandler.py @@ -23,7 +23,7 @@ class ExceptionHandler: boolean_error = "Veld moet een Boolse waarde zijn." wrong_email_error = "Verkeerd email adres." not_equal_error = "Waarde komt niet overeen." - inactive_error = "Object is verwijderd." + inactive_error = "Dit is een inactieve versie." vervangen_error = "Kan geen aanpassingen doen aan vervangen template" def __init__(self):