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

Commit

Permalink
#200 bugfixes
Browse files Browse the repository at this point in the history
Signed-off-by: novdamme <[email protected]>
  • Loading branch information
novdamme committed Apr 13, 2023
1 parent e91a27f commit f38ce17
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion backend/planning/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
path("studenttemplates/<int:template_id>/rondes/<int:ronde_id>/dagplanningen/", views.dagplanningen_view),
path("studenttemplates/<int:template_id>/dagplanningen/<int:dag_id>/", views.dagplanning_view, {'permanent': True}),
path("studenttemplates/<int:template_id>/dagplanningen/<int:dag_id>/eenmalig/", views.dagplanning_view,
{'permanent': True})
{'permanent': False})

]
24 changes: 16 additions & 8 deletions backend/planning/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def dagplanningen_view(request, template_id, ronde_id):
data = request.data
current_year, current_week, _ = datetime.datetime.utcnow().isocalendar()

data["ronde"] = Ronde.objects.get(id=ronde_id)
data["ronde"] = ronde_id
validate_dag_planning_data(data)
new_dag_planning = make_dag_planning(data)

Expand All @@ -349,15 +349,16 @@ def dagplanningen_view(request, template_id, ronde_id):
None,
new_dag_planning,
True,
get_current_week_planning().student_templates
get_current_week_planning().student_templates,
copy_template=make_copy
)

return Response({"message": "Success"})


@api_view(["DELETE", "PATCH"])
@permission_classes([AllowAny])
def dagplanning_view(request, template_id, ronde_id, dag_id, permanent):
def dagplanning_view(request, template_id, dag_id, permanent):

template = StudentTemplate.objects.get(id=template_id)

Expand All @@ -375,7 +376,8 @@ def dagplanning_view(request, template_id, ronde_id, dag_id, permanent):
dag_planning,
None,
permanent,
get_current_week_planning().student_templates
get_current_week_planning().student_templates,
copy_template=make_copy
)
return Response({"message": "Success"})

Expand All @@ -386,9 +388,14 @@ def dagplanning_view(request, template_id, ronde_id, dag_id, permanent):
data = request.data

data["day"] = dag_planning.time.day
data["start_hour"] = dag_planning.time.start_hour
data["end_hour"] = dag_planning.time.end_hour
data["ronde"] = dag_planning.ronde
if "start_hour" not in data:
data["start_hour"] = dag_planning.time.start_hour
if "end_hour" not in data:
data["end_hour"] = dag_planning.time.end_hour
if "ronde" not in data:
data["ronde"] = dag_planning.ronde.id
if "students" not in data:
data["students"] = dag_planning.students.all()

new_dag_planning = make_dag_planning(data)

Expand All @@ -398,6 +405,7 @@ def dagplanning_view(request, template_id, ronde_id, dag_id, permanent):
dag_planning,
new_dag_planning,
permanent,
get_current_week_planning().student_templates
get_current_week_planning().student_templates,
copy_template=make_copy
)
return Response({"message": "Success"})
5 changes: 3 additions & 2 deletions backend/trashtemplates/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ def update_many_to_many(template, many_to_many, old, new):
template[many_to_many].add(new)


def update(template, many_to_many, old, new, permanent, template_list):
def update(template, many_to_many, old, new, permanent, template_list, copy_template=make_copy):
"""
Past het betreffende many_to_many veld van de template aan.
Als het nodig is wordt er ook een copy gemaakt van de template zodat de geschiedenis behouden wordt.
@param copy_template: Functie die een template kopieert
@param template: De originele template
@param many_to_many: Het veld dat aangepast wordt van de template
@param old: De oude waarde
Expand All @@ -130,7 +131,7 @@ def update(template, many_to_many, old, new, permanent, template_list):
if no_copy(template, permanent, current_year, current_week):
update_many_to_many(template, many_to_many, old, new)
else:
copy = make_copy(template, permanent, current_year, current_week)
copy = copy_template(template, permanent, current_year, current_week)
update_many_to_many(copy, many_to_many, old, new)
remove_if_match(template_list, template, current_week)
add_if_match(template_list, copy, current_week)

0 comments on commit f38ce17

Please sign in to comment.