Пример #1
0
    def __init__(self,
                 name,
                 description="",
                 default=None,
                 multiple=1,
                 setable=1,
                 componentFields=None,
                 componentFieldDelimiter='_',
                 valueComposer=_defaultValueComposer):
        Field.__init__(self,
                       name=name,
                       description=description,
                       default=default,
                       multiple=multiple,
                       setable=setable)
        self.delimiter = componentFieldDelimiter
        if componentFields is None:
            componentFields = []

        tmpComponents = []
        for fld in componentFields:
            prxy = FieldProxy(self._getComponentName(fld), fld)
            tmpComponents.append(prxy)
        self._fields = FieldContainer(tmpComponents,
                                      fieldmapper=_getname,
                                      storelists=0)
        self.errors = FieldContainer(fieldmapper=_getfield, storelists=1)
        self.composeValue = valueComposer
Пример #2
0
    def __init__(self,
                 name,
                 description,
                 default=None,
                 multiple=1,
                 setable=1,
                 componentFields=None,
                 componentFieldDelimiter='_',
                 valueComposer=_defaultValueComposer,
                 layout=None):
        CompositeField.__init__(self,
                                name,
                                description,
                                default,
                                multiple,
                                setable,
                                componentFields,
                                componentFieldDelimiter,
                                valueComposer)

        # must override initialization of composite fields to ensure that ViewableFieldProxies 
        # are used
        tmpComponents = []
        for fld in componentFields:
            prxy = ViewableFieldProxy(self._getComponentName(fld), fld)
            tmpComponents.append(prxy)
        self._fields = FieldContainer(tmpComponents,
                                          fieldmapper=_getname,
                                          storelists=0)

        self.layout=layout or StackLayout()
Пример #3
0
 def __init__(self,
              name=None,
              method='POST',
              action="",
              enctype=None,
              fields=None,
              validators=None,
              processors=None):
     self.name = name
     self.method = method
     self.action = action
     self.enctype = enctype
     self._set_fields(fields)
     self.validators = validators or []
     self.processHook = Hook(processors or [])
     self.submitted = None
     self.errors = FieldContainer(fieldmapper=_getfield, storelists=1)
     self.state = None
Пример #4
0
 def __init__(self,
              name=None,
              method='POST',
              action="",
              enctype=None,
              fields=None,
              validators=None,
              processors=None):
     self.name=name
     self.method=method
     self.action=action
     self.enctype=enctype
     self._set_fields(fields)
     self.validators=validators or []
     self.processHook=Hook(processors or [])
     self.submitted=None
     self.errors=FieldContainer(fieldmapper=_getfield,
                                storelists=1)
     self.state=None
Пример #5
0
class Form(object):
    def __init__(self,
                 name=None,
                 method='POST',
                 action="",
                 enctype=None,
                 fields=None,
                 validators=None,
                 processors=None):
        self.name=name
        self.method=method
        self.action=action
        self.enctype=enctype
        self._set_fields(fields)
        self.validators=validators or []
        self.processHook=Hook(processors or [])
        self.submitted=None
        self.errors=FieldContainer(fieldmapper=_getfield,
                                   storelists=1)
        self.state=None

    
    def _get_fields(self):
        return self._fields

    def _set_fields(self, fields):
        self._fields=FieldContainer(fields or [],
                                    fieldmapper=_getname,
                                    storelists=0)

    fields=property(_get_fields, _set_fields)


    def getData(self, prune=1):
        d={}
        for k, v in self.fields.iteritems():
            if prune and k.startswith('_') or not v.setable:
                continue
            d[k]=v.value
        return d

    def setData(self, data):
        for f in self.fields:
            f._setData(data)

    def submit(self, data):
        self.reset()
        self.setData(data)
        self.submitted=1
        self.validate()

    def reset(self):
        for f in self.fields:
            f.clearValue()
        self.submitted=0
        self.errors[:]=[]
        self.state=None
        
    def validate(self):
        self.errors[:]=[]
        for l in ([f.validate for f in self.fields], self.validators):
            for func in l:
                e=func(self)
                if e:
                    self.errors.extend(e)

    def process(self,
                *args,
                **kwargs):
        return self.processHook(self, *args, **kwargs)
Пример #6
0
 def _set_fields(self, fields):
     self._fields = FieldContainer(fields or [],
                                   fieldmapper=_getname,
                                   storelists=0)
Пример #7
0
class Form(object):
    def __init__(self,
                 name=None,
                 method='POST',
                 action="",
                 enctype=None,
                 fields=None,
                 validators=None,
                 processors=None):
        self.name = name
        self.method = method
        self.action = action
        self.enctype = enctype
        self._set_fields(fields)
        self.validators = validators or []
        self.processHook = Hook(processors or [])
        self.submitted = None
        self.errors = FieldContainer(fieldmapper=_getfield, storelists=1)
        self.state = None

    def _get_fields(self):
        return self._fields

    def _set_fields(self, fields):
        self._fields = FieldContainer(fields or [],
                                      fieldmapper=_getname,
                                      storelists=0)

    fields = property(_get_fields, _set_fields)

    def getData(self, prune=1):
        d = {}
        for k, v in self.fields.iteritems():
            if prune and k.startswith('_') or not v.setable:
                continue
            d[k] = v.value
        return d

    def setData(self, data):
        for f in self.fields:
            f._setData(data)

    def submit(self, data):
        self.reset()
        self.setData(data)
        self.submitted = 1
        self.validate()

    def reset(self):
        for f in self.fields:
            f.clearValue()
        self.submitted = 0
        self.errors[:] = []
        self.state = None

    def validate(self):
        self.errors[:] = []
        for l in ([f.validate for f in self.fields], self.validators):
            for func in l:
                e = func(self)
                if e:
                    self.errors.extend(e)

    def process(self, *args, **kwargs):
        return self.processHook(self, *args, **kwargs)
Пример #8
0
 def __init__(self, forms):
     self.forms = FieldContainer(forms, fieldmapper=_getname, storelists=0)