def handle_componentType(request): logger = logging.getLogger("webapp") logger.info("run handle_componentType run") if request.method == "POST": form = ComponentTypeForm(request.POST) if form.is_valid(): t = ComponentType() t.name = form.cleaned_data["name"] t.save() return HttpResponseRedirect("/componenttypes/") else: form = ComponentTypeForm() return render( request, "component/generic_detail.html", {"form": form, "action": "/componenttype/", "http_method": "POST"} )
def edit_componentType(request, componentTypeid=None): logger = logging.getLogger("webapp") logger.info("run edit_ComponentType run") if componentTypeid: t = ComponentType.objects.get(id=int(componentTypeid)) if request.method == "POST": # update record with submitted values logger.info("run submit_edit run") form = ComponentTypeForm(request.POST, instance=t) if form.is_valid(): logger.info("updating ComponentType") logger.info(form.cleaned_data) t.name = form.cleaned_data["name"] t.save() return HttpResponseRedirect("/componenttypes/") return render( request, "component/generic_detail.html", {"form": form, "action": "/componenttype/" + componentTypeid + "/", "http_method": "POST"}, ) else: # load record to allow edition form = ComponentTypeForm(instance=t) return render( request, "component/generic_detail.html", {"form": form, "action": "/componenttype/" + componentTypeid + "/", "http_method": "POST"}, ) else: return HttpResponseRedirect("/componentTypes/")