Пример #1
0
def edit_article(request, slug):
    """Edit an existing article.

    Only staff can edit, but they can edit anything: theirs or not. We're all
    adults here.

    """
    if not request.user.is_staff:
        return HttpResponseForbidden()

    article = get_object_or_404(Article, slug=slug)

    if request.method == 'POST':
        form = ArticleForm(request.POST, instance=article)
        if form.is_valid():
            form.save()
            # TODO: Handle uniqueness violations gracefully.
            return HttpResponseRedirect(reverse('blog.article',
                                        args=[article.slug]))
    else:  # GET
        form = ArticleForm(instance=article)

    # Form is invalid, or it's a GET.
    return _render_contextually(request,
                                'blog/edit_article.html',
                                {'form': form, 'article': article})
Пример #2
0
def edit_article(request, slug):
    """Edit an existing article.

    Only staff can edit, but they can edit anything: theirs or not. We're all
    adults here.

    """
    if not request.user.is_staff:
        return HttpResponseForbidden()

    article = get_object_or_404(Article, slug=slug)

    if request.method == 'POST':
        form = ArticleForm(request.POST, instance=article)
        if form.is_valid():
            form.save()
            # TODO: Handle uniqueness violations gracefully.
            return HttpResponseRedirect(
                reverse('blog.article', args=[article.slug]))
    else:  # GET
        form = ArticleForm(instance=article)

    # Form is invalid, or it's a GET.
    return _render_contextually(request, 'blog/edit_article.html', {
        'form': form,
        'article': article
    })
Пример #3
0
def new_article(request):
    """Show the new-article form or actually create a new article."""
    if not request.user.is_staff:
        return HttpResponseForbidden()

    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.is_valid():
            form.save()
            # TODO: Handle uniqueness violations gracefully.
            return HttpResponseRedirect(
                reverse('blog.article', args=[form.instance.slug]))
    else:  # GET
        form = ArticleForm()

    # Form is invalid, or it's a GET.
    return _render_contextually(request, 'blog/new_article.html',
                                {'form': form})
Пример #4
0
def new_article(request):
    """Show the new-article form or actually create a new article."""
    if not request.user.is_staff:
        return HttpResponseForbidden()

    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.is_valid():
            form.save()
            # TODO: Handle uniqueness violations gracefully.
            return HttpResponseRedirect(reverse('blog.article',
                                        args=[form.instance.slug]))
    else:  # GET
        form = ArticleForm()

    # Form is invalid, or it's a GET.
    return _render_contextually(request,
                                'blog/new_article.html',
                                {'form': form})