@login_required
def editor(request, id):
    """
    Display the article editor.
    """
    article = get_object_or_404(Article, pk=id) if id else None
    if article and not article.can_edit(request):
        raise Http404
    if request.method == 'POST':
        form = EditorForm(instance=article, data=request.POST)
        if form.is_valid():
            creating = article is None
            article = form.save(commit=False)
            if creating:
                article.author = request.user
            article.save()
            messages.info(request, "The article has been saved." if creating else "Your changes to the article have been saved.")
            if 'action' in request.POST and request.POST['action'] == 'continue':
                return redirect('articles:editor', article.id)
            else:
                return redirect(article)
    else:
        form = EditorForm(instance=article)
    return render(request, 'articles/editor.html', {
        'title': 'Edit "%s"' % article if article else 'New Article',
        'form': form,
        'description': "Use the form below to %s." % ('edit the article' if article else 'create an article'),
    })
dataset/ETHPy150Open 2buntu/2buntu-blog/twobuntu/articles/views.py/editor/original