wcs: let category/form link cells be rendered with alternate templates (#18917)

This commit is contained in:
Frédéric Péters 2017-09-24 10:02:36 +02:00
parent ec6fb3d109
commit d15de4513a
1 changed files with 10 additions and 7 deletions

View File

@ -33,6 +33,8 @@ from .utils import get_wcs_json, is_wcs_enabled, get_wcs_services
@register_cell_class
class WcsFormCell(CellBase):
template_name = 'combo/wcs/form.html'
formdef_reference = models.CharField(_('Form'), max_length=150)
cached_title = models.CharField(_('Title'), max_length=150)
@ -64,8 +66,8 @@ class WcsFormCell(CellBase):
self.cached_json = form
return super(WcsFormCell, self).save(*args, **kwargs)
def render(self, context):
formdef_template = template.loader.get_template('combo/wcs/form.html')
def get_cell_extra_context(self, context):
context = super(WcsFormCell, self).get_cell_extra_context(context)
context['slug'] = self.formdef_reference.split(':')[-1]
context['title'] = self.cached_title
context['url'] = self.cached_url
@ -73,7 +75,7 @@ class WcsFormCell(CellBase):
for attribute in self.cached_json:
if not attribute in context:
context[attribute] = self.cached_json.get(attribute)
return formdef_template.render(context)
return context
def get_additional_label(self):
if not self.cached_title:
@ -113,6 +115,7 @@ class WcsCommonCategoryCell(CellBase):
@register_cell_class
class WcsCategoryCell(WcsCommonCategoryCell):
template_name = 'combo/wcs/category.html'
class Meta:
verbose_name = _('Category Link')
@ -121,15 +124,15 @@ class WcsCategoryCell(WcsCommonCategoryCell):
from .forms import WcsCategoryCellForm
return WcsCategoryCellForm
def render(self, context):
def get_cell_extra_context(self, context):
context = super(WcsCategoryCell, self).get_cell_extra_context(context)
if not self.category_reference:
return ''
category_template = template.loader.get_template('combo/wcs/category.html')
return context
context['slug'] = self.category_reference.split(':')[-1]
context['title'] = self.cached_title
context['description'] = self.cached_description
context['url'] = self.cached_url
return category_template.render(context)
return context
class WcsBlurpMixin(object):