Exemplo n.º 1
0
    def fields(self):
        # Since @property is readonly we can't modify field values in display() method
        # Returns fields modified by display()
        if self._fields:
            return self._fields

        list_of_fields = [
            ew.SingleSelectField(
                name='sex',
                label='Gender',
                options=[
                    ew.Option(py_value=v, label=v, selected=False)
                    for v in ['Male', 'Female', 'Unknown', 'Other']
                ],
                validator=formencode.All(
                    V.OneOfValidator(['Male', 'Female', 'Unknown', 'Other']),
                    fev.UnicodeString(not_empty=True))),
            ew.SingleSelectField(
                name='country',
                label='Country of residence',
                validator=V.MapValidator(country_names, not_empty=False),
                options=[
                    ew.Option(
                        py_value=" ", label=" -- Unknown -- ", selected=False)
                ] + [
                    ew.Option(py_value=c, label=n, selected=False)
                    for c, n in sorted(country_names.items(),
                                       key=lambda (k, v): v)
                ],
                attrs={'onchange': 'selectTimezone(this.value)'}),
            ew.TextField(name='city',
                         label='City of residence',
                         attrs=dict(value=None),
                         validator=fev.UnicodeString(not_empty=False)),
            ew.SingleSelectField(
                name='timezone',
                label='Timezone',
                attrs={'id': 'tz'},
                validator=V.OneOfValidator(common_timezones, not_empty=False),
                options=[ew.Option(py_value=" ", label=" -- Unknown -- ")] + [
                    ew.Option(py_value=n, label=n)
                    for n in sorted(common_timezones)
                ])
        ]
        if asbool(tg.config.get('auth.allow_birth_date', True)):
            list_of_fields[1:1] = self.birth_date_fields

        return list_of_fields
Exemplo n.º 2
0
 class fields(ew_core.NameList):
     sex = ew.SingleSelectField(
         label='Gender',
         options=[
             ew.Option(py_value=v, label=v, selected=False)
             for v in ['Male', 'Female', 'Unknown', 'Other']
         ],
         validator=formencode.All(
             V.OneOfValidator(['Male', 'Female', 'Unknown', 'Other']),
             fev.UnicodeString(not_empty=True)))
     birthdate = ew.TextField(label='Birth date',
                              validator=V.DateValidator(),
                              attrs=dict(value=None))
     exp = _HTMLExplanation(text="Use the format DD/MM/YYYY",
                            show_errors=False)
     country = ew.SingleSelectField(
         label='Country of residence',
         validator=V.MapValidator(country_names, not_empty=False),
         options = [
             ew.Option(
                 py_value=" ", label=" -- Unknown -- ", selected=False)] +\
             [ew.Option(py_value=c, label=n, selected=False)
              for c,n in sorted(country_names.items(),
                                key=lambda (k,v):v)],
         attrs={'onchange':'selectTimezone(this.value)'})
     city = ew.TextField(label='City of residence',
                         attrs=dict(value=None),
                         validator=fev.UnicodeString(not_empty=False))
     timezone=ew.SingleSelectField(
         label='Timezone',
         attrs={'id':'tz'},
         validator=V.OneOfValidator(common_timezones, not_empty=False),
         options=[
              ew.Option(
                  py_value=" ",
                  label=" -- Unknown -- ")] + \
              [ew.Option(py_value=n, label=n)
               for n in sorted(common_timezones)])