Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #291 from SELab-2/development
Browse files Browse the repository at this point in the history
Fix Milestone 3
  • Loading branch information
robbe0x00 authored May 21, 2023
2 parents f22e4f0 + 999a5d3 commit 5222066
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 18 deletions.
2 changes: 1 addition & 1 deletion backend/exceptions/exceptionHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
25 changes: 25 additions & 0 deletions backend/planning/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
SuperstudentPermission, StudentPermission, SyndicusPermission, \
BewonerPermission
from .util import *
from exceptions.exceptionHandler import ExceptionHandler


class StudentDayPlan(generics.RetrieveAPIView):
Expand Down Expand Up @@ -531,6 +532,11 @@ 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_not_inactive(template, "template")
handler.check()

if template.status == Status.EENMALIG:
# template was eenmalig dus de originele template moet terug actief gemaakt worden
original = StudentTemplate.objects.get(
Expand Down Expand Up @@ -559,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

Expand Down Expand Up @@ -620,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()
Expand Down Expand Up @@ -666,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)
Expand Down Expand Up @@ -704,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
Expand Down Expand Up @@ -738,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(
Expand All @@ -758,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)
Expand Down
57 changes: 41 additions & 16 deletions backend/ronde/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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"})
27 changes: 26 additions & 1 deletion backend/trashtemplates/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ 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_not_inactive(template, "template")
handler.check()

current_year, current_week = get_current_time()
planning = get_current_week_planning()
if template.status == Status.EENMALIG:
Expand Down Expand Up @@ -161,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

Expand Down Expand Up @@ -201,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"]
Expand Down Expand Up @@ -240,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"]
Expand Down Expand Up @@ -274,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
Expand Down Expand Up @@ -317,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(
Expand All @@ -338,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"],
Expand Down

0 comments on commit 5222066

Please sign in to comment.