Commit 6a49f62e authored by cynddl's avatar cynddl
Browse files

Cleanup article views using Article.publish()

parent cafdb48d
......@@ -16,8 +16,7 @@ class ArticleViewSet(viewsets.ModelViewSet):
@detail_route(methods=["post"], url_path="publish")
def publish(self, request, pk=None):
article = self.get_object()
article.status = "PUBLISHED"
return self.response_serialized_object(article)
@detail_route(methods=["post"], url_path="reject")
......@@ -5,6 +5,8 @@ from taggit.managers import TaggableManager
from newspaper import Article as ArticleParser
from django_und.models import VoteMixin
from datetime import datetime
("PENDING", _("Pending")),
......@@ -62,6 +64,13 @@ class Article(VoteMixin):
def __str__(self):
return self.title
def publish(self):
if not self.published_at:
self.published_at =
self.status = "PUBLISHED"
def parse(self):
article = ArticleParser(url=self.url, language=self.lang)
from django.http import HttpResponseRedirect
from django.views.generic.detail import DetailView
from django.views.generic.edit import UpdateView
from django.utils.translation import ugettext_lazy as _
from django.urls import reverse
from django import forms
......@@ -65,8 +66,7 @@ class ArticleEdit(UpdateView):
if "preview" in self.request.POST:
self.success_url = reverse("rp:article-preview", args=[])
elif "publish" in self.request.POST:
self.object.status = "PUBLISHED"
self.success_url = reverse("rp:article-list")
return HttpResponseRedirect(self.get_success_url())
......@@ -83,8 +83,9 @@ class ArticleEdit(UpdateView):
Field('title', wrapper_class='col-sm-10'),
Field('lang', wrapper_class='col-sm-2'),
'<a href="%s">Go to link</a>' % form.initial['url']),
_('<a href="%s">Go to link</a>') % form.initial['url']),
......@@ -104,7 +105,4 @@ class ArticleEdit(UpdateView):
form.helper.layout = Layout(
Div(left_layout, right_layout, css_class="row"))
Submit('submit', 'Update the article', css_class='btn-primary'))
return form
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment