def new_zaak_for_subject(request, subject_id): '''Create new zaak for a subject''' subject = get_object_or_404(Subject, pk = subject_id) if request.method == "POST": form = NewZaakForSubjectForm(request.POST) #prefilled form from POST data if form.is_valid(): new_zaak = Zaak() new_zaak.subject = subject for k,v in form.cleaned_data.iteritems(): setattr(new_zaak, k, v) new_zaak.save() return HttpResponseRedirect("/subjecten/%s/zaken/" % subject.pk) else: form = NewZaakForSubjectForm() #empty form return render_to_response('subjecten/new_zaak_for_subject.html', {'form': form, 'subject': subject})
def edit(request, zaak_id): """Edit existing zaak. You are not allowed to change subject attributes for an existing zaak.""" # I am reusing NewZaakForSubjectForm because it contains the fields # you are allowed to edit. zaak = get_object_or_404(Zaak, pk=zaak_id) if request.method == "POST": form = NewZaakForSubjectForm(request.POST) # prefilled form from POST data if form.is_valid(): for k, v in form.cleaned_data.iteritems(): setattr(zaak, k, v) zaak.save() return HttpResponseRedirect("/subjecten/%s/zaken/" % zaak.subject.pk) else: form = NewZaakForSubjectForm( initial={"type_zaak": zaak.type_zaak, "opmerkingen": zaak.opmerkingen} ) # empty form return render_to_response("zaken/edit_zaak.html", {"form": form, "zaak": zaak})