Example #1
0
    def __init__(self, *args, **kwargs):

        super(SavForm, self).__init__(*args, **kwargs)

        self.fields.pop('question')
        self.fields.pop('choice_type')

        elig_help_text = _("set minimal number of votes")
        label_text = _("Minimum votes")
        ordered_dict_prepend(
            self.fields, 'min_votes',
            forms.CharField(label=label_text, help_text=elig_help_text))
Example #2
0
    def __init__(self, *args, **kwargs):
        deps = kwargs['initial']['departments_data'].split('\n')
        DEPARTMENT_CHOICES = []
        for dep in deps:
            DEPARTMENT_CHOICES.append((dep.strip(), dep.strip()))

        super(StvForm, self).__init__(*args, **kwargs)

        self.fields.pop('question')
        answers = len(
            filter(lambda k: k.startswith("%s-answer_" % self.prefix),
                   self.data)) / 2
        if not answers:
            answers = len(
                filter(lambda k: k.startswith("answer_"), self.initial))
        if answers == 0:
            answers = DEFAULT_ANSWERS_COUNT

        self.fields.clear()
        for ans in range(answers):
            field_key = 'answer_%d' % ans
            field_key1 = 'department_%d' % ans
            self.fields[field_key] = forms.CharField(
                max_length=600,
                required=True,
                widget=CandidateWidget(departments=DEPARTMENT_CHOICES),
                label=('Candidate'))

        widget = forms.TextInput(attrs={'hidden': 'True'})
        dep_lim_help_text = _(
            "maximum number of elected from the same constituency")
        dep_lim_label = _("Constituency limit")
        ordered_dict_prepend(
            self.fields, 'department_limit',
            forms.CharField(help_text=dep_lim_help_text,
                            label=dep_lim_label,
                            widget=widget,
                            required=False))

        widget = forms.CheckboxInput(attrs={'onclick': 'enable_limit()'})
        limit_help_text = _(
            "enable limiting the elections from the same constituency")
        limit_label = _("Limit elected per constituency")
        ordered_dict_prepend(
            self.fields, 'has_department_limit',
            forms.BooleanField(widget=widget,
                               help_text=limit_help_text,
                               label=limit_label,
                               required=False))

        elig_help_text = _("set the eligibles count of the election")
        label_text = _("Eligibles count")
        ordered_dict_prepend(
            self.fields, 'eligibles',
            forms.CharField(label=label_text, help_text=elig_help_text))
Example #3
0
    def __init__(self, *args, **kwargs):
        self.election = kwargs.pop('election', None)
        super(PollForm, self).__init__(*args, **kwargs)
        CHOICES = (
            ('public', 'public'),
            ('confidential', 'confidential'),
        )

        TYPES = (
            ('google', 'google'),
            ('facebook', 'facfebook'),
            ('other', 'other')
        )

        ordered_dict_prepend(self.fields, 'jwt_file',
                             forms.FileField(
                                 label="JWT public keyfile",
                                 required=False))
        self.fields['jwt_file'].widget.attrs['accept'] = '.pem'
        self.fields['jwt_public_key'] = forms.CharField(required=False,
                                                        widget=forms.Textarea)
        self.fields['oauth2_type'] = forms.ChoiceField(required=False,
                                                       choices=TYPES)
        self.fields['oauth2_client_type'] = forms.ChoiceField(required=False,
                                                              choices=CHOICES)
        self.fields['google_code_url'] = forms.CharField(
                                    widget=HiddenInput,
                                    initial="https://accounts.google.com/o/oauth2/auth",
                                    required=False)
        self.fields['google_exchange_url'] = forms.CharField(
                                    widget=HiddenInput,
                                    initial="https://accounts.google.com/o/oauth2/token",
                                    required=False)
        self.fields['google_confirmation_url'] = forms.CharField(
                                    widget=HiddenInput,
                                    initial="https://www.googleapis.com/oauth2/v1/userinfo",
                                    required=False)
        self.fields['facebook_code_url'] = forms.CharField(
                                    widget=HiddenInput,
                                    initial="https://www.facebook.com/dialog/oauth",
                                    required=False)
        self.fields['facebook_exchange_url'] = forms.CharField(
                                    widget=HiddenInput,
                                    initial="https://graph.facebook.com/oauth/access_token",
                                    required=False)
        self.fields['facebook_confirmation_url'] = forms.CharField(
                                    widget=HiddenInput,
                                    initial="https://graph.facebook.com/v2.2/me",
                                    required=False)

        if self.initial:
            shib = self.initial.get('shibboleth_constraints', None)
            if shib is not None and isinstance(shib, dict):
                self.initial['shibboleth_constraints'] = json.dumps(shib)
        if self.election.feature_frozen:
            self.fields['name'].widget.attrs['readonly'] = True

        auth_title = _('2-factor authentication')
        auth_help = _('2-factor authentication help text')
        self.fieldsets = {'auth': [auth_title, auth_help, []]}
        self.fieldset_fields = []

        auth_fields = ['jwt', 'google', 'facebook', 'shibboleth', 'oauth2']
        for name, field in list(self.fields.items()):
            if name.split("_")[0] in auth_fields:
                self.fieldsets['auth'][2].append(name)
                self.fieldset_fields.append(field)

        keyOrder = self.fieldsets['auth'][2]
        for field in ['jwt_auth', 'oauth2_thirdparty', 'shibboleth_auth']:
            prev_index = keyOrder.index(field)
            item = keyOrder.pop(prev_index)
            keyOrder.insert(0, item)
            self.fields[field].widget.attrs['field_class'] = 'fieldset-auth'
            if field == 'jwt_auth':
                self.fields[field].widget.attrs['field_class'] = 'clearfix last'