Ejemplo n.º 1
0
def preview(request):
    if request.method == "POST":
        form = Paragraph.EditForm(request.POST)
        if form.is_valid():
            p = Paragraph()
            p.text = form.cleaned_data["text"]
            p.title = form.cleaned_data["title"]
            p.last_edit = datetime.datetime.now()
            p.render()
            return HttpResponse(p.rendered)
        else:
            return HttpResponse("Incorrect input")
    else:
        return HttpResponseForbidden("I eat only POST")
Ejemplo n.º 2
0
def add(request, note_id):
    if not request.user.is_authenticated():
        return HttpResponseForbidden(
            '<a href="{0}" target="_blank">Login</a> required'.format(reverse("social:begin", args=("google",)))
        )
    n = get_object_or_404(Note, pk=note_id)
    if request.method == "POST":
        form = Paragraph.EditForm(request.POST)
        if form.is_valid():
            p = Paragraph()
            p.note = n
            p.text = form.cleaned_data["text"]
            p.title = form.cleaned_data["title"]
            p.last_edit = datetime.datetime.now()
            p.render()
            p.save()
            return HttpResponse(p.rendered)
        else:
            return HttpResponseForbidden("Invalid data.")
    else:
        return HttpResponseForbidden("POST, please!")