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
a725135e
Commit
a725135e
authored
May 15, 2019
by
Okhin
Browse files
Adding the needed methods and views into the API
parent
9c347d50
Pipeline
#2605
passed with stages
in 3 minutes and 3 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/rp/api/serializers.py
View file @
a725135e
...
...
@@ -24,7 +24,8 @@ class ArticleSerializer(serializers.ModelSerializer):
class
Meta
:
model
=
Article
fields
=
(
'id'
,
'url'
,
'title'
,
'tags'
,
'extracts'
,
'status'
,
'score'
,
'priority'
)
'status'
,
'score'
,
'priority'
,
'archive'
,
'quote'
,
'speak'
)
def
create
(
self
,
validated_data
):
article
=
Article
.
add_new_url
(
**
validated_data
)
...
...
apps/rp/factories.py
View file @
a725135e
...
...
@@ -25,7 +25,7 @@ class ArticleFactory(factory.django.DjangoModelFactory):
published_at
=
FuzzyDateTime
(
datetime
.
datetime
(
2014
,
1
,
1
,
tzinfo
=
pytz
.
UTC
))
status
=
FuzzyChoice
(
STATUS_CHOICES
)
status
=
FuzzyChoice
(
[
s
[
0
]
for
s
in
STATUS_CHOICES
]
)
@
factory
.
post_generation
def
tags
(
self
,
create
,
extracted
,
**
kwargs
):
...
...
apps/rp/models.py
View file @
a725135e
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.core
import
files
from
django.contrib.auth.decorators
import
permission_required
from
taggit.managers
import
TaggableManager
from
newspaper
import
Article
as
ArticleParser
,
ArticleException
...
...
@@ -103,7 +104,7 @@ class Article(models.Model):
#: If the article is quoting something LQDN said or wrote
quote
=
models
.
BooleanField
(
_
(
"Article directly quotes us"
),
default
=
False
)
default
=
False
)
#: If the article speaks about something LQDN did or wrote
speak
=
models
.
BooleanField
(
_
(
"Article speaks of us"
),
default
=
False
)
...
...
@@ -131,20 +132,20 @@ class Article(models.Model):
"""Toggle the speak flag"""
self
.
speak
=
not
self
.
speak
self
.
save
()
return
self
def
toggle_archive
(
self
):
"""Toggle the archive flag"""
self
.
archive
=
not
self
.
archive
self
.
save
()
return
self
def
toggle_quote
(
self
):
"""Toggle the quote flag"""
self
.
quote
=
not
self
.
quote
self
.
save
()
return
self
@
transition
(
field
=
status
,
source
=
[
'DRAFT'
,
'NEW'
,
'PUBLISHED'
],
target
=
RETURN_VALUE
(
'DRAFT'
,
'NEW'
,
'PUBLISHED'
,),
permission
=
"rp.can_edit"
)
def
set_flags
(
self
,
archive
=
False
,
speak
=
False
,
quote
=
False
):
"""
This method is used to set _all_ the flags in the state their given as
...
...
@@ -154,10 +155,9 @@ class Article(models.Model):
self
.
speak
=
speak
self
.
quote
=
quote
self
.
save
()
return
self
return
self
.
status
# Finite state logic
@
transition
(
field
=
status
,
source
=
'DRAFT'
,
target
=
'PUBLISHED'
,
permission
=
"rp.can_change_status"
)
def
publish
(
self
):
...
...
apps/rp/tests/test_article.py
View file @
a725135e
...
...
@@ -11,6 +11,7 @@ from rp.views.articles import ArticleList
class
TestArticle
(
TestCase
):
def
setUp
(
self
):
self
.
article
=
ArticleFactory
()
self
.
newarticle
=
ArticleFactory
(
status
=
'NEW'
)
def
test_init
(
self
):
assert
RpConfig
.
name
==
"rp"
...
...
@@ -37,6 +38,53 @@ class TestArticle(TestCase):
assert
article_again
.
status
==
'NEW'
assert
article_again
.
score
==
2
def
test_flags
(
self
):
assert
not
self
.
article
.
archive
assert
not
self
.
article
.
quote
assert
not
self
.
article
.
speak
def
test_toggle_flags
(
self
):
self
.
newarticle
.
toggle_archive
()
assert
self
.
newarticle
.
archive
self
.
newarticle
.
toggle_archive
()
assert
not
self
.
newarticle
.
archive
self
.
newarticle
.
toggle_quote
()
assert
self
.
newarticle
.
quote
self
.
newarticle
.
toggle_quote
()
assert
not
self
.
newarticle
.
quote
self
.
newarticle
.
toggle_speak
()
assert
self
.
newarticle
.
speak
self
.
newarticle
.
toggle_speak
()
assert
not
self
.
newarticle
.
speak
def
test_set_flags
(
self
):
# Method signature is set_flags(boolean: archive = False,
# boolean: speak = False,
# boolean: quote = False)
# All falsg set to their default values
self
.
newarticle
.
set_flags
()
assert
not
self
.
newarticle
.
archive
assert
not
self
.
newarticle
.
speak
assert
not
self
.
newarticle
.
quote
self
.
newarticle
.
set_flags
(
speak
=
True
)
assert
not
self
.
newarticle
.
archive
assert
self
.
newarticle
.
speak
assert
not
self
.
newarticle
.
quote
self
.
newarticle
.
set_flags
(
quote
=
True
)
assert
not
self
.
newarticle
.
archive
assert
not
self
.
newarticle
.
speak
assert
self
.
newarticle
.
quote
self
.
newarticle
.
set_flags
(
quote
=
True
,
speak
=
True
)
assert
not
self
.
newarticle
.
archive
assert
self
.
newarticle
.
speak
assert
self
.
newarticle
.
quote
class
TestArticleViews
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
Client
()
...
...
@@ -68,14 +116,6 @@ class TestArticleViews(TestCase):
r
=
self
.
client
.
get
(
'/rp/by-tag/zogzog'
)
assert
len
(
r
.
context
[
'object_list'
])
==
0
def
test_filter_view
(
self
):
new
=
[
article
for
article
in
self
.
articles
if
article
.
status
==
'NEW'
]
r
=
self
.
client
.
get
(
'/rp/by-tag/new'
)
assert
len
(
r
.
context
[
'object_list'
])
==
len
(
new
)
r
=
self
.
client
.
get
(
'/rp/by-tag/nosuchtag'
)
assert
len
(
r
.
context
[
'object_list'
])
==
0
def
test_search_view
(
self
):
article
=
ArticleFactory
(
title
=
u
'Zog Zog chez les schtroumphs'
,
lang
=
'FR'
)
...
...
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