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
Simon Daron
panikweb
Commits
0b880f9f
Commit
0b880f9f
authored
Aug 23, 2013
by
fred
Browse files
performance: turn player into a templatetag
parent
8e600195
Changes
4
Hide whitespace changes
Inline
Side-by-side
panikweb/paniktags/templatetags/paniktags.py
View file @
0b880f9f
import
uuid
from
django
import
template
from
django
import
template
register
=
template
.
Library
()
register
=
template
.
Library
()
...
@@ -5,3 +7,7 @@ register = template.Library()
...
@@ -5,3 +7,7 @@ register = template.Library()
@
register
.
filter
(
name
=
'zip'
)
@
register
.
filter
(
name
=
'zip'
)
def
zip_lists
(
a
,
b
):
def
zip_lists
(
a
,
b
):
return
zip
(
a
,
b
)
return
zip
(
a
,
b
)
@
register
.
inclusion_tag
(
'includes/player.html'
,
takes_context
=
False
)
def
player
():
return
{
'unique'
:
uuid
.
uuid4
()}
panikweb/views.py
View file @
0b880f9f
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
import
math
,
uuid
import
math
from
django.views.generic.base
import
TemplateView
from
django.views.generic.base
import
TemplateView
from
django.views.generic.detail
import
DetailView
from
django.views.generic.detail
import
DetailView
...
@@ -173,7 +173,6 @@ class Home(TemplateView):
...
@@ -173,7 +173,6 @@ class Home(TemplateView):
image__isnull
=
True
).
exclude
(
image__exact
=
''
).
order_by
(
'-datetime'
)[:
3
])
image__isnull
=
True
).
exclude
(
image__exact
=
''
).
order_by
(
'-datetime'
)[:
3
])
context
[
'news'
]
=
list
(
NewsItem
.
objects
.
all
().
order_by
(
'-datetime'
)[:
60
])
context
[
'news'
]
=
list
(
NewsItem
.
objects
.
all
().
order_by
(
'-datetime'
)[:
60
])
context
[
'emissions'
]
=
list
(
Emission
.
objects
.
filter
(
archived
=
False
).
order_by
(
'title'
))
context
[
'emissions'
]
=
list
(
Emission
.
objects
.
filter
(
archived
=
False
).
order_by
(
'title'
))
context
[
'player'
]
=
audioPlayer
()
return
context
return
context
home
=
Home
.
as_view
()
home
=
Home
.
as_view
()
...
@@ -186,7 +185,6 @@ class News(TemplateView):
...
@@ -186,7 +185,6 @@ class News(TemplateView):
context
[
'newsImaged'
]
=
list
(
NewsItem
.
objects
.
all
().
exclude
(
image__isnull
=
True
).
exclude
(
image__exact
=
''
).
order_by
(
'-datetime'
)[:
3
])
context
[
'newsImaged'
]
=
list
(
NewsItem
.
objects
.
all
().
exclude
(
image__isnull
=
True
).
exclude
(
image__exact
=
''
).
order_by
(
'-datetime'
)[:
3
])
context
[
'news'
]
=
list
(
NewsItem
.
objects
.
all
().
order_by
(
'-datetime'
)[:
60
])
context
[
'news'
]
=
list
(
NewsItem
.
objects
.
all
().
order_by
(
'-datetime'
)[:
60
])
context
[
'categories'
]
=
list
(
NewsCategory
.
objects
.
all
())
context
[
'categories'
]
=
list
(
NewsCategory
.
objects
.
all
())
context
[
'player'
]
=
audioPlayer
()
return
context
return
context
news
=
News
.
as_view
()
news
=
News
.
as_view
()
...
@@ -217,15 +215,10 @@ class Listen(TemplateView):
...
@@ -217,15 +215,10 @@ class Listen(TemplateView):
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
Listen
,
self
).
get_context_data
(
**
kwargs
)
context
=
super
(
Listen
,
self
).
get_context_data
(
**
kwargs
)
context
[
'sounds'
]
=
SoundFile
.
objects
.
all
()[:
15
]
context
[
'sounds'
]
=
SoundFile
.
objects
.
all
()[:
15
]
context
[
'player'
]
=
audioPlayer
()
return
context
return
context
listen
=
Listen
.
as_view
()
listen
=
Listen
.
as_view
()
class
audioPlayer
:
def
__init__
(
self
):
self
.
unique
=
uuid
.
uuid4
()
@
csrf_exempt
@
csrf_exempt
@
to_json
(
'api'
)
@
to_json
(
'api'
)
...
...
panikweb_templates/templates/base.html
View file @
0b880f9f
{% load url from future %}{% load i18n %}
<!DOCTYPE html>
{% load url from future %}{% load i18n
%}{% load paniktags
%}
<!DOCTYPE html>
<html>
<html>
<head>
<head>
<title>
Radio Panik {% block title %}{% endblock %}
</title>
<title>
Radio Panik {% block title %}{% endblock %}
</title>
...
@@ -31,7 +31,7 @@
...
@@ -31,7 +31,7 @@
<!--{% block logo %}<img class="logo" src="{{ STATIC_URL }}/img/LogoPanik.jpg"/>{% endblock %}-->
<!--{% block logo %}<img class="logo" src="{{ STATIC_URL }}/img/LogoPanik.jpg"/>{% endblock %}-->
</div>
</div>
<div
id=
"Listen"
>
<div
id=
"Listen"
>
{% block listen %}{%
include "includes/player.html"
%}{% endblock %}
{% block listen %}{%
player
%}{% endblock %}
</div>
</div>
</div>
</div>
...
...
panikweb_templates/templates/includes/player.html
View file @
0b880f9f
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
preload=
"none"
preload=
"none"
class=
"hidden"
class=
"hidden"
tabindex=
"0"
tabindex=
"0"
src=
"http://streaming.domainepublic.net:8000/radiopanik.ogg?&unique={{
player.unique
}}"
src=
"http://streaming.domainepublic.net:8000/radiopanik.ogg?&unique={{
uuid
}}"
controls=
"controls"
controls=
"controls"
></audio>
></audio>
<ul
class=
"inline metas small"
>
<ul
class=
"inline metas small"
>
...
...
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