Ejemplo n.º 1
0
def add_article(request):
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.is_valid():
            new_article = form.save(commit=False)
            new_article.author = request.user
            split_content = new_article.content.split(settings.LIBRARY_CUT)
            if len(split_content) > 0:
                new_article.preview = split_content[0]
            if 'save' in request.POST:
                new_article.is_published = True
            if 'draft' in request.POST:
                new_article.is_published = False
            new_article.save()
            form.save_m2m()
            return HttpResponseRedirect(reverse('library_index'))
    else:
        form = ArticleForm()

    return direct_to_template(request, 'flibrary/article_edit.html',{'form':form})
Ejemplo n.º 2
0
def article_edit(request, slug, **kwargs):
    article = Article.objects.get(slug=slug)
    if request.method == 'POST':
        form = ArticleForm(request.POST, instance=article)
        if form.is_valid():
            new_article = form.save(commit=False)
            new_article.author = request.user
            split_content = new_article.content.split(settings.LIBRARY_CUT)
            if len(split_content) > 0:
                new_article.preview = split_content[0]
            if 'save' in request.POST:
                new_article.is_published = True
            if 'draft' in request.POST:
                new_article.is_published = False
            new_article.save()
            form.save_m2m()
            return HttpResponseRedirect(article.get_absolute_url())
    else:
        form = ArticleForm(instance=article)

    return direct_to_template(request, 'flibrary/article_edit.html',
        {'form':form,'article':article})