Example #1
0
File: forms.py Project: jitka/zeus
    def __init__(self, owner, institution, *args, **kwargs):
        self.institution = institution
        self.owner = owner

        if kwargs.get('lang'):
            lang = kwargs.pop('lang')
        else:
            lang = None
        super(ElectionForm, self).__init__(*args, **kwargs)
        choices = [('en', _('English')), ('el', _('Greek'))]
        help_text = _("Set the language that will be used for email messages")
        self.fields['communication_language'] = forms.ChoiceField(
            label=_("Communication language"),
            choices=choices,
            initial=lang,
            help_text=help_text)
        self.creating = True
        self._initial_data = {}
        if self.instance and self.instance.pk:
            self._initial_data = {}
            for field in LOG_CHANGED_FIELDS:
                self._initial_data[field] = self.initial[field]
            self.creating = False

        eligible_types = owner.eligible_election_types
        if not self.creating and self.instance:
            eligible_types.add(self.instance.election_module)
        eligible_types_choices = filter(lambda x: x[0] in eligible_types,
                                        ELECTION_MODULES_CHOICES)

        self.fields['election_module'].choices = eligible_types_choices
        if 'election_module' in self.data:
            if self.data['election_module'] != 'stv':
                self.fields['departments'].required = False
        if self.instance and self.instance.pk:
            self.fields.get('trustees').initial = \
                election_trustees_to_text(self.instance)
            self.fields.get('remote_mixes').initial = \
                bool(self.instance.mix_key)

        for field, features in self.FIELD_REQUIRED_FEATURES.iteritems():
            editable = all([self.instance.check_feature(f) for \
                            f in features])

            widget = self.fields.get(field).widget
            if not editable:
                self.fields.get(field).widget.attrs['readonly'] = True
                if isinstance(widget, forms.CheckboxInput):
                    self.fields.get(field).widget.attrs['disabled'] = True

        if not self.instance.frozen_at:
            self.fields.pop('voting_extended_until')
Example #2
0
    def __init__(self, institution, *args, **kwargs):
        self.institution = institution
        if kwargs.get('lang'):
            lang = kwargs.pop('lang')
        else:
            lang = None
        super(ElectionForm, self).__init__(*args, **kwargs)
        choices = [('en', _('English')),
                   ('el', _('Greek'))]
        help_text = _("Set the language that will be used for email messages")
        self.fields['communication_language'] = forms.ChoiceField(label=
                                                    _("Communication language"),
                                                    choices=choices,
                                                    initial=lang,
                                                    help_text = help_text)
        self.creating = True
        self._inital_data = {}
        if self.instance and self.instance.pk:
            self._initial_data = {}
            for field in LOG_CHANGED_FIELDS:
                self._initial_data[field] = self.initial[field]
            self.creating = False
        if 'election_module' in self.data:
            if self.data['election_module'] != 'stv':
                self.fields['departments'].required = False
        if self.instance and self.instance.pk:
            self.fields.get('trustees').initial = \
                election_trustees_to_text(self.instance)
            self.fields.get('remote_mixes').initial = \
                bool(self.instance.mix_key)

        for field, features in self.FIELD_REQUIRED_FEATURES.iteritems():
            editable = all([self.instance.check_feature(f) for \
                            f in features])

            widget = self.fields.get(field).widget
            if not editable:
                self.fields.get(field).widget.attrs['readonly'] = True
                if isinstance(widget, forms.CheckboxInput):
                    self.fields.get(field).widget.attrs['disabled'] = True

        if not self.instance.frozen_at:
            self.fields.pop('voting_extended_until')
Example #3
0
    def clean(self):
        data = super(ElectionForm, self).clean()
        self.clean_voting_dates(data.get('voting_starts_at'),
                                data.get('voting_ends_at'),
                                data.get('voting_extended_until'))
        for field, features in self.FIELD_REQUIRED_FEATURES.items():
            if not self.instance.pk:
                continue
            editable = all([self.instance.check_feature(f) for f in features])
            if not editable and field in self.cleaned_data:
                if field == 'trustees':
                    self.cleaned_data[field] = \
                        election_trustees_to_text(self.instance)
                elif field == 'remote_mixes':
                    self.cleaned_data[field] = bool(self.instance.mix_key)
                else:
                    self.cleaned_data[field] = getattr(self.instance, field)

        return data
Example #4
0
    def clean(self):
        data = super(ElectionForm, self).clean()
        self.clean_voting_dates(data.get('voting_starts_at'),
                                data.get('voting_ends_at'),
                                data.get('voting_extended_until'))
        for field, features in self.FIELD_REQUIRED_FEATURES.iteritems():
            if not self.instance.pk:
                continue
            editable = all([self.instance.check_feature(f) for \
                            f in features])
            if not editable and field in self.cleaned_data:
                if field == 'trustees':
                    self.cleaned_data[field] = \
                        election_trustees_to_text(self.instance)
                elif field == 'remote_mixes':
                    self.cleaned_data[field] = bool(self.instance.mix_key)
                else:
                    self.cleaned_data[field] = getattr(self.instance, field)

        return data
Example #5
0
    def __init__(self, owner, institution, *args, **kwargs):
        self.institution = institution
        self.owner = owner

        if kwargs.get('lang'):
            lang = kwargs.pop('lang')
        else:
            lang = None
        super(ElectionForm, self).__init__(*args, **kwargs)
        choices = settings.LANGUAGES
        help_text = _("Set the language that will be used for email messages")
        self.fields['communication_language'] = forms.ChoiceField(
            label=_("Communication language"),
            choices=choices,
            initial=lang,
            help_text=help_text)
        self.fields['linked_polls'].widget = forms.HiddenInput()
        if owner.sms_data:
            help_text = _(
                "Notify voters using SMS (%d deliveries available for your account)"
            ) % owner.sms_data.left
            self.fields['sms_api_enabled'] = forms.BooleanField(
                label=_("Mobile SMS notifications enabled"),
                initial=True,
                required=False,
                help_text=help_text)
        else:
            del self.fields['sms_api_enabled']

        self.creating = True
        self._initial_data = {}
        if self.instance and self.instance.pk:
            self._initial_data = {}
            for field in LOG_CHANGED_FIELDS:
                self._initial_data[field] = self.initial[field]
            self.creating = False

        eligible_types = owner.eligible_election_types
        if not self.creating and self.instance:
            eligible_types.add(self.instance.election_module)
        eligible_types_choices = [
            x for x in ELECTION_MODULES_CHOICES if x[0] in eligible_types
        ]

        self.fields['election_module'].choices = eligible_types_choices

        self.fields['departments'].required = False
        if 'election_module' in self.data:
            if self.data['election_module'] == 'stv':
                self.fields['departments'].required = True

        if self.instance and self.instance.pk:
            self.fields.get('trustees').initial = \
                election_trustees_to_text(self.instance)
            self.fields.get('remote_mixes').initial = \
                bool(self.instance.mix_key)

        for field, features in self.FIELD_REQUIRED_FEATURES.items():
            editable = all([self.instance.check_feature(f) for f in features])

            widget = self.fields.get(field).widget
            if not editable:
                self.fields.get(field).widget.attrs['readonly'] = True
                if isinstance(widget, forms.CheckboxInput):
                    self.fields.get(field).widget.attrs['disabled'] = True

        if not self.instance.frozen_at:
            self.fields.pop('voting_extended_until')