Ejemplo n.º 1
0
def url(parser, token):

    bits = token.split_contents()
    if len(bits) < 2:
        raise TemplateSyntaxError("'%s' takes at least one argument" " (path to a view)" % bits[0])
    viewname = bits[1]
    args = []
    kwargs = {}
    asvar = None
    bits = bits[2:]
    if len(bits) >= 2 and bits[-2] == "as":
        asvar = bits[-1]
        bits = bits[:-2]

    # Backwards compatibility: check for the old comma separated format
    # {% url urlname arg1,arg2 %}
    # Initial check - that the first space separated bit has a comma in it
    if bits and "," in bits[0]:
        check_old_format = True
        # In order to *really* be old format, there must be a comma
        # in *every* space separated bit, except the last.
        for bit in bits[1:-1]:
            if "," not in bit:
                # No comma in this bit. Either the comma we found
                # in bit 1 was a false positive (e.g., comma in a string),
                # or there is a syntax problem with missing commas
                check_old_format = False
                break
    else:
        # No comma found - must be new format.
        check_old_format = False

    if check_old_format:
        # Confirm that this is old format by trying to parse the first
        # argument. An exception will be raised if the comma is
        # unexpected (i.e. outside of a static string).
        match = kwarg_re.match(bits[0])
        if match:
            value = match.groups()[1]
            try:
                parser.compile_filter(value)
            except TemplateSyntaxError:
                bits = "".join(bits).split(",")

    # Now all the bits are parsed into new format,
    # process them as template vars

    if len(bits):
        for bit in bits:
            match = kwarg_re.match(bit)
            if not match:
                raise TemplateSyntaxError("Malformed arguments to url tag")
            name, value = match.groups()
            if name:
                kwargs[name] = parser.compile_filter(value)
            else:
                args.append(parser.compile_filter(value))

    viewname = ExpedientThemeManager.getThemeStaticUrl(viewname, args)
    return URLNode(viewname, args, kwargs, asvar)
Ejemplo n.º 2
0
'''
@author: jnaous
'''
from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings
from django.views.generic.simple import direct_to_template


''' Theme Management '''

from expedient.common.utils.ExpedientThemeManager import ExpedientThemeManager
ExpedientThemeManager.initialize()

""" Plugin system """
from expedient.common.utils.plugins.pluginloader import PluginLoader as PLUGIN_LOADER
from expedient.common.utils.plugins.topologygenerator import TopologyGenerator as TOPOLOGY_GENERATOR

if not PLUGIN_LOADER.plugin_settings:
    PLUGIN_SETTINGS = PLUGIN_LOADER.load_settings()
    # Iterate over loaded settings to add them to the locals() namespace
    for (plugin, plugin_settings) in PLUGIN_SETTINGS.iteritems():
        for (section, section_settings) in plugin_settings.iteritems():
            for (setting, setting_value) in section_settings.iteritems():
                if hasattr(settings, setting.upper()):
                    conf_setting = getattr(settings, setting.upper())
                else:
#                    setattr(settings, setting.upper(), list()) 
#                    conf_setting = getattr(settings, setting.upper())
                    conf_setting = list()
                try: