Commit 0b880f9f authored by fred's avatar fred
Browse files

performance: turn player into a templatetag

parent 8e600195
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()}
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')
......
{% 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>
......
...@@ -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">
......
Supports Markdown
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