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
panikdb
Commits
30b6aafa
Commit
30b6aafa
authored
Aug 28, 2013
by
Simon Daron
Browse files
Ad brother episodes for episode view to allow nav
parent
afd4df05
Changes
1
Hide whitespace changes
Inline
Side-by-side
panikdb/emissions/views.py
View file @
30b6aafa
...
...
@@ -122,6 +122,30 @@ class EpisodeDetailView(DetailView):
context
[
'add_soundfile_form'
]
=
SoundFileForm
(
initial
=
{
'episode'
:
self
.
object
})
context
[
'add_diffusion_form'
]
=
DiffusionForm
(
initial
=
{
'episode'
:
self
.
object
})
context
[
'emission'
]
=
Emission
.
objects
.
get
(
slug
=
self
.
kwargs
.
get
(
'emission_slug'
))
# get all episodes, with an additional attribute to get the date of
# their first diffusion
context
[
'episodes'
]
=
\
Episode
.
objects
.
filter
(
emission
=
context
[
'emission'
]
).
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'
)
# get all related soundfiles in a single query
soundfiles
=
{}
for
soundfile
in
SoundFile
.
objects
.
filter
(
podcastable
=
True
,
fragment
=
False
,
episode__emission
=
self
.
object
):
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
)
return
context
...
...
Write
Preview
Supports
Markdown
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