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
radiopanik
panikweb
Commits
290e8b85
Commit
290e8b85
authored
Sep 02, 2013
by
fred
Browse files
add search results on archives pages
parent
c6da002d
Changes
2
Hide whitespace changes
Inline
Side-by-side
panikweb/views.py
View file @
290e8b85
...
...
@@ -10,6 +10,7 @@ from django.views.generic.dates import _date_from_string
from
django.core.paginator
import
Paginator
from
haystack.query
import
SearchQuerySet
from
jsonresponse
import
to_json
from
emissions.models
import
Category
,
Emission
,
Episode
,
Diffusion
,
SoundFile
,
\
...
...
@@ -19,14 +20,19 @@ from emissions.utils import whatsonair, period_program
class
EmissionMixin
:
def
get_emission_context
(
self
,
emission
):
def
get_emission_context
(
self
,
emission
,
episode_ids
=
None
):
context
=
{}
# get all episodes, with an additional attribute to get the date of
# their first diffusion
episodes_queryset
=
Episode
.
objects
.
select_related
()
if
episode_ids
is
not
None
:
episodes_queryset
=
episodes_queryset
.
filter
(
id__in
=
episode_ids
)
else
:
episodes_queryset
=
episodes_queryset
.
filter
(
emission
=
emission
)
context
[
'episodes'
]
=
\
Episode
.
objects
.
select_related
().
filter
(
emission
=
emission
).
extra
(
select
=
{
episodes_queryset
.
extra
(
select
=
{
'first_diffusion'
:
'emissions_diffusion.datetime'
,
},
select_params
=
(
False
,
True
),
...
...
@@ -50,7 +56,6 @@ class EmissionMixin:
return
context
class
EmissionDetailView
(
DetailView
,
EmissionMixin
):
model
=
Emission
...
...
@@ -84,7 +89,16 @@ class EmissionEpisodesDetailView(DetailView, EmissionMixin):
context
=
super
(
EmissionEpisodesDetailView
,
self
).
get_context_data
(
**
kwargs
)
context
[
'sectionName'
]
=
"Emissions"
context
[
'schedules'
]
=
Schedule
.
objects
.
select_related
().
filter
(
emission
=
self
.
object
).
order_by
(
'datetime'
)
context
.
update
(
self
.
get_emission_context
(
self
.
object
))
context
[
'search_query'
]
=
self
.
request
.
GET
.
get
(
'q'
)
if
context
[
'search_query'
]:
# query string
sqs
=
SearchQuerySet
().
filter
(
emission_slug_exact
=
self
.
object
.
slug
,
text
=
context
[
'search_query'
])
episode_ids
=
[
x
.
pk
for
x
in
sqs
]
else
:
episode_ids
=
None
context
.
update
(
self
.
get_emission_context
(
self
.
object
,
episode_ids
=
episode_ids
))
return
context
emissionEpisodes
=
EmissionEpisodesDetailView
.
as_view
()
...
...
panikweb_templates/templates/emissions/episodes.html
View file @
290e8b85
...
...
@@ -8,12 +8,16 @@
<form
method=
"get"
action=
"."
class=
"padded center"
id=
"search-form"
>
<div
class=
"big "
>
<label
for=
"id_q"
>
Rechercher:
</label>
<input
id=
"id_q"
name=
"q"
type=
"text"
>
<input
id=
"id_q"
name=
"q"
type=
"text"
{%
if
search_query
%}
value=
"{{ search_query }}{% endif %}"
>
<button
class=
"icon-search"
></button>
</div>
</form>
<div
class=
"wrapper {% if episodes %}sided{% endif %}"
>
{% if search_query and not episodes %}
<div
class=
"big error padded center"
>
Sorry, no result with your query!
</div>
{% endif %}
<div
id=
"Emission-container"
class=
"emission padded"
>
{% if episodes %}
{% with episodes as episodes %}
...
...
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