Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
rpteam
Revue de Press
Commits
6a49f62e
Commit
6a49f62e
authored
Apr 27, 2017
by
cynddl
Browse files
Cleanup article views using Article.publish()
parent
cafdb48d
Changes
3
Hide whitespace changes
Inline
Side-by-side
apps/rp/api/views.py
View file @
6a49f62e
...
...
@@ -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"
)
...
...
apps/rp/models/article.py
View file @
6a49f62e
...
...
@@ -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
()
...
...
apps/rp/views/articles.py
View file @
6a49f62e
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment