def edit_intervention(request, pk): intervention = Intervention.objects.get(pk=pk) form = InterventionForm(request.POST or None, instance=intervention) if request.method == "POST" and form.is_valid(): if "cancel" in request.POST: return redirect("/lifespan/intervention/%s" % pk) with reversion.create_revision(): form.save() reversion.set_user(request.user) comment = request.POST["comment"] or "Changed intervention" reversion.set_comment(comment) log(request, intervention, comment) return redirect("/lifespan/intervention/%s" % pk) ctx = {"intervention": intervention, "form": form, "action": "Edit"} return render_to_response("lifespan/intervention_form.html", ctx, context_instance=RequestContext(request))
def edit_intervention(request, pk): intervention = Intervention.objects.get(pk=pk) form = InterventionForm(request.POST or None, instance=intervention) if request.method == "POST" and form.is_valid(): if "cancel" in request.POST: return redirect('/lifespan/intervention/%s' % pk) with reversion.create_revision(): form.save() reversion.set_user(request.user) comment = request.POST['comment'] or "Changed intervention" reversion.set_comment(comment) log(request, intervention, comment) return redirect('/lifespan/intervention/%s' % pk) ctx = {'intervention': intervention, 'form': form, 'action': 'Edit'} return render_to_response('lifespan/intervention_form.html', ctx, context_instance=RequestContext(request))
def add_intervention(request): form = InterventionForm(request.POST or None) if request.method == "POST" and form.is_valid(): with reversion.create_revision(): intervention = form.save(commit=False) form.save() if isinstance(request.user, AnonymousUser): request.user = User.objects.get(username="******") reversion.set_user(request.user) comment = "Added intervention. %s" % request.POST["comment"] or "" reversion.set_comment(comment) log(request, intervention, comment) msg = "Successfully added intervention." messages.add_message(request, messages.SUCCESS, ugettext(msg)) return redirect("/lifespan/intervention/%s" % intervention.pk) ctx = {"form": form, "action": "Add"} return render_to_response("lifespan/intervention_form.html", ctx, context_instance=RequestContext(request))
def add_intervention(request): form = InterventionForm(request.POST or None) if request.method == "POST" and form.is_valid(): with reversion.create_revision(): intervention = form.save(commit=False) form.save() if isinstance(request.user, AnonymousUser): request.user = User.objects.get(username="******") reversion.set_user(request.user) comment = "Added intervention. %s" % request.POST['comment'] or '' reversion.set_comment(comment) log(request, intervention, comment) msg = "Successfully added intervention." messages.add_message(request, messages.SUCCESS, ugettext(msg)) return redirect('/lifespan/intervention/%s' % intervention.pk) ctx = {'form': form, 'action': 'Add'} return render_to_response('lifespan/intervention_form.html', ctx, context_instance=RequestContext(request))