mitar avatar mitar committed 914e3b8

Passing context and placholder to markup parse function.

Comments (0)

Files changed (7)

cmsplugin_markup/cms_plugins.py

 
 from django import http
 from django import shortcuts
+from django import template
 from django.contrib import admin
 
 from cms.models import pluginmodel
         context.update({
             'object': instance,
             'placeholder': placeholder,
-            })
+        })
         return context
 
     def save_model(self, request, obj, form, change):
             'name': 'markupeditor',
             'used_plugins': pluginmodel.CMSPlugin.objects.filter(parent=object_id),
             'markup_plugins': [c() for c in utils.get_list_of_markup_classes().values()],
-            })
+        })
         return super(MarkupPlugin, self).change_view(request, object_id, extra_context=extra_context)
 
     def add_view(self, request, form_url='', extra_context={}):
             'text_plugins': 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()],
-            })
+        })
         return super(MarkupPlugin, self).add_view(request, form_url, extra_context=extra_context);
 
     def get_plugin_urls(self):
     def preview(self, request):
         if request.method != 'POST':
             return http.HttpResponseNotAllowed(['POST'])
-        
-        if not shortcuts.get_object_or_404(pluginmodel.CMSPlugin, pk=request.POST.get('plugin_id')).placeholder.has_change_permission(request):
+
+        plugin = shortcuts.get_object_or_404(MarkupField, pk=request.POST.get('plugin_id'))
+        placeholder = plugin.placeholder
+        if not placeholder.has_change_permission(request):
             raise http.Http404
         
         if not request.POST.get('markup'):
             return http.HttpResponse('')
 
-        return http.HttpResponse(markup.markup_parser(request.POST.get('text'), request.POST.get('markup')))
+        return http.HttpResponse(markup.markup_parser(request.POST.get('text'), request.POST.get('markup'), template.RequestContext(request, {
+                'object': plugin,
+                'placeholder': placeholder,
+            }), placeholder))
 
 plugin_pool.register_plugin(MarkupPlugin)

cmsplugin_markup/models.py

             self.dynamic = False
         return super(MarkupField, self).save(*args, **kwargs)
 
-    def render(self):
+    def render(self, context):
         if self.dynamic:
-            return mark_safe(utils.markup_parser(self.body, self.markup))
+            return mark_safe(utils.markup_parser(self.body, self.markup, context, context.get('placeholder')))
         else:
             return mark_safe(self.body_html)
 

cmsplugin_markup/plugins/markdown/mark_down.py

     name = 'Markdown'
     identifier = 'markdown'
 
-    def parse(self, value):
+    def parse(self, value, context=None, placeholder=None):
         try:
             import markdown
         except ImportError:

cmsplugin_markup/plugins/restructuredtext/__init__.py

     name = 'ReST (ReStructured Text)'
     identifier = 'restructuredtext'
 
-    def parse(self, value):
+    def parse(self, value, context=None, placeholder=None):
         try:
             from docutils.core import publish_parts
         except ImportError:

cmsplugin_markup/plugins/textile/__init__.py

     name = 'Textile'
     identifier = 'textile'
 
-    def parse(self, value):
+    def parse(self, value, context=None, placeholder=None):
         try:
             import textile
         except ImportError:

cmsplugin_markup/templates/cmsplugin_markup/markup.html

-{{ object.render }}
+{% load markuptags %}{% rendermarkup %}

cmsplugin_markup/utils/markup.py

     markup_classes = get_list_of_markup_classes(settings.CMS_MARKUP_OPTIONS)
     return markup_classes[markup_id]()
 
-def markup_parser(value, parser_identifier):
+def markup_parser(value, parser_identifier, context=None, placeholder=None):
     """
     Takes a string and a parser identifier and returns a string parsed
     by that parser. If anything goes wrong it returns the original string
     """
 
-    return get_markup_object(parser_identifier).parse(value)
+    return get_markup_object(parser_identifier).parse(value, context, placeholder)
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.