def facility_form(request, ds, facility_id=None, zone_id=None): if request.is_teacher and not ds["facility"].teacher_can_edit_facilities: return HttpResponseForbidden() context = control_panel_context(request, zone_id=zone_id, facility_id=facility_id) if request.method != "POST": form = FacilityForm(instance=context["facility"]) else: form = FacilityForm(data=request.POST, instance=context["facility"]) if not form.is_valid(): messages.error(request, _("Failed to save the facility; please review errors below.")) else: form.instance.zone_fallback = get_object_or_None(Zone, pk=zone_id) if settings.CENTRAL_SERVER: assert form.instance.zone_fallback is not None form.save() messages.success( request, _("The facility '%(facility_name)s' has been successfully saved!") % {"facility_name": form.instance.name}, ) return HttpResponseRedirect(reverse("zone_management", kwargs={"zone_id": zone_id})) context.update({"form": form}) return context
def facility_form(request, ds, facility_id=None, zone_id=None): if request.is_teacher and not ds["facility"].teacher_can_edit_facilities: return HttpResponseForbidden() context = control_panel_context(request, zone_id=zone_id, facility_id=facility_id) if request.method != "POST": form = FacilityForm(instance=context["facility"]) else: form = FacilityForm(data=request.POST, instance=context["facility"]) if not form.is_valid(): messages.error( request, _("Failed to save the facility; please review errors below.")) else: form.instance.zone_fallback = get_object_or_None(Zone, pk=zone_id) if settings.CENTRAL_SERVER: assert form.instance.zone_fallback is not None form.save() messages.success( request, _("The facility '%(facility_name)s' has been successfully saved!" ) % {"facility_name": form.instance.name}) return HttpResponseRedirect( reverse("zone_management", kwargs={"zone_id": zone_id})) context.update({"form": form}) return context
def facility_form(request, facility, zone_id=None): context = control_panel_context(request, zone_id=zone_id, facility_id=facility.id) if request.method != "POST": form = FacilityForm(instance=context["facility"]) else: form = FacilityForm(data=request.POST, instance=context["facility"]) if not form.is_valid(): messages.error(request, _("Failed to save the facility; please review errors below.")) else: form.instance.zone_fallback = get_object_or_404(Zone, pk=zone_id) form.save() return HttpResponseRedirect(reverse("zone_management", kwargs={"zone_id": zone_id})) context.update({"form": form}) return context