def facility_form(request, facility_id, org_id=None, zone_id=None): org = get_object_or_None(Organization, pk=org_id) if org_id else None zone = get_object_or_None(Zone, pk=zone_id) if zone_id else None facil = get_object_or_404(Facility, pk=facility_id) if id != "new" else None if request.method != "POST": form = FacilityForm(instance=facil) else: form = FacilityForm(data=request.POST, instance=facil) if form.is_valid(): form.instance.zone_fallback = get_object_or_404(Zone, pk=zone_id) form.save() return HttpResponseRedirect( reverse("zone_management", kwargs={ "org_id": org_id, "zone_id": zone_id })) return { "org": org, "zone": zone, "facility": facil, "form": form, }
def add_facility(request): if request.method == "POST": form = FacilityForm(data=request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse("add_facility_student") + "?facility=" + form.instance.pk) else: form = FacilityForm() return { "form": form }
def add_facility(request): if request.method == "POST": form = FacilityForm(data=request.POST) if form.is_valid(): form.save() return HttpResponseRedirect( reverse("add_facility_student") + "?facility=" + form.instance.pk) else: form = FacilityForm() return {"form": form}
def facility_form(request, facility_id, org_id=None, zone_id=None): context = control_panel_context(request, org_id=org_id, 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 form.is_valid(): form.instance.zone_fallback = get_object_or_404(Zone, pk=zone_id) form.save() return HttpResponseRedirect(reverse("zone_management", kwargs={"org_id": org_id, "zone_id": zone_id})) context.update({"form": form}) return context
def facility_edit(request, id=None): if id != "new": facil = get_object_or_404(Facility, pk=id) else: facil = None if request.method == "POST": form = FacilityForm(data=request.POST, instance=facil) if form.is_valid(): form.save() # Translators: Do not change the text of '%(facility_name)s' because it is a variable, but you can change its position. messages.success(request, _("The facility '%(facility_name)s' has been successfully saved!") % {"facility_name": form.instance.name}) return HttpResponseRedirect(request.next or reverse("facility_admin")) else: form = FacilityForm(instance=facil) return { "form": form }
def facility_edit(request, id=None): if id != "new": facil = get_object_or_404(Facility, pk=id) else: facil = None if request.method == "POST": form = FacilityForm(data=request.POST, instance=facil) if form.is_valid(): form.save() # Translators: Do not change the text of '%(facility_name)s' because it is a variable, but you can change its position. messages.success( request, _("The facility '%(facility_name)s' has been successfully saved!" ) % {"facility_name": form.instance.name}) return HttpResponseRedirect(request.next or reverse("facility_admin")) else: form = FacilityForm(instance=facil) return {"form": form}
def facility_form(request, facility_id, org_id=None, zone_id=None): org = get_object_or_None(Organization, pk=org_id) if org_id else None zone = get_object_or_None(Zone, pk=zone_id) if zone_id else None facil = get_object_or_404(Facility, pk=facility_id) if id != "new" else None if request.method != "POST": form = FacilityForm(instance=facil) else: form = FacilityForm(data=request.POST, instance=facil) if form.is_valid(): form.instance.zone_fallback = get_object_or_404(Zone, pk=zone_id) form.save() return HttpResponseRedirect(reverse("zone_management", kwargs={"org_id": org_id, "zone_id": zone_id})) return { "org": org, "zone": zone, "facility": facil, "form": form, }
def central_facility_edit(request, org_id=None, zone_id=None, id=None): org = get_object_or_404(Organization, pk=org_id) if not org.is_member(request.user): return HttpResponseNotAllowed("You do not have permissions for this organization.") zone = org.zones.get(pk=zone_id) if id != "new": facil = get_object_or_404(Facility, pk=id) if not facil.in_zone(zone): return HttpResponseNotAllowed("This facility does not belong to this zone.") else: facil = None if request.method == "POST": form = FacilityForm(data=request.POST, instance=facil) if form.is_valid(): form.instance.zone_fallback = get_object_or_404(Zone, pk=zone_id) form.save() return HttpResponseRedirect(reverse("central_facility_admin", kwargs={"org_id": org_id, "zone_id": zone_id})) else: form = FacilityForm(instance=facil) return { "form": form, "zone_id": zone_id, }
def facility_form(request, facility_id, org_id=None, zone_id=None): context = control_panel_context(request, org_id=org_id, 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 form.is_valid(): form.instance.zone_fallback = get_object_or_404(Zone, pk=zone_id) form.save() return HttpResponseRedirect( reverse("zone_management", kwargs={ "org_id": org_id, "zone_id": zone_id })) context.update({"form": form}) return context