예제 #1
0
파일: prefs.py 프로젝트: palankai/xadrpy
from xadrpy.templates.libs import XWidgetBase, WidgetLibrary
from xadrpy.core.preferences.libs import prefs


register = WidgetLibrary()


class PropertyNode(XWidgetBase):

    def value(self, context, key=None, default=None, site=None, group=None, user=None, namespace=None, language_code=None, trans=None, order=""):
        order = [item.strip() for item in order.split(",") if item.strip()]
        v = prefs(key=key, default=default, site=site, group=group, user=user, namespace=namespace, language_code=language_code, trans=trans, order=order)
        if not self.asvar:
            v = v or ""
        return v 
            

register.widget('prefs')(PropertyNode)


예제 #2
0
from xadrpy.templates.libs import WidgetLibrary, XWidgetBase
from django.template.loader import render_to_string
register = WidgetLibrary()

class StylesNode(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/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)
예제 #3
0
from xadrpy.utils.jsonlib import JSONEncoder
from django.utils.safestring import mark_safe
from xadrpy.templates.libs import WidgetLibrary, XWidgetBase
from django.utils import importlib
from xadrpy.templates.libs import PLUGIN_CACHE

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)


class PluginNode(XWidgetBase):
    def value(self, context, name, placeholder, *args, **kwargs):
        if name in PLUGIN_CACHE: