33 lines
1007 B
Python
33 lines
1007 B
Python
import logging
|
|
|
|
from django.conf import settings
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from cms.plugin_pool import plugin_pool
|
|
from cms.plugin_base import CMSPluginBase
|
|
|
|
from . import models, utils
|
|
|
|
class BlurpPlugin(CMSPluginBase):
|
|
name = _('Blurp Plugin')
|
|
text_enabled = True
|
|
model = models.PluginRenderer
|
|
render_template = ''
|
|
|
|
def render(self, context, instance, placeholder):
|
|
logger = logging.getLogger(__name__)
|
|
try:
|
|
slug = instance.name
|
|
template, context = utils.render_blurp(context, slug)
|
|
self.render_template = template
|
|
return context
|
|
except Exception, e:
|
|
logger.exception('error while rendering blurp %s', slug)
|
|
if settings.TEMPLATE_DEBUG:
|
|
msg = 'error while rendering blurp %s: %s' % (slug, e)
|
|
self.render_template = 'cmsplugin_blurp/error.html'
|
|
return {'content': msg}
|
|
|
|
|
|
plugin_pool.register_plugin(BlurpPlugin)
|