Commit 6c9f3862 authored by Simon Daron's avatar Simon Daron
Browse files

Merge branch 'master' of ssh://git.domainepublic.net/panikweb

parents 6957ca1b 6895c302
import re
import urllib2
import uuid
from django import template
register = template.Library()
......@@ -5,3 +9,62 @@ register = template.Library()
@register.filter(name='zip')
def zip_lists(a, b):
return zip(a, b)
@register.inclusion_tag('episodes/resume.html', takes_context=True)
def episode_resume(context, date=None):
return {
'episode': context.get('episode'),
'date': date,
}
@register.inclusion_tag('episodes/inline.html', takes_context=True)
def episode_inline(context, date=None):
return {
'episode': context.get('episode'),
'date': date,
}
@register.inclusion_tag('emissions/detail.html', takes_context=True)
def emission_detail(context, date=None):
return {
'emission': context.get('emission'),
'schedules': context.get('schedules'),
}
@register.inclusion_tag('includes/player.html', takes_context=False)
def player():
return {'unique': uuid.uuid4()}
@register.inclusion_tag('includes/metaNav.html', takes_context=False)
def metanav():
return {}
@register.inclusion_tag('news/inline.html', takes_context=False)
def news_inline(content=None, klass=None, logo=None):
return {
'content': content,
'class': klass,
'logo': logo
}
@register.filter
def remove_tag_facet(url, facet):
facet = urllib2.quote(facet.encode('utf-8'), safe='')
return re.sub(r'&page=\d+', '', url.replace('&selected_facets=tags_exact:%s' % facet, ''))
@register.filter
def remove_category_facet(url, facet):
facet = urllib2.quote(facet.encode('utf-8'), safe='')
return re.sub(r'&page=\d+', '', url.replace('&selected_facets=categories_exact:%s' % facet, ''))
@register.filter
def append_tag_facet(url, facet):
facet = urllib2.quote(facet.encode('utf-8'), safe='')
return re.sub(r'&page=\d+', '', url + '&selected_facets=tags_exact:%s' % facet)
@register.filter
def append_category_facet(url, facet):
facet = urllib2.quote(facet.encode('utf-8'), safe='')
return re.sub(r'&page=\d+', '', url + '&selected_facets=categories_exact:%s' % facet)
......@@ -60,6 +60,8 @@ register.filter(thumbnail)
def clean_thumb(sender, instance, **kwargs):
if not hasattr(instance, 'image'):
return
if not instance.image:
return
name, ext = os.path.splitext(os.path.basename(instance.image.name))
exp = '^%s__\d+x\d+x[0-1]{1}\%s' % (name, ext)
for file_path in os.listdir(settings.MEDIA_ROOT):
......
from haystack.views import search_view_factory, FacetedSearchView
from haystack.forms import FacetedSearchForm
from haystack.query import SearchQuerySet
class SearchView(FacetedSearchView):
def extra_context(self):
context = super(SearchView, self).extra_context()
context['selected_categories'] = [
x.split(':', 1)[1] for x in self.request.GET.getlist('selected_facets')
if x.startswith('categories_exact')]
context['selected_tags'] = [
x.split(':', 1)[1] for x in self.request.GET.getlist('selected_facets')
if x.startswith('tags_exact')]
return context
sqs = SearchQuerySet().facet('categories').facet('tags')
view = search_view_factory(SearchView,
form_class=FacetedSearchForm,
searchqueryset=sqs)
......@@ -135,6 +135,7 @@ INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.admindocs',
'south',
'haystack',
'taggit',
'panikweb_templates',
'panikweb.paniktags',
......
......@@ -20,6 +20,8 @@ urlpatterns = patterns('',
url(r'^news/$', 'panikweb.views.news', name='news'),
url(r'^news/(?P<slug>[\w,-]+)$', 'panikweb.views.newsitem', name='news-view'),
url(r'^search/', 'panikweb.search.view', name='search'),
(r'^api/v2/', include('fiber.rest_api.urls')),
(r'^admin/fiber/', include('fiber.admin_urls')),
(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', {'packages': ('fiber',),}),
......
from datetime import datetime, timedelta
import math, uuid
import math
from django.views.generic.base import TemplateView
from django.views.generic.detail import DetailView
......@@ -17,7 +17,7 @@ class ProgramView(TemplateView):
def get_context_data(self, **kwargs):
context = super(ProgramView, self).get_context_data(**kwargs)
schedules = Schedule.objects.all().order_by('datetime')
schedules = Schedule.objects.select_related().order_by('datetime')
days = []
for day in range(7):
days.append({'schedules': [x for x in schedules if x.is_on_weekday(day+1)],
......@@ -64,7 +64,6 @@ class Grid(TemplateView):
def get_context_data(self, **kwargs):
context = super(Grid, self).get_context_data(**kwargs)
schedules = Schedule.objects.all().order_by('datetime')
nb_lines = 2 * 24 # the cells are half hours
grid = []
......@@ -103,7 +102,7 @@ class Grid(TemplateView):
time_cell.time_label = '%02d:00-%02d:00' % (
nonstop[0], nonstop[1])
for schedule in Schedule.objects.all():
for schedule in Schedule.objects.select_related().order_by('datetime'):
row_start = schedule.datetime.hour * 2 + \
int(math.ceil(schedule.datetime.minute / 30))
day_no = schedule.get_weekday()
......@@ -169,10 +168,10 @@ class Home(TemplateView):
def get_context_data(self, **kwargs):
context = super(Home, self).get_context_data(**kwargs)
context['newsImaged'] = NewsItem.objects.all().exclude(image__isnull=True).exclude(image__exact='').order_by('-datetime')[:3]
context['news'] = NewsItem.objects.all().order_by('-datetime')[:60]
context['emissions'] = Emission.objects.filter(archived=False).order_by('title')
context['player'] = audioPlayer()
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['emissions'] = list(Emission.objects.filter(archived=False).order_by('title'))
return context
home = Home.as_view()
......@@ -182,11 +181,9 @@ class News(TemplateView):
def get_context_data(self, **kwargs):
context = super(News, self).get_context_data(**kwargs)
context['newsImaged'] = NewsItem.objects.all().exclude(image__isnull=True).exclude(image__exact='').order_by('-datetime')[:3]
context['news'] = NewsItem.objects.all().order_by('-datetime')[:60]
context['categories'] = NewsCategory.objects.all()
context['emissions'] = Emission.objects.filter(archived=False).order_by('?')
context['player'] = audioPlayer()
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())
return context
news = News.as_view()
......@@ -217,15 +214,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')
......@@ -241,6 +233,12 @@ def onair(request):
'title': d['emission'].title,
'url': d['emission'].get_absolute_url()
}
if d.get('nonstop'):
d['nonstop'] = {
'title': d['nonstop'].title,
}
if d.get('current_slot'):
del d['current_slot']
return d
......
......@@ -490,4 +490,29 @@ body { font-size: 16px;}
#Panik {padding-top:1em}
#Panik *{color:black !important;border-bottom:2px solid black;}
#Listen.small-player ul.metas { display: none; }
#Listen.small-player div.content { padding: 5px 5%; }
ul.tag-facets {
font-size: 80%;
text-transform: lowercase;
font-family: "Reglo";
}
ul#search-results li {
margin: 0.5ex;
}
ul#search-results li.previous-page {
margin-bottom: 2ex;
text-align: left;
margin-left: 0ex;
font-style: italic;
}
ul#search-results li.next-page {
margin-top: 2ex;
text-align: right;
margin-right: 0;
font-style: italic;
}
{% 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>
......@@ -23,15 +23,15 @@
</head>
<body id="{% block bodyID %}{% endblock %}">
{% block meta %}<div id="metaNav">{% include "includes/metaNav.html" %}</div>{% endblock %}
{% block meta %}<div id="metaNav">{% metanav %}</div>{% endblock %}
<div id="Commons">
<div id="Panik" class="center">
<h1>Radio Panik 105.4 FM</h1>
<!--{% block logo %}<img class="logo" src="{{ STATIC_URL }}/img/LogoPanik.jpg"/>{% endblock %}-->
</div>
<div id="Listen">
{% block listen %}{% include "includes/player.html" %}{% endblock %}
<div id="Listen" class="{% block player-class %}{% endblock %}">
{% block listen %}{% player %}{% endblock %}
</div>
</div>
......
{% extends "base.html" %}
{% load paniktags %}
{% block bodyID %}Emissions{% endblock %}
{% block main %}
<div class="emission padded">
<div class="wrapper half">
<div id="Emission-tabs-detail">
{% include "emissions/detail.html" %}
{% emission_detail %}
</div>
<div id="Emission-tabs-episodes" class="episodes">
{% if episodes %}
......@@ -15,9 +16,9 @@
{% for episode in month.list %}
{% if episode.title == episodes.0.title %}
<li>{% include "episodes/resume.html" with date="daytime" %}</li>
<li>{% episode_resume date="daytime"%}</li>
{% else %}
<li>{% include "episodes/inline.html" with date="daytime" %}</li>
<li>{% episode_inline date="daytime" %}</li>
{% endif %}
{% endfor %}
</ul>
......
......@@ -16,8 +16,8 @@
{{ episode.first_diffusion|date:"H:i" }}
</span>
</div>
<!--
{% if episode.main_sound %}
<!--
<div class="controls right">
{% include "includes/audio.html" with file=episode.main_sound.file %}
</div>
......
{% extends "news.html" %}
{% block listen %}{% include "includes/player.html" %}{% endblock %}
{% block bodyID %}Home{% endblock %}
{% block nav %}{% endblock %}
{% block title %}{% endblock %}
......
......@@ -34,6 +34,11 @@
<span class="icon-info-sign" ></span>
<span class="iconLabel">About</span>
</a></li>
<li><form id="search" action="{% url 'search' %}">
<span class="icon-search" ></span>
<input name="q" type="search" class="iconLabel" placeholder="Rechercher..."></input>
</form></li>
</ul>
</div>
</nav>
......@@ -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">
......@@ -43,6 +43,9 @@
result = result + ($.type(onair.data.emission) == 'object'?'<strong>'+onair.data.emission.title+'</strong>&nbsp;':'');
result = result + ($.type(onair.data.episode) == 'object'?'<span>'+onair.data.episode.title+'</span>':'');
WhatsOnAir.html(result);
} else if (onair.data.nonstop) {
result = onair.data.nonstop.title;
WhatsOnAir.html('<strong>' + result + '</strong>');
}
else{WhatsOnAir.html('<strong>Unknown (Probably Non-Stop)</strong>');}
WhatsOnAir.fadeIn();
......
{% extends "base.html"%}
{% load paniktags %}
{% block bodyID %}News{% endblock %}
{% block title %}News{% endblock %}
{% block nav %}
......@@ -21,11 +22,11 @@
{% for NewsItem in newsImaged %}
<li class="item num-{{forloop.counter}}">
{% if NewsItem.slug == newsImaged.0.slug %}
{% include "news/inline.html" with content=NewsItem class="special" logo="large"%}
{% news_inline content=NewsItem klass="special" logo="large" %}
{% elif NewsItem.slug == newsImaged.1.slug or NewsItem.slug == newsImaged.2.slug%}
{% include "news/inline.html" with content=NewsItem class="special" logo="medium"%}
{% news_inline content=NewsItem klass="special" logo="medium"%}
{% else %}
{% include "news/inline.html" with content=NewsItem%}
{% news_inline with content=NewsItem%}
{% endif %}
</li>
{% endfor %}
......@@ -35,7 +36,11 @@
<div class="wrapper">
<ul class="news columns padded">
{% for NewsItem in news %}
<li class="item ellipsis small ">{% include "news/link.html" with content=NewsItem %}</li>
<li class="item ellipsis small ">
<a href="{% url 'news-view' slug=NewsItem.slug %}">
<span class="title"><strong>{{ NewsItem.datetime|date:"D m/M" }}</strong>&nbsp;-&nbsp;{{ NewsItem.title }}</span>
</a>
</li>
{% endfor %}
</ul>
</div>
......
<a href="{% url 'news-view' slug=content.slug %}">
<span class="title"><strong>{{ NewsItem.datetime|date:"D m/M" }}</strong>&nbsp;-&nbsp;{{ content.title }}</span>
</a>
{% extends 'panikdb/base.html' %}
{% load paniktags %}
{% block player-class %}small-player{% endblock %}
{% block nav %}
{% if query %}
<nav id="gridNav">
{% if facets.fields.categories %}
<ul>
{# Provide only the top 5 categories #}
{% for category in facets.fields.categories|slice:":5" %}
<li>
{% if category.0 in selected_categories %}
<strong><a href="{{ request.get_full_path|remove_category_facet:category.0 }}">{{ category.0 }}</a></strong> ({{ category.1 }})
{% else %}
<span><a href="{{ request.get_full_path|append_category_facet:category.0 }}">{{ category.0 }}</a> ({{ category.1 }})</span>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% if facets.fields.tags %}
<ul class="tag-facets">
{# Provide only the top 5 tags #}
{% for tag in facets.fields.tags|slice:":20" %}
<li>
{% if tag.0 in selected_tags %}
<strong><a href="{{ request.get_full_path|remove_tag_facet:tag.0 }}">{{ tag.0 }}</a></strong> ({{ tag.1 }})
{% else %}
<span><a href="{{ request.get_full_path|append_tag_facet:tag.0 }}">{{ tag.0 }}</a> ({{ tag.1 }})</span>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
</nav>
{% endif %}
{% endblock %}
{% block main %}
{% if not query %}
<h2>Recherche</h2>
<form method="get" action=".">
<table>
{{ form.as_table }}
<tr>
<td>&nbsp;</td>
<td>
<input type="submit" value="Rechercher">
</td>
</tr>
</table>
</form>
{% else %}
<ul id="search-results" class="list columns padded">
{% if page.has_previous %}
<li class="previous-page"><a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">&laquo; Résultats précédénts</a></li>
{% endif %}
{% for result in page.object_list %}
<li>
{% if result.model_name == "episode" %}
<a href="{% url 'episode-view' emission_slug=result.object.emission.slug slug=result.object.slug %}">
{{ result.object.emission.title }}
{{ result.object.title }}
</a>
{% elif result.model_name == "emission" %}
<a href="{% url 'emission-view' slug=result.object.slug %}">
{{ result.object.title }}
</a>
{% else %}
{{ result.object.title }}
{% endif %}
</li>
{% endfor %}
{% if page.has_next %}
<li class="next-page"><a href="?q={{ query }}&amp;page={{ page.next_page_number }}">Résultats suivants &raquo;</a></li>
{% endif %}
</ul>
{% endif %}
{% endblock %}
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