Beispiel #1
0
    def __init__(self, *args, **kwargs):
        Schema.__init__(self, *args, **kwargs)

        for v in self.fields.itervalues():
            for attr in ('if_empty', 'if_missing', 'if_invalid', 'min', 'max', 'value'):
                if hasattr(v, attr):
                    default = getattr(v, attr)
                    if default is not formencode.api.NoDefault and callable(default):
                        setattr(v, attr, default())
Beispiel #2
0
 def __init__(self, name):
     self.action = request.path_qs
     schema = Schema()
     schema.allow_extra_fields = True
     schema.filter_extra_fields = True
     self.schema = schema
     self.name = name
     self.errors = None
     self.fields = self.Fields()
     self.init()
Beispiel #3
0
 def __init__(self, name):
     self.action = request.path_qs
     schema = Schema()
     schema.allow_extra_fields = True
     schema.filter_extra_fields = True
     self.schema = schema
     self.name = name
     self.errors = None
     self.fields = self.Fields()
     self.init()
Beispiel #4
0
    def __init__(self, formdata, submit='form.submitted',
                 cancel='form.cancel'):
        Schema.__init__(self)
        self.defaults = {}
        for name, value in self.fields.items():
            default = getattr(value, 'default', None)
            if default is not None:
                self.defaults[name] = value.default
        self.formdata = formdata
        self.submit = submit
        self.cancel = cancel

        # Merge field defaults with any request.POST data passed in
        self.fieldvalues = deepcopy(self.defaults)
        for key, value in self.formdata.items():
            self.fieldvalues[key] = value
Beispiel #5
0
 class ProyectoRegistrationForm(AddRecordForm):
     form_validator =  Schema(chained_validators=(FieldsMatch('cod_proyecto',
                                                       'verify_password',
                                                       messages={'invalidNoMatch':
                                                       'cod_proyecto do not match'}),))
     __model__ = Proyecto
     __require_fields__     = ['cod_proyecto', 'nombre', 'cant_fases','user_id']
     __omit_fields__        = ['id_proyecto', 'estado', 'fecha_creacion', 'fecha_inicio', 'fecha_finalizacion_anulacion']
     __field_order__        = ['cod_proyecto', 'nombre', 'cant_fases','user_id']
     __base_validator__     = form_validator
     cod_proyecto           = TextField
     nombre                 = TextField
     cant_fases             = TextField
Beispiel #6
0
 class UserRegistrationForm(AddRecordForm):
     form_validator =  Schema(chained_validators=(FieldsMatch('password',
                                                      'verify_password',
                                                      messages={'invalidNoMatch':
                                                      'Passwords do not match'}),))
   
     __model__ = User
     __require_fields__     = ['password', 'user_name', 'email_address']
     __omit_fields__        = ['_password', 'groups', 'created', 'user_id', 'town_id']
     __field_order__        = ['user_name', 'email_address', 'display_name', 'password', 'verify_password']
     __base_validator__     = form_validator
     email_address          = TextField
     display_name           = TextField
     verify_password        = PasswordField('verify_password')
Beispiel #7
0
	def _to_python(self, value_dict, state):
		sl = syslanguage
		active_cultures = sl.active_record_cultures() if self.record_cultures else sl.active_cultures()

		culture_fields = set(x.replace('-', '_') for x in active_cultures)
		existing_fields = set(self.fields.keys())

		for field in existing_fields - culture_fields:
			if field not in culture_fields:
				del self.fields[field]

		for field in culture_fields - existing_fields:
			self.fields[field] = self.validator

		retval = Schema._to_python(self, value_dict, state)
		if self.delete_empty:
			retval = DeleteKeyIfEmpty().to_python(retval, state)
		return retval
Beispiel #8
0
    def _to_python(self, value_dict, state):
        sl = syslanguage
        active_cultures = (sl.active_record_cultures()
                           if self.record_cultures else sl.active_cultures())

        culture_fields = {x.replace("-", "_") for x in active_cultures}
        existing_fields = set(self.fields.keys())

        for field in existing_fields - culture_fields:
            if field not in culture_fields:
                del self.fields[field]

        for field in culture_fields - existing_fields:
            self.fields[field] = self.validator

        retval = Schema._to_python(self, value_dict, state)
        if self.delete_empty:
            retval = DeleteKeyIfEmpty().to_python(retval, state)
        return retval
Beispiel #9
0
	def __initargs__(self, new_attrs):
		del new_attrs['validator']
		Schema.__initargs__(self, new_attrs)
Beispiel #10
0
 def _to_python(self, value_dict, state):
     return Schema._to_python(self, value_dict, getattr(self, 'dao', state))
Beispiel #11
0
 def __init__(self, fields=None, **kwargs):
     Schema.__init__(self, **kwargs)
     if fields:
         for (name, validator) in fields:
             self.add_field(name, validator)
Beispiel #12
0
 def __initargs__(self, new_attrs):
     del new_attrs["validator"]
     Schema.__initargs__(self, new_attrs)