Ejemplo n.º 1
0
    def __init__(cls, *args, **kwargs):
        bases = []
        for class_ in cls.__mro__:
            if 'Meta' in class_.__dict__:
                bases.append(getattr(class_, 'Meta'))

        cls.Meta = type('Meta', tuple(bases), {})

        FormMeta.__init__(cls, *args, **kwargs)

        if hasattr(cls.Meta, 'model') and cls.Meta.model:
            generator = cls.Meta.form_generator(cls)
            generator.create_form(cls)
Ejemplo n.º 2
0
    def __init__(cls, *args, **kwargs):
        property_dict = {}
        for class_ in reversed(class_list(cls)):
            if hasattr(class_, 'Meta'):
                property_dict.update(class_.Meta.__dict__)

        cls.Meta = type('Meta', (object, ), property_dict)

        FormMeta.__init__(cls, *args, **kwargs)

        if hasattr(cls.Meta, 'model') and cls.Meta.model:
            generator = cls.Meta.form_generator(cls)
            generator.create_form(cls)
Ejemplo n.º 3
0
 def __init__(cls, *args, **kwargs):
     property_dict = {}
     for class_ in reversed(class_list(cls)):
         if hasattr(class_, "Meta"):
             property_dict.update(properties(class_.Meta))
     cls.Meta = type("Meta", (object,), property_dict)
     return FormMeta.__init__(cls, *args, **kwargs)
Ejemplo n.º 4
0
    def __init__(cls, *args, **kwargs):
        property_dict = {}
        for class_ in reversed(class_list(cls)):
            if hasattr(class_, 'Meta'):
                property_dict.update(properties(class_.Meta))

        cls.Meta = type('Meta', (object, ), property_dict)

        return FormMeta.__init__(cls, *args, **kwargs)
Ejemplo n.º 5
0
Archivo: forms.py Proyecto: zjjott/html
def form_factory(kwargs, base=MethodActionForm, name=b"DynamicForm"):
    """动态form生成函数,
    """
    fields = {}
    for kw in kwargs:
        _type = kw.type
        v = []
        if kw.required:
            v.append(validators.Required())
        else:
            v.append(validators.Optional())

        fields[kw.name] = SELECT_FIELD_MAP[_type](validators=v)
    form_class = FormMeta(name, (base, ), fields)
    return form_class
Ejemplo n.º 6
0
    def __new__(cls, name, bases, attrs):
        new_cls = FormMeta.__new__(cls, name, bases, attrs)
        opts = new_cls._meta = ModelFormOptions(getattr(new_cls, 'Meta', None))

        if opts.model:
            # find decleared fields
            decleared_fields = {}

            for k, v in attrs.items():
                if hasattr(v, '_formfield'):
                    decleared_fields[k] = v

            # TODO: find decleared fields in bases?
            new_cls.model_fields = fields_for_model(opts.model, opts.fields, opts.exclude)

            for name, f in dict(new_cls.model_fields, **decleared_fields).items():
                setattr(new_cls, name, f)

        return new_cls
Ejemplo n.º 7
0
    def __call__(cls, *args, **kwargs):
        if cls.Meta.model:
            generator = cls.Meta.form_generator(cls)
            generator.create_form(cls)

        return FormMeta.__call__(cls, *args, **kwargs)
Ejemplo n.º 8
0
    def __call__(cls, *args, **kwargs):
        if cls.Meta.model:
            generator = cls.Meta.form_generator(cls)
            generator.create_form(cls)

        return FormMeta.__call__(cls, *args, **kwargs)
Ejemplo n.º 9
0
 def __init__(cls, *args, **kwargs):
     cls.test_attr = 'SomeVal'
     FormMeta.__init__(cls, *args, **kwargs)