Exemplo n.º 1
0
def new_article(request):
    """
    Add a new article to the DB
    """
    form = ArticleForm()
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.validate():
            article = Article()
            form.populate_obj(article)
            article.put()
            return redirect('index')

    context_dict = {'form': form}
    return render(request, 'new_article.html', context_dict)
Exemplo n.º 2
0
def edit_article(request, article_id):
    if request.method == 'POST':
        article_form = ArticleForm(request.POST)
        context_dict = {'article_form': article_form}
        if article_form.validate():
            article = Article()
            article_form.populate_obj(article)
            article.put()
            return redirect('index')
    else:
        # Get the details of the article
        article_id = int(article_id)
        article = Article.get_by_id(article_id)

        article_form = ArticleForm(obj=article)
        context_dict = {'article_form': article_form}

    return render(request, 'edit_article.html', context_dict)