Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
radiopanik
panikweb
Commits
0a2f32c0
Commit
0a2f32c0
authored
Sep 15, 2013
by
fred
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
listen archives page
parent
fec22fea
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
80 additions
and
55 deletions
+80
-55
panikweb/paniktags/templatetags/paniktags.py
panikweb/paniktags/templatetags/paniktags.py
+5
-3
panikweb/search.py
panikweb/search.py
+32
-4
panikweb/urls.py
panikweb/urls.py
+1
-1
panikweb/views.py
panikweb/views.py
+1
-33
panikweb_templates/templates/listen.html
panikweb_templates/templates/listen.html
+2
-2
panikweb_templates/templates/listen/archives.html
panikweb_templates/templates/listen/archives.html
+35
-8
panikweb_templates/templates/listen/nav.html
panikweb_templates/templates/listen/nav.html
+1
-1
panikweb_templates/templates/soundfiles/resume.html
panikweb_templates/templates/soundfiles/resume.html
+3
-3
No files found.
panikweb/paniktags/templatetags/paniktags.py
View file @
0a2f32c0
...
...
@@ -11,6 +11,7 @@ from django.db.models.query import QuerySet
from
django.utils
import
simplejson
from
datetime
import
datetime
,
timedelta
from
emissions.models
import
Emission
,
Episode
,
NewsItem
from
emissions.utils
import
period_program
from
panikweb
import
utils
...
...
@@ -94,8 +95,9 @@ def emission_inline(context, date=None):
}
@
register
.
inclusion_tag
(
'soundfiles/resume.html'
)
def
soundfile_resume
(
soundfile
):
return
{
'soundfile'
:
soundfile
}
def
soundfile_resume
(
soundfile
,
date
=
None
):
return
{
'soundfile'
:
soundfile
,
'date'
:
date
}
@
register
.
inclusion_tag
(
'includes/player.html'
,
takes_context
=
False
)
def
player
():
...
...
@@ -225,5 +227,5 @@ def rfc822(datetime):
@
register
.
inclusion_tag
(
'includes/related.html'
,
takes_context
=
False
)
def
related_objects
(
object
):
sqs
=
search
.
MoreLikeThisSearchQuerySet
()
sqs
=
search
.
MoreLikeThisSearchQuerySet
()
.
models
(
Emission
,
Episode
,
NewsItem
)
return
{
'more_like_this'
:
sqs
.
more_like_this
(
object
)[:
12
]}
panikweb/search.py
View file @
0a2f32c0
import
haystack.backends.solr_backend
from
haystack.query
import
SearchQuerySet
from
haystack.query
import
SearchQuerySet
,
RelatedSearchQuerySet
from
haystack.constants
import
ID
,
DJANGO_CT
,
DJANGO_ID
from
haystack.utils
import
get_identifier
from
haystack.backends
import
EmptyResults
from
pysolr
import
SolrError
from
django.conf
import
settings
from
emissions.models
import
Emission
,
Episode
,
NewsItem
,
SoundFile
class
MoreLikeThisSearchQuerySet
(
SearchQuerySet
):
def
more_like_this
(
self
,
model_instance
,
**
kwargs
):
...
...
@@ -110,8 +111,9 @@ class CustomSolrSearchBackend(haystack.backends.solr_backend.SolrSearchBackend):
haystack
.
backends
.
solr_backend
.
SolrEngine
.
query
=
CustomSolrSearchQuery
haystack
.
backends
.
solr_backend
.
SolrEngine
.
backend
=
CustomSolrSearchBackend
import
haystack.views
from
haystack.views
import
search_view_factory
,
FacetedSearchView
from
haystack.forms
import
FacetedSearchForm
from
haystack.forms
import
FacetedSearchForm
,
SearchForm
class
SearchView
(
FacetedSearchView
):
...
...
@@ -126,8 +128,34 @@ class SearchView(FacetedSearchView):
if
x
.
startswith
(
'tags_exact'
)]
return
context
sqs
=
SearchQuerySet
().
facet
(
'categories'
).
facet
(
'tags'
)
sqs
=
SearchQuerySet
().
models
(
Emission
,
Episode
,
NewsItem
).
facet
(
'categories'
).
facet
(
'tags'
)
view
=
search_view_factory
(
SearchView
,
form_class
=
FacetedSearchForm
,
searchqueryset
=
sqs
)
class
ListenArchivesForm
(
SearchForm
):
def
no_query_found
(
self
):
return
self
.
searchqueryset
.
all
()
def
search
(
self
):
sqs
=
super
(
ListenArchivesForm
,
self
).
search
()
return
sqs
.
load_all
()
class
ListenArchivesView
(
haystack
.
views
.
SearchView
):
template
=
'listen/archives.html'
def
__init__
(
self
):
sqs
=
RelatedSearchQuerySet
().
filter
(
django_ct
=
'emissions.soundfile'
).
order_by
(
'-date'
)
super
(
ListenArchivesView
,
self
).
__init__
(
searchqueryset
=
sqs
,
form_class
=
ListenArchivesForm
,
results_per_page
=
20
)
def
extra_context
(
self
):
context
=
super
(
ListenArchivesView
,
self
).
extra_context
()
context
[
'sectionName'
]
=
"Listen"
return
context
listenArchives
=
search_view_factory
(
ListenArchivesView
)
panikweb/urls.py
View file @
0a2f32c0
...
...
@@ -20,7 +20,7 @@ urlpatterns = patterns('',
url
(
r
'^ckeditor/'
,
include
(
'ckeditor.urls'
)),
url
(
r
'^emissions/archives$'
,
'panikweb.views.emissionsArchives'
,
name
=
'emissionsArchives'
),
url
(
r
'^listen/$'
,
'panikweb.views.listen'
,
name
=
'listen'
),
url
(
r
'^listen/archives/$'
,
'panikweb.
views
.listenArchives'
,
name
=
'listenArchives'
),
url
(
r
'^listen/archives/$'
,
'panikweb.
search
.listenArchives'
,
name
=
'listenArchives'
),
url
(
r
'^news/$'
,
'panikweb.views.news'
,
name
=
'news'
),
url
(
r
'^news/archives/$'
,
'panikweb.views.newsArchives'
,
name
=
'newsArchives'
),
url
(
r
'^news/(?P<slug>[\w,-]+)$'
,
'panikweb.views.newsitemview'
,
name
=
'news-view'
),
...
...
panikweb/views.py
View file @
0a2f32c0
...
...
@@ -519,7 +519,7 @@ class Listen(TemplateView):
where
=
[
'''datetime = (SELECT MIN(datetime)
FROM emissions_diffusion
WHERE episode_id = emissions_episode.id)'''
],
tables
=
[
'emissions_diffusion'
],).
order_by
(
'-first_diffusion'
)
[:
2
0
]
tables
=
[
'emissions_diffusion'
],).
order_by
(
'-first_diffusion'
)
[:
1
0
]
context
[
'categories'
]
=
Category
.
objects
.
all
()
...
...
@@ -527,38 +527,6 @@ class Listen(TemplateView):
listen
=
Listen
.
as_view
()
class
ListenArchives
(
TemplateView
):
template_name
=
'listen/archives.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
ListenArchives
,
self
).
get_context_data
(
**
kwargs
)
context
[
'sectionName'
]
=
"Listen"
context
[
'episodes'
]
=
Episode
.
objects
.
filter
(
soundfile__podcastable
=
True
,
soundfile__fragment
=
False
)
\
.
select_related
().
extra
(
select
=
{
'first_diffusion'
:
'emissions_diffusion.datetime'
,
},
select_params
=
(
False
,
True
),
where
=
[
'''datetime = (SELECT MIN(datetime)
FROM emissions_diffusion
WHERE episode_id = emissions_episode.id)'''
],
tables
=
[
'emissions_diffusion'
],).
order_by
(
'-first_diffusion'
)
[:
60
]
# get all related soundfiles in a single query
soundfiles
=
{}
for
soundfile
in
SoundFile
.
objects
.
select_related
().
filter
(
podcastable
=
True
,
fragment
=
False
,
episode__in
=
[
x
.
id
for
x
in
context
[
'episodes'
]]):
soundfiles
[
soundfile
.
episode_id
]
=
soundfile
# replace dynamic property by a static attribute, to avoid database
# lookups
for
episode
in
context
[
'episodes'
]:
episode
.
main_sound
=
soundfiles
.
get
(
episode
.
id
)
context
[
'categories'
]
=
Category
.
objects
.
all
()
return
context
listenArchives
=
ListenArchives
.
as_view
()
@
cache_control
(
max_age
=
25
)
@
csrf_exempt
@
to_json
(
'api'
)
...
...
panikweb_templates/templates/listen.html
View file @
0a2f32c0
...
...
@@ -6,10 +6,10 @@
{% block main %}
<div
class=
""
>
<div
class=
"wrapper"
>
<ul
class=
"padded custom
columns
list"
>
<ul
class=
"padded custom list"
>
{% for soundfile in soundfiles %}
<li
class=
"item {% if soundfile.episode.emission.categories.all.count = 0 %}nocat{% endif %} {% for category in soundfile.episode.emission.categories.all %} {{ category|slugify }}{% endfor %}"
>
{% soundfile_resume soundfile=soundfile %}
{% soundfile_resume soundfile=soundfile
date=soundfile.first_diffusion
%}
</li>
{% endfor %}
</ul>
...
...
panikweb_templates/templates/listen/archives.html
View file @
0a2f32c0
...
...
@@ -3,14 +3,41 @@
{% block title %}Listen - Archives{% endblock %}
{% block nav %}
{% listen_nav with klass="archives" %}
<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"
{%
if
search_query
%}
value=
"{{ search_query }}{% endif %}"
>
<button
class=
"icon-search"
></button>
</div>
</form>
{% endblock %}
{% block main %}
<form
method=
"get"
action=
"."
class=
"padded center"
id=
"search-form"
>
<div
class=
"big"
>
{{ form.as_table }}
<button
class=
"icon-search"
></button>
</div>
</form>
<div
class=
"wrapper"
>
{% if not page.object_list %}
<div
class=
"big error padded center"
>
Sorry, no result with your query!
</div>
{% else %}
{% if page.has_previous %}
<div
class=
"previous-page cf"
>
<a
class=
"button big left"
href=
"?q={{ query }}&page={{ page.previous_page_number }}"
>
«
Résultats précédénts
</a>
</div>
{% endif %}
<ul
class=
"padded custom columns list"
>
{% for result in page.object_list %}
<li>
{% soundfile_resume soundfile=result.object date=result.date %}
</li>
{% endfor %}
</ul>
{% if page.has_next %}
<div
class=
"next-page cf"
>
<a
class=
"button big right"
href=
"?q={{ query }}&page={{ page.next_page_number }}"
>
Résultats suivants
»
</a>
</div>
{% endif %}
{% endif %}
</div>
{% endblock %}
panikweb_templates/templates/listen/nav.html
View file @
0a2f32c0
...
...
@@ -4,7 +4,7 @@
<ul
class=
"inline padded"
>
<li><a
href=
"{% url 'listen' %}"
class=
"{% if class != "
archives
"
%}
active
{%
endif
%}"
>
<span
class=
"icon-bolt"
></span>
<span
class=
"iconLabel"
>
Derni
èr
es
</span>
<span
class=
"iconLabel"
>
Dernie
r
s
</span>
</a></li>
<li><a
href=
"{% url 'listenArchives' %}"
class=
"{% if class = "
archives
"
%}
active
{%
endif
%}"
>
<span
class=
"icon-archive"
></span>
...
...
panikweb_templates/templates/soundfiles/resume.html
View file @
0a2f32c0
...
...
@@ -4,9 +4,9 @@
<div
class=
"episode inline cf"
>
<div
class=
"dateBloc"
>
<div
class=
"date"
>
<div
class=
"day"
>
{{
soundfile.first_diffusion
|date:"D"|slice:":2"}}
</div>
<div
class=
"number"
>
{{
soundfile.first_diffusion
|date:"d" }}
</div>
<div
class=
"month"
>
{{
soundfile.first_diffusion
|date:"M y" }}
</div>
<div
class=
"day"
>
{{
date
|date:"D"|slice:":2"}}
</div>
<div
class=
"number"
>
{{
date
|date:"d" }}
</div>
<div
class=
"month"
>
{{
date
|date:"M y" }}
</div>
</div>
</div>
<div
class=
"logo"
>
...
...
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