Exemplo n.º 1
0
 def __new__(cls, name, bases, attrs):
     # Returns the generated Configurator subclass.
     attrs['_config_name'] = name
     config_fields = {}
     for key,object in attrs.items():
         if isinstance(object, forms.Field):
             config_fields[key] = object
             del attrs[key]
     attrs['_config_fields'] = config_fields
     config_cls = type(name + "Form", (forms.Form,), config_fields.copy())
     attrs['_config_cls'] = config_cls
     new_class = super(ConfiguratorDeclarativeParser,cls).__new__(cls, name, bases, attrs)
     # For each field, set the default value if it hasn't already been set.
     initial = config_cls({})
     for key,field in initial.fields.items():
         full_key = 'CFG__' + name + '__' + key
         if not full_key in conf:
             try:
                 conf[full_key] = field.clean(field.default)
                 logger.log_debug("set initial value for %s.%s to '%s'" % (name, key, field.default))
             except forms.ValidationError:
                 e = ConfiguratorException("'%s' is not a valid value for %s.%s" % (field.default, name, key))
                 logger.log_warning("failed to set initial value: %s" % e)
                 raise e
     return new_class
Exemplo n.º 2
0
def load_template_source(path, template_dirs=None):
    """
    Loads templates for django from Python eggs via pkg_resource.resource_string.
    """
    if resource_string is not None:
        try:
            pkg_name,template_path = path.split(':', 1)
        except:
            pkg_name = 'higgins.data'
            template_path = path
        try:
            charset = conf.get('FILE_CHARSET', 'ISO-8859-1')
            return (resource_string(pkg_name, template_path).decode(charset), '%s:%s' % (pkg_name,template_path))
        except Exception, e:
            logger.log_warning("failed to load template %s: %s" % (path,e))