]> git.0d.be Git - django-panik-combo.git/blobdiff - panikombo/models.py
update auto cells to generic render() method
[django-panik-combo.git] / panikombo / models.py
index 350f77e609fe11a3894a502929daede0bc985178..bdf07043fdbec68354ff01eeb5043f7f3476a98b 100644 (file)
@@ -99,6 +99,8 @@ class EpisodeAutoSelectionCell(CellBase):
                      (1, _('Future')),
                      (2, _('Past'))))
 
+    template_name = 'panikombo/episode_auto_selection.html'
+
 
     class Meta:
         verbose_name = _('Automatic Episode Selection')
@@ -139,17 +141,18 @@ class EpisodeAutoSelectionCell(CellBase):
 
         return episodes_queryset
 
-    def render(self, context):
-        tmpl = template.loader.get_template('panikombo/episode_auto_selection.html')
-        context['title'] = self.title
+    def get_cell_extra_context(self, context):
+        ctx = super(EpisodeAutoSelectionCell, self).get_cell_extra_context(context)
+        ctx['title'] = self.title
 
         if (self.category or self.period or self.tags.count()):
             episodes_queryset = self.get_included_items()
             episodes_queryset = episodes_queryset.order_by('-first_diffusion').distinct()
-            context['episodes'] = episodes_queryset
+            ctx['episodes'] = episodes_queryset
         else:
-            context['episodes'] = []
-        return tmpl.render(context)
+            ctx['episodes'] = []
+
+        return ctx
 
     def get_default_form_class(self):
         from .forms import EpisodeAutoSelectionCellForm
@@ -169,6 +172,8 @@ class NewsItemAutoSelectionCell(CellBase):
     category = models.ForeignKey('emissions.NewsCategory',
             verbose_name=_('Category'), null=True, blank=True)
 
+    template_name = 'panikombo/newsitem_auto_selection.html'
+
     class Meta:
         verbose_name = _('Automatic Newsitem Selection')
 
@@ -186,14 +191,16 @@ class NewsItemAutoSelectionCell(CellBase):
         newsitems_queryset = newsitems_queryset.order_by('-event_date', '-creation_timestamp')
         return newsitems_queryset
 
-    def render(self, context):
-        tmpl = template.loader.get_template('panikombo/newsitem_auto_selection.html')
-        context['title'] = self.title
+    def get_cell_extra_context(self, context):
+        ctx = super(NewsItemAutoSelectionCell, self).get_cell_extra_context(context)
+        ctx['title'] = self.title
+
         if self.tags.count() or self.future or self.category:
-            context['newsitems'] = self.get_included_items()
+            ctx['newsitems'] = self.get_included_items()
         else:
-            context['newsitems'] = []
-        return tmpl.render(context)
+            ctx['newsitems'] = []
+
+        return ctx
 
     def get_default_form_class(self):
         from .forms import NewsItemAutoSelectionCellForm