def articles_edit(request, article_id): try: article_id = int(url_decode(str(article_id))) except (ValueError, TypeError): raise Http404("Invalid article ID") article = get_object_or_404(Article, id=article_id) user = request.user if user.id != article.author.id and not user.has_perm('articles.can_publish'): return HttpResponseForbidden("Invalid") form = ArticleForm(request.POST or None, request.FILES or None, instance=article) if request.method == 'POST': post = request.POST.copy() if form.is_valid(): form.save() messages.success(request, "Draft successfully saved") if post['action'] == 'save-and-close': return redirect('contribute:articles_list') elif post['action'] == 'save-and-continue': article = get_object_or_404(Article, id=article_id) form = ArticleForm(instance=article) else: form = ArticleForm(post) return render(request, 'contribute/articles_edit.html', {'form': form, 'article': article})
def articles_preview(request, article_id): try: article_id = int(url_decode(str(article_id))) except (ValueError, TypeError): raise Http404("Invalid preview URL") article = get_object_or_404(Article, id=article_id) user = request.user if user.id != article.author.id and not user.has_perm('articles.can_publish'): return HttpResponseForbidden("Invalid") return render(request, 'contribute/article_preview.html', {'article': article})
def articles_unsubmit(request, article_id): try: article_id = int(url_decode(str(article_id))) except (ValueError, TypeError): raise Http404("Invalid article ID") article = get_object_or_404(Article, id=article_id) user = request.user if user.id != article.author.id and not user.has_perm('articles.can_publish'): return HttpResponseForbidden("Invalid") article.status = Article.DRAFT article.save() messages.success(request, "Article \"{}\" successfully unsubmitted for publication.".format(article.title)) return redirect('contribute:articles_list')