Esempio n. 1
0
from xadrpy.core.templates.base import XWidgetBase, WidgetLibrary
from xadrpy.contrib.plugins.models import PluginStore, PluginPlace
from django.core.exceptions import ImproperlyConfigured
import logging

logger = logging.getLogger("xadrpy.contrib.plugins.templatetags.plugins")

register = WidgetLibrary()

class PluginNode(XWidgetBase):

    def value(self, context, name, *args, **kwargs):
        placeholder = kwargs.get('placeholder', None)
        template = kwargs.pop('TEMPLATE', None)
        request = context['request']
        try:
            store = PluginStore.objects.get_plugin(name)
            if not store.enabled:
                return
            plugin_cls = store.get_plugin_cls()
            plugin = store.get_instance(*args, **kwargs)
            if placeholder:
                model = plugin_cls.model or PluginPlace
                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:
Esempio n. 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)

Esempio n. 3
0
from xadrpy.core.templates.base import WidgetLibrary, XWidgetBase
from django.template.loader import render_to_string
register = WidgetLibrary()

class StylesNode(XWidgetBase):

    def value(self, context, *args, **kwargs):
        request = context.get('request')
        route = getattr(request, 'route', None)
        theme = getattr(request, "theme", None)
        TEMPLATE = kwargs.pop("TEMPLATE", None)
        if not theme and not TEMPLATE:
            return ""
        if not theme:
            return TEMPLATE.render(context)
        
        styles = []
        for library in theme.get_libraries():
            for style in library.get_styles():
                styles.append({"href": style, "type": "text/css", "rel":"stylesheet" })
        for style in theme.get_styles():
            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 }