From 7fcf6167aa7b0f46dc59f1c2cd0b994037795938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 21 May 2015 09:40:51 +0200 Subject: [PATCH] wcs: cache all form attributes (#7323) --- .../0008_wcsformcell_cached_json.py | 21 +++++++++++++++++++ combo/apps/wcs/models.py | 7 +++++++ setup.py | 1 + 3 files changed, 29 insertions(+) create mode 100644 combo/apps/wcs/migrations/0008_wcsformcell_cached_json.py 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 00000000..d64a6571 --- /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 7e3e0628..97983c06 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 c4097223..569aa76a 100644 --- a/setup.py +++ b/setup.py @@ -97,6 +97,7 @@ setup( 'django-ckeditor', 'gadjo', 'django-cmsplugin-blurp', + 'django-jsonfield', ], zip_safe=False, cmdclass={