Commit 0b880f9f authored by fred's avatar fred

performance: turn player into a templatetag

parent 8e600195
import uuid
from django import template
register = template.Library()
......@@ -5,3 +7,7 @@ register = template.Library()
@register.filter(name='zip')
def zip_lists(a, b):
return zip(a, b)
@register.inclusion_tag('includes/player.html', takes_context=False)
def player():
return {'unique': uuid.uuid4()}
from datetime import datetime, timedelta
import math, uuid
import math
from django.views.generic.base import TemplateView
from django.views.generic.detail import DetailView
......@@ -173,7 +173,6 @@ class Home(TemplateView):
image__isnull=True).exclude(image__exact='').order_by('-datetime')[:3])
context['news'] = list(NewsItem.objects.all().order_by('-datetime')[:60])
context['emissions'] = list(Emission.objects.filter(archived=False).order_by('title'))
context['player'] = audioPlayer()
return context
home = Home.as_view()
......@@ -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['news'] = list(NewsItem.objects.all().order_by('-datetime')[:60])
context['categories'] = list(NewsCategory.objects.all())
context['player'] = audioPlayer()
return context
news = News.as_view()
......@@ -217,15 +215,10 @@ class Listen(TemplateView):
def get_context_data(self, **kwargs):
context = super(Listen, self).get_context_data(**kwargs)
context['sounds'] = SoundFile.objects.all()[:15]
context['player'] = audioPlayer()
return context
listen = Listen.as_view()
class audioPlayer:
def __init__(self):
self.unique = uuid.uuid4()
@csrf_exempt
@to_json('api')
......
{% load url from future %}{% load i18n %}<!DOCTYPE html>
{% load url from future %}{% load i18n %}{% load paniktags %}<!DOCTYPE html>
<html>
<head>
<title>Radio Panik {% block title %}{% endblock %}</title>
......@@ -31,7 +31,7 @@
<!--{% block logo %}<img class="logo" src="{{ STATIC_URL }}/img/LogoPanik.jpg"/>{% endblock %}-->
</div>
<div id="Listen">
{% block listen %}{% include "includes/player.html" %}{% endblock %}
{% block listen %}{% player %}{% endblock %}
</div>
</div>
......
......@@ -11,7 +11,7 @@
preload="none"
class="hidden"
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"
></audio>
<ul class="inline metas small">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment