add Topik object, wrapper around Page
[django-panik-combo.git] / panikombo / views.py
index 9fc516d..a76ac84 100644 (file)
@@ -1,13 +1,16 @@
+from django.core.urlresolvers import reverse
 from django.db.models import Q
+from django.views.generic.edit import UpdateView
 import django_select2
 
-from emissions.models import SoundFile
+from emissions.models import SoundFile, Episode
+from .models import Topik
 
 class SoundFilesView(django_select2.views.Select2View):
     def get_results(self, request, terms, page, context):
         queryset = SoundFile.objects.all()
         for term in terms.split():
-            queryset = queryset.filter(Q(title__icontains=term) |
+            queryset = queryset.filter(podcastable=True).filter(Q(title__icontains=term) |
                     Q(episode__title__icontains=term) |
                     Q(episode__emission__title__icontains=term))
         def fmt(soundfile):
@@ -17,3 +20,29 @@ class SoundFilesView(django_select2.views.Select2View):
         return ('nil', False, ((x.id, fmt(x)) for x in queryset.select_related()))
 
 soundfiles = SoundFilesView.as_view()
+
+
+class EpisodesView(django_select2.views.Select2View):
+    def get_results(self, request, terms, page, context):
+        queryset = Episode.objects.all()
+        for term in terms.split():
+            queryset = queryset.filter(Q(title__icontains=term) |
+                    Q(emission__title__icontains=term))
+        def fmt(episode):
+            return '%s - %s' % (episode.emission.title, episode.title)
+        return ('nil', False, ((x.id, fmt(x)) for x in queryset.select_related()))
+
+episodes = EpisodesView.as_view()
+
+
+class TopikEdit(UpdateView):
+    model = Topik
+
+    def get_form_class(self):
+        from .forms import TopikEditForm
+        return TopikEditForm
+
+    def get_success_url(self):
+        return reverse('combo-manager-page-view', kwargs={'pk': self.object.page.id})
+
+topik_edit = TopikEdit.as_view()