Skip to content
Snippets Groups Projects
Commit 7f695bad authored by Felix Blanke's avatar Felix Blanke
Browse files

Add success and failure messages

parent 3fad6919
No related branches found
No related tags found
1 merge request!8Avoid setting the slot duration at import
......@@ -383,7 +383,7 @@ class Event(models.Model):
)
@transaction.atomic
def schedule_from_json(self, schedule: str) -> None:
def schedule_from_json(self, schedule: str) -> int:
"""Load AK schedule from a json string.
:param schedule: A string that can be decoded to json, describing
......@@ -401,6 +401,7 @@ class Event(models.Model):
for timeslot in block
}
slots_updated = 0
for scheduled_slot in schedule["scheduled_aks"]:
scheduled_slot["timeslot_ids"] = list(map(int, scheduled_slot["timeslot_ids"]))
start_timeslot = timeslot_dict[min(scheduled_slot["timeslot_ids"])].avail
......@@ -414,6 +415,8 @@ class Event(models.Model):
assert solver_duration + 1e-4 >= slot.duration
slot.save()
slots_updated += 1
return slots_updated
class AKOwner(models.Model):
""" An AKOwner describes the person organizing/holding an AK.
......
......@@ -61,7 +61,7 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
def _test_ak_fixed_in_slot(self, ak_id, slot: Availability, ak_fixed: dict) -> bool:
"""Test if AK defined by `ak_id` is fixed to happen during slot."""
if not ak_id in ak_fixed:
if ak_id not in ak_fixed:
return False
fixed_slot = Availability(self.event, start=ak_fixed[ak_id].start, end=ak_fixed[ak_id].end)
......
......@@ -257,6 +257,18 @@ class AKScheduleJSONImportView(EventSlugMixin, IntermediateAdminView):
title = _("AK Schedule JSON Import")
def form_valid(self, form):
self.event.schedule_from_json(form.data["json_data"])
try:
number_of_slots_changed = self.event.schedule_from_json(form.data["json_data"])
messages.add_message(
self.request,
messages.SUCCESS,
_("Successfully imported {n} slot(s)").format(n=number_of_slots_changed)
)
except ValueError as ex:
messages.add_message(
self.request,
messages.ERROR,
_("Importing an AK schedule failed! Reason: ") + str(ex),
)
return redirect("admin:event_status", self.event.slug)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment