Commits

mitar committed 7818ddb

Added media necessary for preview of plugins.

  • Participants
  • Parent commits 914e3b8

Comments (0)

Files changed (2)

File cmsplugin_markup/cms_plugins.py

 
     def change_view(self, request, object_id, extra_context={}):
         extra_context.update({
-            'text_plugins': plugin_pool.get_text_enabled_plugins(self.placeholder, self.page),
+            'text_plugins': [p() for p in plugin_pool.get_text_enabled_plugins(self.placeholder, self.page)],
             'name': 'markupeditor',
             'used_plugins': pluginmodel.CMSPlugin.objects.filter(parent=object_id),
             'markup_plugins': [c() for c in utils.get_list_of_markup_classes().values()],
 
     def add_view(self, request, form_url='', extra_context={}):
         extra_context.update({
-            'text_plugins': plugin_pool.get_text_enabled_plugins(self.placeholder, self.page),
+            'text_plugins': [p() for p in plugin_pool.get_text_enabled_plugins(self.placeholder, self.page)],
             'name': 'markupeditor',
             'markup_plugins': [c() for c in utils.get_list_of_markup_classes().values()],
         })
         if request.method != 'POST':
             return http.HttpResponseNotAllowed(['POST'])
 
-        plugin = shortcuts.get_object_or_404(MarkupField, pk=request.POST.get('plugin_id'))
+        try:
+            plugin = MarkupField.objects.get(pk=request.POST.get('plugin_id'))
+        except MarkupField.DoesNotExist:
+            plugin = shortcuts.get_object_or_404(pluginmodel.CMSPlugin, pk=request.POST.get('plugin_id'))
+
         placeholder = plugin.placeholder
+
         if not placeholder.has_change_permission(request):
             raise http.Http404
         

File cmsplugin_markup/templates/cmsplugin_markup/markup_plugin_change_form.html

     add_plugin_for_markup(pluginvalue, parent_id, language, '{{ name|escapejs }}')
   }).css("cursor", "pointer").css("margin", "5px");
 
-  $('<input/>').attr({
-    'type': 'button',
-    'value': '{% trans "Refresh preview" %}',
-    'id': 'markup_preview_button_id'
-  }).css({
-    'margin': '0 0 0 5px'
-  }).click(function() {
-    forceAutoPreview = true;
-    $('#id_body').blur();
-  }).insertAfter('#markupfield_form :submit');
+  // Only if preview exists
+  $('#plugin-preview').each(function() {
+    $('<input/>').attr({
+      'type': 'button',
+      'value': '{% trans "Refresh preview" %}',
+      'id': 'markup_preview_button_id'
+    }).css({
+      'margin': '0 0 0 5px'
+    }).click(function() {
+      forceAutoPreview = true;
+      $('#id_body').blur();
+	}).insertAfter('#markupfield_form :submit');
+  });
 
 {% for p in used_plugins %}
   add_plugin_to_list('{{ p.pk|escapejs }}', '{{ p.get_instance_icon_src|escapejs }}', '{{ p.get_instance_icon_alt|escapejs }}');
 </script>
 <link rel="stylesheet" type="text/css" href="{{ STATIC_URL|default:MEDIA_URL }}cmsplugin_markup/markup.css" />
 <link rel="stylesheet" type="text/css" href="{{ CMS_MEDIA_URL }}css/jquery/cupertino/jquery-ui.css" />
+{% for p in text_plugins %}
+{{ p.pluginmedia }}
+{% endfor %}
 {% endblock %}