Пример #1
0
def new(request):
    ctx = {}
    template_name = 'jstnote/form.html'
    form = PasterForm()
    preview = request.POST.get('preview', '')
    if request.method == "POST":
        ctx['paster_body'] = request.POST.get('body', '')
        ctx['paster_markup'] = request.POST.get('markup', '')
        form = PasterForm(request.POST)
        if form.is_valid() and request.POST.get('submit', ''):
            paster = form.save()
            return HttpResponseRedirect(reverse("note_detail", args=[paster.pk]))
    ctx['form'] = form
    ctx['preview'] = preview
    return render(request, template_name, ctx)
Пример #2
0
def edit(request, pk):
    ctx = {}
    template_name = 'jstnote/form.html'
    paster = get_object_or_404(Paster, pk=pk)
    ctx['paster'] = paster
    form = PasterForm(instance=paster)
    preview = request.POST.get('preview', '')
    if request.method == "POST":
        ctx['paster_body'] = request.POST.get('body', '')
        ctx['paster_markup'] = request.POST.get('markup', '')
        form = PasterForm(request.POST, instance=paster)
        if form.is_valid() and request.POST.get('submit', ''):
            form.save()
            messages.info(request, u'成功编辑')
            return HttpResponseRedirect(reverse("note_detail", args=[paster.pk]))
    ctx['form'] = form
    ctx['preview'] = preview
    return render(request, template_name, ctx)