mitar avatar mitar committed 2c45f0d

Made preview work also with django-cms 2.1.

Comments (0)

Files changed (5)

 directory somewhere on your Python path, or symlink to it from somewhere on
 your Python path; this is useful if your working from a Mercurial checkout.
 
+If you want preview functionality in admin to work you have to add something
+like:
+
+    (r'^admin/cms/plugin/markup/', include('cmsplugin_markup.urls')),
+
+to the very beginning of your ``urls.py``.
+
 Note that this application requires Python2.3 or later, and a functional
 installation of Django 1.` or newer as well as a functional install of 
 Django-CMS 2.` Final or newer. Each of the markup plugins also have their own 

cmsplugin_markup/cms_plugins.py

     def get_plugin_urls(self):
         from django.conf.urls.defaults import patterns, url
 
-        urls = super(MarkupPlugin, self).get_plugin_urls()
+        # If django-cms has get_plugin_urls feature or not
+        urls = getattr(super(MarkupPlugin, self), 'get_plugin_urls', lambda: [])()
         preview_urls = patterns('',
-            url(r'^preview/$', admin.site.admin_view(self.preview), name='markup_preview'),
+            url(r'^preview/$', admin.site.admin_view(self.preview), name='cmsplugin_markup_preview'),
         )
 
         return preview_urls + urls

cmsplugin_markup/static/cmsplugin_markup/markup.js

     var preview = $(this);
     $('#id_body').autoPreview(auto_preview_url, {
         'markup': $('#id_markup').val(),
-		'plugin_id': plugin_id
+        'plugin_id': plugin_id
       },
       function (textarea, text, data) {
         preview.html(data);

cmsplugin_markup/templates/cmsplugin_markup/markup_plugin_change_form.html

 <script type="text/javascript" src="{{ CMS_MEDIA_URL }}js/csrf.js"></script>
 <script type="text/javascript">
 /* <![CDATA[ */
-var plugin_id = '{{ object_id|escapejs }}';
-var auto_preview_timeout = 2.0;{% url admin:markup_preview as auto_preview_url %}
+var plugin_id = '{{ plugin.id|escapejs }}';
+var auto_preview_timeout = 2.0;{% url cmsplugin_markup_preview as auto_preview_url %}
 var auto_preview_url = '{{ auto_preview_url|escapejs }}';
 /* ]]> */
 </script>

cmsplugin_markup/urls.py

+from cmsplugin_markup.cms_plugins import MarkupPlugin
+
+urlpatterns = MarkupPlugin().get_plugin_urls()
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.