summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2015-05-21 07:40:51 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2015-05-22 11:38:01 (GMT)
commit7fcf6167aa7b0f46dc59f1c2cd0b994037795938 (patch)
tree2b4175857450ea92328f68ccd8724106aeaffda8
parentaabe5461ad3569d020a55f0df960297c44169582 (diff)
downloadcombo-7fcf6167aa7b0f46dc59f1c2cd0b994037795938.zip
combo-7fcf6167aa7b0f46dc59f1c2cd0b994037795938.tar.gz
combo-7fcf6167aa7b0f46dc59f1c2cd0b994037795938.tar.bz2
wcs: cache all form attributes (#7323)
-rw-r--r--combo/apps/wcs/migrations/0008_wcsformcell_cached_json.py21
-rw-r--r--combo/apps/wcs/models.py7
-rw-r--r--setup.py1
3 files changed, 29 insertions, 0 deletions
diff --git a/combo/apps/wcs/migrations/0008_wcsformcell_cached_json.py b/combo/apps/wcs/migrations/0008_wcsformcell_cached_json.py
new file mode 100644
index 0000000..d64a657
--- /dev/null
+++ b/combo/apps/wcs/migrations/0008_wcsformcell_cached_json.py
@@ -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,
+ ),
+ ]
diff --git a/combo/apps/wcs/models.py b/combo/apps/wcs/models.py
index 7e3e062..97983c0 100644
--- a/combo/apps/wcs/models.py
+++ b/combo/apps/wcs/models.py
@@ -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):
diff --git a/setup.py b/setup.py
index c409722..569aa76 100644
--- a/setup.py
+++ b/setup.py
@@ -97,6 +97,7 @@ setup(
'django-ckeditor',
'gadjo',
'django-cmsplugin-blurp',
+ 'django-jsonfield',
],
zip_safe=False,
cmdclass={