Commits

mitar committed 3b604f4

Added support for dynamic content.

Comments (0)

Files changed (5)

cmsplugin_markup/models.py

 from django.db import models
 from django.utils.translation import ugettext as _
+from django.utils.safestring import mark_safe
 from django.utils.html import strip_tags
 from django.utils.text import truncate_words
 from django.conf import settings
             choices=MARKUP_CHOICES,
             default=MARKUP_CHOICES[0][0] if len(MARKUP_CHOICES) == 1 else models.NOT_PROVIDED,
             )
+    dynamic = models.BooleanField(_('Render every time'), default=False, help_text=_('Should be the content rendered every time the page is displayed or should it be rendered only when saved?'))
 
     search_fields = ('body_html',)
 
         return u'%s' %(truncate_words(strip_tags(self.body_html), 3)[:30]+'...')
 
     def save(self, *args, **kwargs):
+        # We store it in any case to also check the parser for possible exceptions and to use it for __unicode__
         self.body_html = utils.markup_parser(self.body, self.markup)
+        if not utils.get_markup_object(self.markup).is_dynamic:
+            self.dynamic = False
         return super(MarkupField, self).save(*args, **kwargs)
 
+    def render(self):
+        if self.dynamic:
+            return mark_safe(utils.markup_parser(self.body, self.markup))
+        else:
+            return mark_safe(self.body_html)
+
     def clean_plugins(self):
         ids = utils.plugin_id_list(self.body, self.markup)
         plugins = CMSPlugin.objects.filter(parent=self)

cmsplugin_markup/plugins/base.py

 class MarkupBase(object):
     text_enabled_plugins = False
+    is_dynamic = False
 
     def plugin_id_list(self, text):
         """

cmsplugin_markup/static/cmsplugin_markup/markup.js

   return markupPlugins[$('#id_markup').val()]['markup'](plugin_id, icon_src, icon_alt);
 }
 
-function showhideplugins() {
+function markupchange() {
   (function ($) {
     var plugin = markupPlugins[$('#id_markup').val()];
     if ((typeof(plugin) !== "undefined") && plugin['textenabled']) {
     else {
       $('.iftextplugins').hide();
     }
+    if ((typeof(plugin) !== "undefined") && plugin['isdynamic']) {
+      $('#id_dynamic').closest('.form-row').show();
+    }
+    else {
+      $('#id_dynamic').closest('.form-row').hide();
+    }
   })(jQuery);
 }
 
   $('#id_markup').change(function() {
     forceAutoPreview = true;
     $('#id_body').blur();
-    showhideplugins();
+    markupchange();
   });
-  showhideplugins();
+  markupchange();
 });

cmsplugin_markup/templates/cmsplugin_markup/markup.html

-{{ object.body_html|safe }}
+{{ object.render }}

cmsplugin_markup/templates/cmsplugin_markup/markup_plugin_change_form.html

 {% for p in markup_plugins %}
 markupPlugins['{{ p.identifier|escapejs }}'] = {
   'textenabled': {{ p.text_enabled_plugins|yesno:"true,false" }},
+  'isdynamic': {{ p.is_dynamic|yesno:"true,false" }},
   'markup': {{ p.plugin_markup|default:"null" }},
   'regex': {{ p.plugin_regexp|default:"null" }}
 };
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.