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
7b9e9cc7
Verified
Commit
7b9e9cc7
authored
Sep 11, 2017
by
Thibaut Broggi
Browse files
Add search feature in RSS feed
parent
75c766ec
Pipeline
#1221
passed with stages
in 1 minute and 57 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/rp/feeds/feeds.py
View file @
7b9e9cc7
from
django.contrib.syndication.views
import
Feed
from
django.urls
import
reverse
from
django.db.models
import
Q
from
rp.models
import
Article
class
ArticlesFeed
(
Feed
):
...
...
@@ -37,7 +38,20 @@ class ArticlesTagsFeed(ArticlesFeed):
pass
def
items
(
self
):
return
Article
.
objects
.
filter
(
tags__name__in
=
[
self
.
filter_tag
])[:
25
]
return
Article
.
objects
.
filter
(
tags__name__in
=
[
self
.
filter_tag
])
\
.
order_by
(
'-created_at'
)[:
25
]
def
get_object
(
self
,
request
,
filter_tag
):
self
.
filter_tag
=
filter_tag
class
ArticlesSearchFeed
(
ArticlesFeed
):
def
__init__
(
self
,
**
kwargs
):
pass
def
items
(
self
):
return
Article
.
objects
.
filter
(
Q
(
title__icontains
=
self
.
search_keywords
)
|
Q
(
extracts__icontains
=
self
.
search_keywords
))
\
.
order_by
(
'-created_at'
)[:
25
]
def
get_object
(
self
,
request
,
search_keywords
):
self
.
search_keywords
=
search_keywords
apps/rp/feeds/urls.py
View file @
7b9e9cc7
from
django.conf.urls
import
url
from
.feeds
import
ArticlesFeed
,
ArticlesTagsFeed
from
.feeds
import
ArticlesFeed
,
ArticlesTagsFeed
,
ArticlesSearchFeed
urlpatterns
=
[
url
(
r
'^$'
,
ArticlesFeed
(
filter_lang
=
'FR'
),
name
=
'articles-feed'
),
url
(
r
'^international$'
,
ArticlesFeed
(
filter_lang
=
'EN'
),
name
=
'articles-feed-international'
),
url
(
r
'^by-tag/(?P<filter_tag>.*)'
,
ArticlesTagsFeed
())
url
(
r
'^by-tag/(?P<filter_tag>.*)'
,
ArticlesTagsFeed
()),
url
(
r
'^search/(?P<search_keywords>.*)'
,
ArticlesSearchFeed
())
]
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