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
654b3e26
Commit
654b3e26
authored
May 02, 2019
by
Okhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
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
Showing
3 changed files
with
37 additions
and
7 deletions
+37
-7
apps/rp/api/serializers.py
apps/rp/api/serializers.py
+3
-0
apps/rp/models.py
apps/rp/models.py
+9
-6
apps/rp/tests/test_article.py
apps/rp/tests/test_article.py
+25
-1
No files found.
apps/rp/api/serializers.py
View file @
654b3e26
...
@@ -30,6 +30,9 @@ class ArticleSerializer(serializers.ModelSerializer):
...
@@ -30,6 +30,9 @@ class ArticleSerializer(serializers.ModelSerializer):
und_score_down
=
serializers
.
IntegerField
(
und_score_down
=
serializers
.
IntegerField
(
required
=
False
,
required
=
False
,
help_text
=
"This is used to decrease the vote count by this value"
)
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
:
class
Meta
:
model
=
Article
model
=
Article
...
...
apps/rp/models.py
View file @
654b3e26
...
@@ -180,17 +180,21 @@ class Article(VoteMixin):
...
@@ -180,17 +180,21 @@ class Article(VoteMixin):
import
requests
import
requests
url
=
cleanup_url
(
data
.
pop
(
'url'
,
None
))
url
=
cleanup_url
(
data
.
pop
(
'url'
,
None
))
article
,
created
=
Article
.
objects
.
get_or_create
(
url
=
url
,
tags
=
data
.
pop
(
'tags'
,
None
)
defaults
=
data
)
(
article
,
created
)
=
Article
.
objects
.
get_or_create
(
url
=
url
,
defaults
=
data
)
# Is the article was already there, we should upvote it
# 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
:
if
not
created
:
article
.
upvote
(
str
(
by
))
article
.
upvote
(
str
(
by
))
try
:
try
:
r
=
requests
.
get
(
url
,
timeout
=
0.5
)
r
=
requests
.
get
(
url
,
timeout
=
0.5
)
article
.
original_status
=
r
.
status_code
article
.
original_status
=
r
.
status_code
except
:
except
Exception
:
# If the domain name can't be found, we're not even getting into
# 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,
# the HTTP protocol So, let's get a specific status for that,
# one that can be easily identified.
# one that can be easily identified.
...
@@ -199,7 +203,6 @@ class Article(VoteMixin):
...
@@ -199,7 +203,6 @@ class Article(VoteMixin):
return
article
return
article
# Content extraction
# Content extraction
def
fetch_content
(
self
):
def
fetch_content
(
self
):
if
self
.
lang
!=
"NA"
:
if
self
.
lang
!=
"NA"
:
article
=
ArticleParser
(
url
=
self
.
url
,
language
=
self
.
lang
.
lower
())
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):
...
@@ -116,9 +116,33 @@ class TestArticleApi(TestCase):
assert
r
.
data
[
'count'
]
==
0
assert
r
.
data
[
'count'
]
==
0
def
test_api_filter_search
(
self
):
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
text
=
self
.
articles
[
0
].
title
r
=
self
.
client
.
get
(
'/api/articles-search/{}/'
.
format
(
text
))
r
=
self
.
client
.
get
(
'/api/articles-search/{}/'
.
format
(
text
))
assert
r
.
status_code
==
200
assert
r
.
status_code
==
200
assert
r
.
data
[
'count'
]
==
1
assert
r
.
data
[
'count'
]
==
1
assert
r
.
data
[
'results'
][
0
][
'id'
]
==
self
.
articles
[
0
].
id
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