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
5db4c8b1
Commit
5db4c8b1
authored
Apr 23, 2017
by
luxcem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
api urls for upvote/downvote/publish/reject
parent
e5551869
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
16 deletions
+67
-16
apps/rp/api/views.py
apps/rp/api/views.py
+31
-0
apps/rp/migrations/0008_auto_20170423_1557.py
apps/rp/migrations/0008_auto_20170423_1557.py
+29
-0
apps/rp/urls.py
apps/rp/urls.py
+5
-0
apps/rp/views/articles.py
apps/rp/views/articles.py
+2
-1
apps/rp/views/votes.py
apps/rp/views/votes.py
+0
-15
No files found.
apps/rp/api/views.py
View file @
5db4c8b1
from
rest_framework
import
viewsets
from
rest_framework.decorators
import
detail_route
from
rest_framework.response
import
Response
from
rp.models
import
Article
from
.serializers
import
ArticleSerializer
...
...
@@ -7,3 +9,32 @@ from .serializers import ArticleSerializer
class
ArticleViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
Article
.
objects
.
all
()
serializer_class
=
ArticleSerializer
def
response_serialized_object
(
self
,
object
):
return
Response
(
self
.
serializer_class
(
object
).
data
)
@
detail_route
(
methods
=
[
"post"
],
url_path
=
"publish"
)
def
publish
(
self
,
request
,
pk
=
None
):
article
=
self
.
get_object
()
article
.
status
=
"PUBLISHED"
article
.
save
()
return
self
.
response_serialized_object
(
article
)
@
detail_route
(
methods
=
[
"post"
],
url_path
=
"reject"
)
def
reject
(
self
,
request
,
pk
=
None
):
article
=
self
.
get_object
()
article
.
status
=
"REJECTED"
article
.
save
()
return
self
.
response_serialized_object
(
article
)
@
detail_route
(
methods
=
[
"post"
],
url_path
=
"upvote"
)
def
upvote
(
self
,
request
,
pk
=
None
):
article
=
self
.
get_object
()
article
.
upvote
(
username
=
request
.
user
.
username
)
return
self
.
response_serialized_object
(
article
)
@
detail_route
(
methods
=
[
"post"
],
url_path
=
"downvote"
)
def
downvote
(
self
,
request
,
pk
=
None
):
article
=
self
.
get_object
()
article
.
downvote
(
username
=
request
.
user
.
username
)
return
self
.
response_serialized_object
(
article
)
apps/rp/migrations/0008_auto_20170423_1557.py
0 → 100644
View file @
5db4c8b1
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-04-23 15:57
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'rp'
,
'0007_article_website'
),
]
operations
=
[
migrations
.
AlterModelOptions
(
name
=
'article'
,
options
=
{
'permissions'
:
((
'can_change_status'
,
'Can change article status'
),
(
'can_change_priority'
,
'Can change article priority'
),
(
'can_vote'
,
'Can vote articles'
)),
'verbose_name'
:
'Article'
,
'verbose_name_plural'
:
'Articles'
},
),
migrations
.
AddField
(
model_name
=
'article'
,
name
=
'priority'
,
field
=
models
.
BooleanField
(
default
=
False
),
),
migrations
.
AlterField
(
model_name
=
'article'
,
name
=
'status'
,
field
=
models
.
CharField
(
choices
=
[(
'PENDING'
,
'Pending'
),
(
'PUBLISHED'
,
'Published'
),
(
'REJECTED'
,
'Rejected'
)],
default
=
'PENDING'
,
max_length
=
20
,
verbose_name
=
'Status'
),
),
]
apps/rp/urls.py
View file @
5db4c8b1
...
...
@@ -8,6 +8,11 @@ urlpatterns = [
ArticleListFlux
.
as_view
(),
name
=
"article-list"
),
url
(
r
"^article/list"
,
ArticleListFlux
.
as_view
(),
name
=
"article-list"
),
url
(
r
"^votes/upvote/(?P<content_type>\d+)/(?P<object_id>\d+)$"
,
upvote
,
...
...
apps/rp/views/articles.py
View file @
5db4c8b1
...
...
@@ -21,5 +21,6 @@ class ArticleListFlux(UDList):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
().
get_context_data
(
**
kwargs
)
context
[
"filter_view"
]
=
self
.
kwargs
.
get
(
"filter_view"
,
"draft"
)
context
[
"nb_draft"
]
=
Article
.
objects
.
filter
(
und_score__gte
=
3
,
status
=
"PENDING"
).
count
()
context
[
"nb_draft"
]
=
Article
.
objects
.
filter
(
und_score__gte
=
3
,
status
=
"PENDING"
).
count
()
return
context
apps/rp/views/votes.py
View file @
5db4c8b1
from
django.views.generic
import
ListView
from
django.contrib.contenttypes.models
import
ContentType
from
django.http
import
HttpResponse
def
upvote
(
request
,
content_type
,
object_id
):
ct
=
ContentType
.
objects
.
get_for_id
(
content_type
)
obj
=
ct
.
get_object_for_this_type
(
pk
=
object_id
)
obj
.
upvote
(
username
=
request
.
user
.
username
)
return
HttpResponse
({
"success"
})
def
downvote
(
request
,
content_type
,
object_id
):
ct
=
ContentType
.
objects
.
get_for_id
(
content_type
)
obj
=
ct
.
get_object_for_this_type
(
pk
=
object_id
)
obj
.
downvote
(
username
=
request
.
user
.
username
)
return
HttpResponse
({
"success"
})
class
UDList
(
ListView
):
...
...
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