Exemple #1
0
def edit(request, zapisek, template="zapisnik/edit.html"):
    article_form = None

    zapisnik = Zapisnik(site=request.site, owner=request.site_owner, visitor=request.user)

    article = Article.objects.get(pk=zapisek)

    if request.method == "POST":
        article_form = ArticleForm(request.POST)

        if article_form.is_valid():
            article.djangomarkup_description = article_form.cleaned_data["annotation"]
            article.title = article_form.cleaned_data["title"]
            article.tags = article_form.cleaned_data["tags"]

            article.content.djangomarkup_content = article_form.cleaned_data["content"]
            article.content.title = article.title

            article.content.save()
            article.save()

            return HttpResponseRedirect(reverse("zapisnik-edit", kwargs={"zapisek": article.pk}))

    if not article_form:
        article_form = ArticleForm(
            {
                "annotation": article.djangomarkup_description,
                "title": article.title,
                "content": article.content.djangomarkup_content,
                "tags": ", ".join([tag.name for tag in article.tags]),
            }
        )

    return direct_to_template(request, template, {"article_form": article_form, "article": article})
Exemple #2
0
def new(request, template="zapisnik/new.html"):
    article_form = None

    if request.method == "POST":
        article_form = ArticleForm(request.POST)
        if article_form.is_valid():

            zapisnik = Zapisnik(site=request.site, owner=request.site_owner, visitor=request.user)
            article = zapisnik.create_article_draft(
                annotation=article_form.cleaned_data["annotation"],
                title=article_form.cleaned_data["title"],
                content=article_form.cleaned_data["content"],
                tags=article_form.cleaned_data["tags"],
            )

            # TODO: redirect to article
            return HttpResponseRedirect(reverse("zapisnik-edit", kwargs={"zapisek": article.pk}))

    if not article_form:
        article_form = ArticleForm()

    return direct_to_template(request, template, {"article_form": article_form})