wcs: cache all form attributes (#7323)

This commit is contained in:
Frédéric Péters 2015-05-21 09:40:51 +02:00
parent aabe5461ad
commit 7fcf6167aa
3 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import jsonfield.fields
class Migration(migrations.Migration):
dependencies = [
('wcs', '0007_trackingcodeinputcell'),
]
operations = [
migrations.AddField(
model_name='wcsformcell',
name='cached_json',
field=jsonfield.fields.JSONField(default=dict, blank=True),
preserve_default=True,
),
]

View File

@ -23,6 +23,7 @@ from django.forms import Select
from django.utils.translation import ugettext_lazy as _
import cmsplugin_blurp.utils
from jsonfield import JSONField
from combo.data.models import CellBase
from combo.data.library import register_cell_class
@ -36,6 +37,7 @@ class WcsFormCell(CellBase):
cached_title = models.CharField(_('Title'), max_length=150)
cached_url = models.URLField(_('URL'))
cached_json = JSONField(blank=True)
is_enabled = classmethod(is_wcs_enabled)
@ -56,6 +58,7 @@ class WcsFormCell(CellBase):
if slug == form_slug:
self.cached_title = form.get('title')
self.cached_url = form.get('url')
self.cached_json = form
return super(WcsFormCell, self).save(*args, **kwargs)
def render(self, context):
@ -63,6 +66,10 @@ class WcsFormCell(CellBase):
context['slug'] = self.formdef_reference.split(':')[-1]
context['title'] = self.cached_title
context['url'] = self.cached_url
if self.cached_json:
for attribute in self.cached_json:
if not attribute in context:
context[attribute] = self.cached_json.get(attribute)
return formdef_template.render(context)
def get_additional_label(self):

View File

@ -97,6 +97,7 @@ setup(
'django-ckeditor',
'gadjo',
'django-cmsplugin-blurp',
'django-jsonfield',
],
zip_safe=False,
cmdclass={