Skip to content
GitLab
Menu
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
654b3e26
Commit
654b3e26
authored
May 02, 2019
by
Okhin
Browse files
Ajoute les tags à la création d'un article si celui-ci existe déjà
parent
4f13cfe3
Pipeline
#2574
failed with stages
in 1 minute and 6 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/rp/api/serializers.py
View file @
654b3e26
...
...
@@ -30,6 +30,9 @@ class ArticleSerializer(serializers.ModelSerializer):
und_score_down
=
serializers
.
IntegerField
(
required
=
False
,
help_text
=
"This is used to decrease the vote count by this value"
)
und_score
=
serializers
.
IntegerField
(
required
=
False
,
help_text
=
"This is the actual computed score for an Article"
)
class
Meta
:
model
=
Article
...
...
apps/rp/models.py
View file @
654b3e26
...
...
@@ -180,17 +180,21 @@ class Article(VoteMixin):
import
requests
url
=
cleanup_url
(
data
.
pop
(
'url'
,
None
))
article
,
created
=
Article
.
objects
.
get_or_create
(
url
=
url
,
defaults
=
data
)
# Is the article was already there, we should upvote it
tags
=
data
.
pop
(
'tags'
,
None
)
(
article
,
created
)
=
Article
.
objects
.
get_or_create
(
url
=
url
,
defaults
=
data
)
# Let's add the tags
if
tags
:
article
.
tags
.
add
(
','
.
join
([
t
for
t
in
tags
if
len
(
t
)
>
0
]))
# If the article was already there, we should upvote it
if
not
created
:
article
.
upvote
(
str
(
by
))
try
:
r
=
requests
.
get
(
url
,
timeout
=
0.5
)
article
.
original_status
=
r
.
status_code
except
:
except
Exception
:
# If the domain name can't be found, we're not even getting into
# the HTTP protocol So, let's get a specific status for that,
# one that can be easily identified.
...
...
@@ -199,7 +203,6 @@ class Article(VoteMixin):
return
article
# Content extraction
def
fetch_content
(
self
):
if
self
.
lang
!=
"NA"
:
article
=
ArticleParser
(
url
=
self
.
url
,
language
=
self
.
lang
.
lower
())
...
...
apps/rp/tests/test_article.py
View file @
654b3e26
...
...
@@ -116,9 +116,33 @@ class TestArticleApi(TestCase):
assert
r
.
data
[
'count'
]
==
0
def
test_api_filter_search
(
self
):
#text = ' '.join(self.articles[0].extracts.split(' ')[:10])
#
text = ' '.join(self.articles[0].extracts.split(' ')[:10])
text
=
self
.
articles
[
0
].
title
r
=
self
.
client
.
get
(
'/api/articles-search/{}/'
.
format
(
text
))
assert
r
.
status_code
==
200
assert
r
.
data
[
'count'
]
==
1
assert
r
.
data
[
'results'
][
0
][
'id'
]
==
self
.
articles
[
0
].
id
def
test_api_tag_push_unauth
(
self
):
a
=
ArticleFactory
(
tags
=
[
'ZogZog'
],)
r
=
self
.
client
.
post
(
'/api/articles/'
,
{
'url'
:
a
.
url
,
'title'
:
a
.
title
,
'tags'
:
','
.
join
([
t
.
name
for
t
in
a
.
tags
.
all
()])
})
assert
r
.
status_code
==
401
def
test_api_tag_push_auth
(
self
):
self
.
client
.
force_login
(
user
=
self
.
user
)
a
=
ArticleFactory
(
tags
=
[
'ZogZog'
],
status
=
'NEW'
)
r
=
self
.
client
.
post
(
'/api/articles/'
,
{
'url'
:
a
.
url
,
'title'
:
a
.
title
,
'tags'
:
','
.
join
([
t
.
name
for
t
in
a
.
tags
.
all
()])
})
assert
r
.
status_code
==
201
# Need to test if we keep the tags
r
=
self
.
client
.
post
(
'/api/articles/'
,
{
'url'
:
a
.
url
,
'title'
:
a
.
title
,
'tags'
:
''
})
assert
[
t
.
name
for
t
in
a
.
tags
.
all
()]
==
r
.
data
[
'tags'
]
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