From 1071323ff0f4b59e13086b5cd5f172a51b73ed21 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 15 Oct 2017 10:47:10 +0200 Subject: [PATCH] update auto cells to generic render() method --- panikombo/models.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/panikombo/models.py b/panikombo/models.py index 350f77e..bdf0704 100644 --- a/panikombo/models.py +++ b/panikombo/models.py @@ -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 -- 2.39.2