Ejemplo n.º 1
0
 def __init__(self):
     # avoid 'no implementation for kind' error.
     import_string(settings.AUTH_USER_MODEL)
     if not 'kay.sessions.middleware.SessionMiddleware' in \
           settings.MIDDLEWARE_CLASSES:
         raise ImproperlyConfigured(
             "The DatastoreBackend requires session middleware to "
             "be installed. Edit your MIDDLEWARE_CLASSES setting to insert "
             "'kay.sessions.middleware.SessionMiddleware'.")
Ejemplo n.º 2
0
 def __init__(self):
     self.user_model = getattr(settings, 'GAEMA_USER_MODEL', GAEMAUser)
     if isinstance(self.user_model, basestring):
         try:
             self.user_model = import_string(self.user_model)
         except Exception:
             raise ImproperlyConfigured("Failed to import %s" %
                                        self.user_model)
     self.valid_services = get_valid_services()
Ejemplo n.º 3
0
def get_standard_processors():
  from kay.conf import settings
  processors = []
  for path in settings.CONTEXT_PROCESSORS:
    try:
      func = import_string(path)
    except (ImportError, AttributeError), e:
      raise ImproperlyConfigured('Error importing request processor module'
                                 ' %s: "%s"' % (path, e))
    processors.append(func)
Ejemplo n.º 4
0
    def __new__(cls, class_name, bases, attrs):
        """Constructor for a new ModelForm class instance.

    The signature of this method is determined by Python internals.

    """
        fields = sorted(((field_name, attrs.pop(field_name))
                         for field_name, obj in attrs.items()
                         if isinstance(obj, forms.Field)),
                        key=lambda obj: obj[1].creation_counter)
        for base in bases[::-1]:
            if hasattr(base, '_base_fields'):
                fields = base._base_fields.items() + fields
        declared_fields = datastructures.OrderedDict()
        for field_name, obj in fields:
            declared_fields[field_name] = obj
        opts = ModelFormOptions(attrs.get('Meta', None))
        attrs['_meta'] = opts

        base_models = []
        for base in bases:
            base_opts = getattr(base, '_meta', None)
            base_model = getattr(base_opts, 'model', None)
            if base_model is not None:
                base_models.append(base_model)
        if len(base_models) > 1:
            raise exceptions.ImproperlyConfigured(
                "%s's base classes define more than one model." % class_name)

        if opts.model is not None:
            if base_models and base_models[0] is not opts.model:
                raise exceptions.ImproperlyConfigured(
                    '%s defines a different model than its parent.' %
                    class_name)

            model_fields = datastructures.OrderedDict()
            for name, prop in sorted(
                    opts.model.properties().iteritems(),
                    key=lambda prop: prop[1].creation_counter):
                if opts.fields and name not in opts.fields:
                    continue
                if opts.exclude and name in opts.exclude:
                    continue
                form_field = prop.get_form_field(
                    help_text=opts.help_texts.get(name, None))
                if form_field is not None:
                    model_fields[name] = form_field

            for bad_attr_name in ModelFormMetaclass.bad_attr_names:
                if model_fields.has_key(bad_attr_name):
                    raise ImproperlyConfigured(
                        "When you use ModelForm, you can not"
                        " use these names as field names: %s" %
                        str(ModelFormMetaclass.bad_attr_names))

            # Preserve order in model definition
            original_ordered_names = model_fields.keys()
            model_fields.update(declared_fields)
            extra_index = len(original_ordered_names)
            for name, field in model_fields.iteritems():
                if name in original_ordered_names:
                    field._position_hint = original_ordered_names.index(name)
                else:
                    field._position_hint = extra_index
                    extra_index += 1

            attrs['_base_fields'] = model_fields

            props = opts.model.properties()
            for name, field in model_fields.iteritems():
                prop = props.get(name)
                if prop:

                    def check_for_property_field(form, value, prop=prop):
                        property_clean(prop, value)
                        return True

                    field.validators.append(check_for_property_field)
        else:
            attrs['_base_fields'] = declared_fields
        # corresponds with form not rendered
        # maybe i should handle this in forms.FormMeta
        return super(ModelFormMetaclass, cls).__new__(cls, class_name, bases,
                                                      attrs)