def request_details(request, request_pk): """Supply request details view""" sreq = get_object_or_404(SupplyRequest, id=request_pk) if request.method == "POST": original_status = sreq.status form = SupplyRequestForm(request.POST, instance=sreq) if form.is_valid(): sreq = form.save(commit=False) sreq.modified = datetime.utcnow() sreq.save() if sreq.status != original_status and \ sreq.requested_by and \ sreq.requested_by.default_connection: # if the status has changed, let's send a message # to the original requester so they know things are # proceeding. text = ("Your request for more %(supply)s at %(loc)s has been updated! " +\ "The new status is: %(status)s.") % \ {"supply": sreq.type.name, "loc": sreq.location.name, "status": sreq.get_status_display().upper()} send_message(sreq.requested_by.default_connection, text) return web_message(request, "Supply request %d status set to %s" % \ (sreq.pk, sreq.get_status_display()), link=reverse("supply_dashboard")) elif request.method == "GET": form = SupplyRequestForm(instance=sreq) return render_to_response(request, "supply/single_request.html", {"sreq": sreq, "form": form})
def edit_location(req, location_type_slug, location_pk): loc_type = get_object_or_404(LocationType, slug=location_type_slug) location = get_object_or_404(Location, pk=location_pk) if req.method == "GET": return render_to_response(req, "locations/location_form.html", { "active_location_type_tab": loc_type.pk, "location": location, # redirect back to this view to save (below) "save_url": reverse("edit_location", kwargs={ "location_type_slug": location_type_slug, "location_pk": location_pk }), # is the map visible? default to 0 (hidden) # since the map makes everything very slow "show_map": int(req.GET.get("map", 0)) }) elif req.method == "POST": # if DELETE was clicked... delete # the object, then and redirect if req.POST.get("delete", ""): pk = location.pk location.delete() return web_message(req, "Location %d deleted" % (pk), link=reverse("locations_dashboard")) # otherwise, just update the object # and display the success message else: location = update_via_querydict(location, req.POST) location.save() return web_message(req, "Location %d saved" % (location.pk), link=reverse("locations_dashboard"))
def add_location(req, location_type_slug): loc_type = get_object_or_404(LocationType, slug=location_type_slug) if req.method == "GET": return render_to_response(req, "locations/location_form.html", { "active_location_type_tab": loc_type.pk, # redirect back to this view to save (below) "save_url": reverse("add_location", kwargs={ "location_type_slug": location_type_slug}), # is the map visible? default to 1 (visible), # since i almost always want to set the location "show_map": int(req.GET.get("map", 1)) }) elif req.method == "POST": location = insert_via_querydict(Location, req.POST, { "type": loc_type }) location.save() return web_message(req, "Location %d saved" % (location.pk), link=reverse("locations_dashboard"))
def request_details(request, request_pk): """Supply request details view""" sreq = get_object_or_404(SupplyRequest, id=request_pk) if request.method == "POST": original_status = sreq.status form = SupplyRequestForm(request.POST, instance=sreq) if form.is_valid(): sreq = form.save(commit=False) sreq.modified = datetime.utcnow() sreq.save() if sreq.status != original_status and \ sreq.requested_by and \ sreq.requested_by.default_connection: # if the status has changed, let's send a message # to the original requester so they know things are # proceeding. text = ("Your request for more %(supply)s at %(loc)s has been updated! " +\ "The new status is: %(status)s.") % \ {"supply": sreq.type.name, "loc": sreq.location.name, "status": sreq.get_status_display().upper()} send_message(sreq.requested_by.default_connection, text) return web_message(request, "Supply request %d status set to %s" % \ (sreq.pk, sreq.get_status_display()), link=reverse("supply_dashboard")) elif request.method == "GET": form = SupplyRequestForm(instance=sreq) return render_to_response(request, "supply/single_request.html", { "sreq": sreq, "form": form })