Пример #1
0
                place, unused = model.objects.get_or_create(store=store, placeholder=placeholder)
                if not place.enabled:
                    return
                plugin.set_place(place)
        except PluginStore.DoesNotExist, e:
            logger.exception("Plugin not found in the store")
            raise
        except ImproperlyConfigured, e:
            logger.exception("Plugin class not found")
            raise
        except Exception, e:
            logger.exception(e)
            raise
        plugin.init_inline(template)
        request.xtensions.append(plugin)
        #plugin.init_template(template)
        context_len = len(context.dicts)
        try:
            plugin.init(context)
            if plugin.is_visible():
                return plugin.render(context)
            else:
                return ""
        except Exception, e:
            logger.exception("Plugin '%s' (placeholder=%s) render error: %s", name, placeholder, e)
            return "Plugin exception: %s" % e
        finally:
            while len(context.dicts)>context_len: context.pop()

register.widget('plugin')(PluginNode)
Пример #2
0
from xadrpy.utils.jsonlib import JSONEncoder
from django.utils.safestring import mark_safe
from xadrpy.core.templates.base import WidgetLibrary, XWidgetBase
from django.utils import importlib
register = WidgetLibrary()

@register.filter
def JSON(value):
    return mark_safe(JSONEncoder().encode(value))

class XWidgetNode(XWidgetBase):

    def value(self, context, name, *args, **kwargs):
        module_name, widget_name = name.rsplit(".",1)
        module = importlib.import_module(module_name)
        widget = getattr(module, widget_name)
        try:
            return widget(context, *args, **kwargs)
        except Exception, e:
            return "Exception: %s" % e

register.widget('xwidget')(XWidgetNode)

Пример #3
0
            styles.append({"href": style, "type": "text/css", "rel":"stylesheet" })

        skin_name = route and route.get_meta().get_skin_name() or None
        skin = skin_name and theme.get_skins()[skin_name] or theme.get_default_skin() or {'source':[]}
        for style_name in skin['source']:
            style = theme.style(style_name)
            for style_file in style['files']:
                styles.append({"href": style_file, "type": "text/css", "rel":"stylesheet" })
        
        ctx = { 'theme': theme, "styles": styles }
        return render_to_string("xadrpy/themes/styles.html", ctx, context)

class ScriptsNode(XWidgetBase):

    def value(self, context, *args, **kwargs):
        theme = getattr(context.get('request', object), "theme", None)
        TEMPLATE = kwargs.pop("TEMPLATE", None)
        if not theme and not TEMPLATE:
            return ""
        if not theme:
            return TEMPLATE.render(context)

        ctx = { 
            'theme': theme,
        }
        return render_to_string("xadrpy/themes/scripts.html", ctx, context)

register.widget('theme_styles')(StylesNode)
register.widget('theme_scripts')(ScriptsNode)