示例#1
0
 def __init__(self, *args, **kwargs):
     self.event = kwargs['obj']
     super().__init__(*args, **kwargs)
     self.fields['confirm_text'].widget.attrs['rows'] = '3'
     self.fields['confirm_text'].widget.attrs['placeholder'] = _(
         'e.g. I hereby confirm that I have read and agree with the event organizer\'s terms of service '
         'and agree with them.'
     )
     self.fields['name_scheme'].choices = (
         (k, _('Ask for {fields}, display like {example}').format(
             fields=' + '.join(str(vv[1]) for vv in v['fields']),
             example=v['concatenation'](v['sample'])
         ))
         for k, v in PERSON_NAME_SCHEMES.items()
     )
     self.fields['name_scheme_titles'].choices = [('', _('Free text input'))] + [
         (k, '{scheme}: {samples}'.format(
             scheme=v[0],
             samples=', '.join(v[1])
         ))
         for k, v in PERSON_NAME_TITLE_GROUPS.items()
     ]
     if not self.event.has_subevents:
         del self.fields['frontpage_subevent_ordering']
         del self.fields['event_list_type']
     self.fields['primary_font'].choices += [
         (a, {"title": a, "data": v}) for a, v in get_fonts().items()
     ]
示例#2
0
    def __init__(self, *args, **kwargs):
        fields = []
        defaults = {
            'widget': self.widget,
            'max_length': kwargs.pop('max_length', None),
            'validators': [
                RegexValidator(
                    # The following characters should never appear in a name anywhere of
                    # the world. However, they commonly appear in inputs generated by spam
                    # bots.
                    r'^[^$€/%§{}<>~]*$',
                    message=_('Please do not use special characters in names.')
                )
            ]
        }
        self.scheme_name = kwargs.pop('scheme')
        self.titles = kwargs.pop('titles')
        self.scheme = PERSON_NAME_SCHEMES.get(self.scheme_name)
        if self.titles:
            self.scheme_titles = PERSON_NAME_TITLE_GROUPS.get(self.titles)
        else:
            self.scheme_titles = None
        self.one_required = kwargs.get('required', True)
        require_all_fields = kwargs.pop('require_all_fields', False)
        kwargs['required'] = False
        kwargs['widget'] = (kwargs.get('widget') or self.widget)(
            scheme=self.scheme, titles=self.scheme_titles, field=self, **kwargs.pop('widget_kwargs', {})
        )
        defaults.update(**kwargs)
        for fname, label, size in self.scheme['fields']:
            defaults['label'] = label
            if fname == 'title' and self.scheme_titles:
                d = dict(defaults)
                d.pop('max_length', None)
                d.pop('validators', None)
                field = forms.ChoiceField(
                    **d,
                    choices=[('', '')] + [(d, d) for d in self.scheme_titles[1]]
                )

            elif fname == 'salutation':
                d = dict(defaults)
                d.pop('max_length', None)
                d.pop('validators', None)
                field = forms.ChoiceField(
                    **d,
                    choices=[('', '---')] + PERSON_NAME_SALUTATIONS
                )
            else:
                field = forms.CharField(**defaults)
            field.part_name = fname
            fields.append(field)
        super().__init__(
            fields=fields, require_all_fields=False, *args, **kwargs
        )
        self.require_all_fields = require_all_fields
        self.required = self.one_required
示例#3
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.fields['name_scheme'].choices = (
         (k, _('Ask for {fields}, display like {example}').format(
             fields=' + '.join(str(vv[1]) for vv in v['fields']),
             example=v['concatenation'](v['sample'])))
         for k, v in PERSON_NAME_SCHEMES.items())
     self.fields['name_scheme_titles'].choices = [
         ('', _('Free text input'))
     ] + [(k, '{scheme}: {samples}'.format(scheme=v[0],
                                           samples=', '.join(v[1])))
          for k, v in PERSON_NAME_TITLE_GROUPS.items()]
示例#4
0
    def __init__(self, *args, **kwargs):
        fields = []
        defaults = {
            'widget': self.widget,
            'max_length': kwargs.pop('max_length', None),
        }
        self.scheme_name = kwargs.pop('scheme')
        self.titles = kwargs.pop('titles')
        self.scheme = PERSON_NAME_SCHEMES.get(self.scheme_name)
        if self.titles:
            self.scheme_titles = PERSON_NAME_TITLE_GROUPS.get(self.titles)
        else:
            self.scheme_titles = None
        self.one_required = kwargs.get('required', True)
        require_all_fields = kwargs.pop('require_all_fields', False)
        kwargs['required'] = False
        kwargs['widget'] = (kwargs.get('widget')
                            or self.widget)(scheme=self.scheme,
                                            titles=self.scheme_titles,
                                            field=self,
                                            **kwargs.pop('widget_kwargs', {}))
        defaults.update(**kwargs)
        for fname, label, size in self.scheme['fields']:
            defaults['label'] = label
            if fname == 'title' and self.scheme_titles:
                d = dict(defaults)
                d.pop('max_length', None)
                field = forms.ChoiceField(**d,
                                          choices=[('', '')] +
                                          [(d, d)
                                           for d in self.scheme_titles[1]])

            elif fname == 'salutation':
                d = dict(defaults)
                d.pop('max_length', None)
                field = forms.ChoiceField(**d,
                                          choices=[('', '---')] +
                                          [(s, s)
                                           for s in PERSON_NAME_SALUTATIONS])
            else:
                field = forms.CharField(**defaults)
            field.part_name = fname
            fields.append(field)
        super().__init__(fields=fields,
                         require_all_fields=False,
                         *args,
                         **kwargs)
        self.require_all_fields = require_all_fields
        self.required = self.one_required