Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
14
Issues
14
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
La Quadrature du Net
rpteam
rp
Commits
6a49f62e
Commit
6a49f62e
authored
Apr 27, 2017
by
cynddl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup article views using Article.publish()
parent
cafdb48d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
9 deletions
+15
-9
apps/rp/api/views.py
apps/rp/api/views.py
+1
-2
apps/rp/models/article.py
apps/rp/models/article.py
+9
-0
apps/rp/views/articles.py
apps/rp/views/articles.py
+5
-7
No files found.
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
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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