Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for plugins to register URL patterns for views.

  • Loading branch information...
commit 802cccf41fa3143d63a32450c7cb0906b382a78f 1 parent 28ab432
@mitar authored
Showing with 35 additions and 0 deletions.
  1. +3 −0  cms/admin/pageadmin.py
  2. +11 −0 cms/plugin_base.py
  3. +21 −0 cms/plugin_pool.py
View
3  cms/admin/pageadmin.py
@@ -201,6 +201,9 @@ def get_urls(self):
pat(r'^(?P<object_id>\d+)/change_template/$', self.change_template), # copy dialog
)
+ if plugin_pool.get_all_plugins():
+ url_patterns += plugin_pool.get_patterns()
+
url_patterns = url_patterns + super(PageAdmin, self).get_urls()
return url_patterns
View
11 cms/plugin_base.py
@@ -211,6 +211,17 @@ def icon_alt(self, instance):
the plugin object in a text editor.
"""
return "%s - %s" % (unicode(self.name), unicode(instance))
+
+ def get_plugin_urls(self):
+ """
+ Return URL patterns for which the plugin wants to register
+ views for.
+ """
+ return []
+
+ def plugin_urls(self):
+ return self.get_plugin_urls()
+ plugin_urls = property(plugin_urls)
def __repr__(self):
return smart_str(self.name)
View
21 cms/plugin_pool.py
@@ -3,7 +3,11 @@
from cms.plugin_base import CMSPluginBase
from cms.utils.helpers import reversion_register
from django.conf import settings
+from django.conf.urls.defaults import url, patterns, include
+from django.template.defaultfilters import slugify
+from django.utils.encoding import force_unicode
from django.utils.importlib import import_module
+from django.utils.translation import get_language, deactivate_all, activate
class PluginPool(object):
def __init__(self):
@@ -95,7 +99,24 @@ def get_plugin(self, name):
"""
self.discover_plugins()
return self.plugins[name]
+
+ def get_patterns(self):
+ # We want untranslated name of the plugin for its slug so we deactivate translation
+ lang = get_language()
+ deactivate_all()
+ url_patterns = []
+ for plugin in self.get_all_plugins():
+ p = plugin()
+ slug = slugify(force_unicode(p.name))
+ url_patterns += patterns('',
+ url(r'^plugin/%s/' % (slug,), include(p.plugin_urls)),
+ )
+
+ # Reactivate translation
+ activate(lang)
+
+ return url_patterns
plugin_pool = PluginPool()
Please sign in to comment.
Something went wrong with that request. Please try again.