Commit 6287dfa4 authored by fred's avatar fred

add support for Topik objects

parent e97101bb
...@@ -3,6 +3,7 @@ from django.conf import settings ...@@ -3,6 +3,7 @@ from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from emissions.models import Emission, Episode, NewsItem, SoundFile, Focus from emissions.models import Emission, Episode, NewsItem, SoundFile, Focus
from panikombo.models import Topik
from combo.data.models import Page from combo.data.models import Page
register = Library() register = Library()
...@@ -54,6 +55,8 @@ def has_focus(object): ...@@ -54,6 +55,8 @@ def has_focus(object):
object_type = 'episode' object_type = 'episode'
elif isinstance(object, SoundFile): elif isinstance(object, SoundFile):
object_type = 'soundfile' object_type = 'soundfile'
elif isinstance(object, Page):
object_type = 'page'
else: else:
return False return False
try: try:
...@@ -73,6 +76,8 @@ def unset_focus_url(object): ...@@ -73,6 +76,8 @@ def unset_focus_url(object):
object_type = 'episode' object_type = 'episode'
elif isinstance(object, SoundFile): elif isinstance(object, SoundFile):
object_type = 'soundfile' object_type = 'soundfile'
elif isinstance(object, Page):
object_type = 'page'
return reverse('focus-unset', kwargs={ return reverse('focus-unset', kwargs={
'object_type': object_type, 'object_type': object_type,
'object_id': object.id}) 'object_id': object.id})
...@@ -88,6 +93,8 @@ def set_focus_url(object): ...@@ -88,6 +93,8 @@ def set_focus_url(object):
object_type = 'episode' object_type = 'episode'
elif isinstance(object, SoundFile): elif isinstance(object, SoundFile):
object_type = 'soundfile' object_type = 'soundfile'
elif isinstance(object, Page):
object_type = 'page'
return reverse('focus-set', kwargs={ return reverse('focus-set', kwargs={
'object_type': object_type, 'object_type': object_type,
'object_id': object.id}) 'object_id': object.id})
...@@ -102,6 +109,12 @@ def can_focus(object): ...@@ -102,6 +109,12 @@ def can_focus(object):
return True return True
elif isinstance(object, SoundFile): elif isinstance(object, SoundFile):
return bool(object.format) return bool(object.format)
elif isinstance(object, Page):
try:
topik = Topik.objects.get(page=object)
except Topik.DoesNotExist:
return False
return bool(topik.image)
return False return False
...@@ -110,3 +123,16 @@ def as_duration(value): ...@@ -110,3 +123,16 @@ def as_duration(value):
if not value: if not value:
return '-' return '-'
return '%s:%02d' % (value/60, value%60) return '%s:%02d' % (value/60, value%60)
@register.filter
def is_page(obj):
return isinstance(obj, Page)
@register.filter
def has_topik(obj):
return Topik.objects.filter(page=obj).count() == 1
@register.filter
def topik_id(obj):
return Topik.objects.get(page=obj).id
{% extends "base.html" %} {% extends "base.html" %}
{% load static %} {% load static panikdbtags %}
{% block extrascripts %} {% block extrascripts %}
<script src="{% static "ckeditor/ckeditor/ckeditor.js" %}"></script> <script src="{% static "ckeditor/ckeditor/ckeditor.js" %}"></script>
...@@ -11,6 +11,15 @@ ...@@ -11,6 +11,15 @@
{% block more-user-links %} {% block more-user-links %}
<a href="{% url 'combo-manager-homepage' %}">Pages</a> <a href="{% url 'combo-manager-homepage' %}">Pages</a>
{% if object|is_page %}
{% if object|has_topik %}
{% with object|topik_id as topik_id %}
<a rel="popup" href="{% url 'edit-topik' pk=topik_id %}">Options de Topik</a>
{% endwith %}
{% else %}
<a href="{% url 'make-topik' page_pk=object.id %}">Transformer en Topik</a>
{% endif %}
{% endif %}
{% endblock %} {% endblock %}
{% block bodyattr %}class="combo"{% endblock %} {% block bodyattr %}class="combo"{% endblock %}
...@@ -55,10 +55,16 @@ urlpatterns = patterns('', ...@@ -55,10 +55,16 @@ urlpatterns = patterns('',
url(r'^focus/unset/(?P<object_type>[\w,-]+)/(?P<object_id>\d+)$', url(r'^focus/unset/(?P<object_type>[\w,-]+)/(?P<object_id>\d+)$',
'panikdb.views.focus_unset', name='focus-unset'), 'panikdb.views.focus_unset', name='focus-unset'),
url(r'^cms/pages/(?P<page_pk>\w+)/make-topik$', 'panikdb.views.make_topik',
name='make-topik'),
url(r'^cms/pages/topik/(?P<pk>\w+)/edit-topik$', 'panikombo.views.topik_edit',
name='edit-topik'),
url(r'^accounts/logout/', 'django.contrib.auth.views.logout_then_login', name='logout'), url(r'^accounts/logout/', 'django.contrib.auth.views.logout_then_login', name='logout'),
url(r'^accounts/', include('registration.backends.default.urls')), url(r'^accounts/', include('registration.backends.default.urls')),
url(r'^combok/soundfiles/', 'panikombo.views.soundfiles'), url(r'^combok/soundfiles/', 'panikombo.views.soundfiles'),
url(r'^combok/episodes/', 'panikombo.views.episodes'),
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
) )
......
...@@ -7,9 +7,12 @@ from django.template import loader, Context ...@@ -7,9 +7,12 @@ from django.template import loader, Context
from django.views.generic.base import TemplateView, RedirectView from django.views.generic.base import TemplateView, RedirectView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.contrib import messages from django.contrib import messages
from django.shortcuts import redirect
from emissions.models import * from emissions.models import *
from emissions.utils import period_program from emissions.utils import period_program
from panikombo.models import Topik
from combo.data.models import Page
import emissions.views import emissions.views
import newsletter.views import newsletter.views
...@@ -147,6 +150,16 @@ class FocusSetView(RedirectView): ...@@ -147,6 +150,16 @@ class FocusSetView(RedirectView):
'slug': soundfile.episode.slug, 'slug': soundfile.episode.slug,
'emission_slug': soundfile.episode.emission.slug, 'emission_slug': soundfile.episode.emission.slug,
}) })
if object_type == 'page':
page = Page.objects.get(id=object_id)
try:
f = Focus.objects.get(page=page)
except Focus.DoesNotExist:
f = Focus()
f.current = True
f.page = page
f.save()
return reverse('combo-manager-page-view', kwargs={'pk': object_id})
focus_set = FocusSetView.as_view() focus_set = FocusSetView.as_view()
...@@ -186,5 +199,17 @@ class FocusUnsetView(RedirectView): ...@@ -186,5 +199,17 @@ class FocusUnsetView(RedirectView):
'slug': soundfile.episode.slug, 'slug': soundfile.episode.slug,
'emission_slug': soundfile.episode.emission.slug, 'emission_slug': soundfile.episode.emission.slug,
}) })
if object_type == 'page':
focus = Focus.objects.get(page=object_id)
focus.current = False
focus.save()
return reverse('combo-manager-page-view', kwargs={'pk': object_id})
focus_unset = FocusUnsetView.as_view() focus_unset = FocusUnsetView.as_view()
def make_topik(request, page_pk):
if Topik.objects.filter(page__id=page_pk).count():
raise Exception('page already associated to topik')
topik = Topik(page_id=page_pk)
topik.save()
return redirect('combo-manager-page-view', pk=page_pk)
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