Commit 6a49f62e authored by cynddl's avatar cynddl

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"
article.save()
article.publish()
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
STATUS_CHOICES = (
("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 = datetime.now()
self.status = "PUBLISHED"
self.save()
def parse(self):
article = ArticleParser(url=self.url, language=self.lang)
article.download()
......
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=[self.object.id])
elif "publish" in self.request.POST:
self.object.status = "PUBLISHED"
self.object.save()
self.object.publish()
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'),
css_class="row"),
AppendedText('url',
'<a href="%s">Go to link</a>' % form.initial['url']),
AppendedText(
'url',
_('<a href="%s">Go to link</a>') % form.initial['url']),
'tags',
'extracts',
css_class="col-sm-8")
......@@ -104,7 +105,4 @@ class ArticleEdit(UpdateView):
form.helper.layout = Layout(
Div(left_layout, right_layout, css_class="row"))
form.helper.add_input(
Submit('submit', 'Update the article', css_class='btn-primary'))
return form
Markdown is supported
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