Check out the IS_IN_SET documentation at
http://web2py.com/books/default/chapter/29/7. Instead of a list of
individual items, it can be a list of two-tuples or a dictionary, where the
first tuple item or dictionary key is the value and the second tuple item
or dictionary value is the label to be displayed in the select widget.
Anthony
On Monday, June 25, 2012 10:08:36 AM UTC-4, Daniel Gonzalez wrote:
>
> Hello,
>
> I am extending the registration data with some custom fields (pretty
> standard). This is my code:
>
> from gluon.tools import Service
> from gluon.tools import Auth
>
> db = DAL('sqlite://storage.sqlite')
> auth = Auth(db)
> service = Service()
>
> db.define_table(
> auth.settings.table_user_name,
> Field('first_name', length=128, default=''),
> Field('last_name', length=128, default=''),
> Field('email', length=128, default='', unique=True),
> Field('address', length=256, default=''),
> Field('postcode', length=128, default=''),
> Field('city', length=128, default=''),
> Field('country', length=128),
> Field('password', 'password', length=512, readable=False,
> label='Password'),
> Field('registration_key', length=512, writable=False,
> readable=False, default=''),
> Field('reset_password_key', length=512, writable=False,
> readable=False, default=''),
> Field('registration_id', length=512, writable=False,
> readable=False, default=''),
> format='%(first_name)s %(last_name)s')
>
> ISO_COUNTRY_CODES = ('DE', 'ES', 'IT', 'US')
>
> # get the custom_auth_table
> member = db[auth.settings.table_user_name]
> member.first_name.requires =
> IS_NOT_EMPTY(error_message=auth.messages.is_empty)
> member.last_name.requires =
> IS_NOT_EMPTY(error_message=auth.messages.is_empty)
> member.password.requires = [IS_STRONG(min=5, special=0, upper=0),
> CRYPT()]
> member.email.requires =
> [IS_EMAIL(error_message=auth.messages.invalid_email), IS_NOT_IN_DB(db,
> 'auth_user.email')]
> member.country.requires = IS_IN_SET(ISO_COUNTRY_CODES)
>
> auth.define_tables()
>
> The problem that I have is that in the registration form I am offered the
> choice among DE, ES, IT, US ...
> I would like to convert those ISO country codes (I need that in my
> database) to human readable contry names.
> Besides, this must be done according to the selected language (T operator?)
>
> Is it possible to tell the form serializer to map one of the fields?
> How can I specifiy the map function? Do you have an example to clarify the
> syntax?
>
> Thanks,
> Daniel
>
>
--