示例#1
0
文件: views.py 项目: drinks/diff_me
def create(request):
    data = request.POST.copy()
    form = DiffForm(data)
    errors = form.errors

    if not errors:
        diff = Diff(**form.cleaned_data)
        diff.save()
        return redirect(diff_html, base58=diff.base58)
    else:
        return render_to_response("index.html", {"form": form}, context_instance=RequestContext(request))
示例#2
0
文件: views.py 项目: drinks/diff_me
def edit(request, base58=None):
    diff = Diff.objects.get(base58=base58)
    form = DiffForm(instance=diff)

    if request.POST:
        data = request.POST.copy()
        form = DiffForm(data)
        errors = form.errors
        if not errors:
            new_diff = Diff(**form.cleaned_data)
            new_diff.parent = diff.parent or Diff.objects.get(pk=diff.pk)
            new_diff.save()
            return redirect(diff_html, base58=new_diff.base58)
        else:
            return render_to_response(
                "edit.html", {"form": form, "diff": diff}, context_instance=RequestContext(request)
            )

    return render_to_response("edit.html", {"form": form, "diff": diff}, context_instance=RequestContext(request))