From: Frédéric Péters Date: Sun, 15 Oct 2017 08:47:10 +0000 (+0200) Subject: update auto cells to generic render() method X-Git-Tag: v2021~43 X-Git-Url: https://git.0d.be/?p=django-panik-combo.git;a=commitdiff_plain;h=1071323ff0f4b59e13086b5cd5f172a51b73ed21 update auto cells to generic render() method --- 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