def update_data(request, manufacturer_id): """Updates data of manufacturer with given manufacturer id. """ manufacturer = Manufacturer.objects.get(pk=manufacturer_id) form = ManufacturerDataForm(instance=manufacturer, data=request.POST) if form.is_valid(): form.save() msg = _(u"Manufacturer data has been saved.") html = ( ("#data", manufacturer_data_inline(request, manufacturer_id, form)), ("#selectable-manufacturers", selectable_manufacturers_inline(request, manufacturer_id)), ) result = simplejson.dumps({ "html": html, "message": msg }, cls=LazyEncoder) return HttpResponse(result)
def add_manufacturer(request, template_name="manage/manufacturers/add_manufacturer.html"): """Form and logic to add a manufacturer. """ if request.method == "POST": form = ManufacturerDataForm(data=request.POST) if form.is_valid(): new_manufacturer = form.save() return HttpResponseRedirect( reverse("muecke_manufacturer", kwargs={"manufacturer_id": new_manufacturer.id})) else: form = ManufacturerDataForm() return render_to_response(template_name, RequestContext(request, { "form": form, "selectable_manufacturers_inline": selectable_manufacturers_inline(request, 0), "came_from": request.REQUEST.get("came_from", reverse("muecke_manufacturer_dispatcher")), }))