Esempio n. 1
0
def ballot_voting_form(ballot_voting, request):

    yes_no_choices = [(True, _('Yes')), (False, _('No')), (None, _('Abstention'))]
    max_points = 9 if len(ballot_voting.options) > 3 else 3
    point_choices = [(i, str(i)) for i in range(max_points+1)]

    schema = Schema()

    for option in ballot_voting.options:

        option_schema = SchemaNode(Mapping(), name=str(option.uuid), title=option.title)

        option_schema.add(SchemaNode(
            Boolean(),
            validator=OneOf([x[0] for x in yes_no_choices]),
            widget=RadioChoiceWidget(values=yes_no_choices, inline=True),
            name='yes_no',
            title=f'Stimmst du dem Antrag zu?'))

        option_schema.add(SchemaNode(
            Int(),
            validator=OneOf([x[0] for x in point_choices]),
            widget=RadioChoiceWidget(values=point_choices, inline=True, null_value='0'),
            name='points',
            title='Welche Punktzahl gibst du dem Antrag?',
            missing=0))

        schema.add(option_schema)

    form = Form(schema, request, buttons=[Button(title=_('check'))])
    return form
Esempio n. 2
0
def items_for_ballot_select_widgets(ballot, departments, proposition_types):
    area_items = [('', _('not_determined'))]
    voting_phase_items = [('', _('not_determined'))]

    for department in sorted(departments, key=attrgetter('name')):
        for area in sorted(department.areas, key=attrgetter('name')):
            area_items.append((area.id, f"{department.name} - {area.name}"))

        for voting_phase in department.voting_phases:
            if voting_phase.ballots_can_be_added:
                voting_phase_title = voting_phase_helper.voting_phase_title(
                    voting_phase)
                voting_phase_items.append(
                    (voting_phase.id,
                     f'{department.name} - {voting_phase_title}'))

    proposition_type_items = [('', _('not_determined'))
                              ] + [(t.id, t.name) for t in proposition_types]
    voting_type_items = [("", _('not_determined'))] + [
        (e.name, _('_'.join(['voting_type', e.value]))) for e in VotingType
    ]
    return {
        'area': area_items,
        'proposition_type': proposition_type_items,
        'voting': voting_phase_items,
        'voting_type': voting_type_items
    }
Esempio n. 3
0
class DepartmentSchema(Schema):
    name = string_property(title=_('name'), validator=Length(min=3, max=255))
    description = string_property(title=_('description'),
                                  validator=Length(min=10, max=2000),
                                  missing='')
    exporter_settings = json_property(title=_('exporter_settings'), missing={})
    voting_module_settings = json_property(title=_('voting_module_settings'),
                                           missing={})
class PropositionTypeSchema(Schema):
    name = string_property(title=_('name'), validator=Length(max=64))
    abbreviation = string_property(title=_('abbreviation'),
                                   validator=Length(max=3))
    description = string_property(title=_('description'),
                                  validator=Length(min=10, max=4000),
                                  missing='')
    policy_id = int_property(title=_('policy'))
Esempio n. 5
0
class PropositionNewSchema(PropositionSchema):
    area_id = int_property(title=_('subject_area'))
    proposition_type_id = int_property(title=_('proposition_type'))
    editing_remarks = string_property(
        title=_('editing_remarks'),
        description=_('editing_remarks_description'),
        missing='',
        validator=Length(max=2000))
class ArgumentSchema(Schema):
    title = string_property(title=_('title'),
                            validator=Length(min=5, max=TITLE_MAXLENGTH))
    abstract = string_property(title=_('abstract'),
                               validator=Length(min=5, max=ABSTRACT_MAXLENGTH))
    details = string_property(title=_('details'),
                              validator=Length(min=10, max=4096),
                              missing='')
class VotingPhaseTypeSchema(Schema):
    name = string_property(title=_('name'), validator=Length(min=3, max=255))
    abbreviation = string_property(title=_('abbreviation'),
                                   validator=Length(max=6))
    secret_voting_possible = bool_property(title=_('secret_voting_possible'))
    voting_type = enum_property(VotingType, title=_('voting_type'))
    description = string_property(title=_('description'),
                                  validator=Length(min=10, max=2000),
                                  missing='')
Esempio n. 8
0
def items_for_document_select_widgets(model, departments, proposition_types):
    proposition_type_items = [('', _('not_determined'))] + [(t.id, t.name) for t in proposition_types]
    area_items = [('', _('not_determined'))]

    for department in sorted(departments, key=attrgetter('name')):
        for area in sorted(department.areas, key=attrgetter('name')):
            area_items.append((area.id, f"{department.name} - {area.name}"))

    return {'area': area_items, 'proposition_type': proposition_type_items}
class PropositionNoteSchema(Schema):
    proposition_id = int_property(title=_('proposition_id'), missing=None)
    user_id = int_property(title=_('user_id'), missing=None)
    notes = string_property(title=_('notes'),
                            validator=Length(min=0, max=2048),
                            missing=None)
    vote = enum_property(VoteByUser,
                         title=_('vote'),
                         missing=VoteByUser.UNSURE)
class BallotSchema(Schema):
    name = string_property(title=_('name'),
                           validator=Length(min=2, max=23),
                           missing='')
    election = int_property(title=_('election_positions'), missing=0)
    result = json_property(title=_('voting_result'), missing={})
    area_id = int_property(title=_('subject_area'), missing=None)
    voting_id = int_property(title=('voting_phase'), missing=None)
    proposition_type_id = int_property(title=('proposition_type'),
                                       missing=None)
Esempio n. 11
0
class PropositionSchema(Schema):
    title = string_property(title=_('title'), validator=Length(min=5, max=255))
    content = string_property(title=_('content'),
                              validator=Length(min=10, max=100_000))
    motivation = string_property(title=_('motivation'),
                                 missing='',
                                 validator=Length(max=100_000))
    tags = set_property(title=_('tags'), missing=tuple())
    abstract = string_property(title=_('abstract'),
                               missing='',
                               validator=Length(max=500))
    relation_type = enum_property(PropositionRelationType, missing=None)
    related_proposition_id = string_property(missing=None)
def items_for_voting_phase_select_widgets(phase_types, departments, voting_phase=None):
    status_items = [(e.name, _('_'.join(['voting_status', e.value]))) for e in VotingStatus]

    phase_type_items = [(pt.id, pt.name) for pt in phase_types]
    department_items = [(d.id, d.name) for d in departments]

    return {'status': status_items, 'phase_type': phase_type_items, 'department': department_items}
Esempio n. 13
0
 def __init__(self, request, action):
     super().__init__(ArgumentForPropositionSchema(),
                      request,
                      action,
                      buttons=[Button(title=_("submit"))])
     self.set_widgets({
         'proposition_id': HiddenWidget(),
         'relation_type': HiddenWidget(),
         **argument_widgets
     })
class VotingPhaseSchema(Schema):
    name = string_property(title=_('name'),
                           validator=Length(min=2, max=23),
                           missing='')
    title = string_property(title=_('title'),
                            validator=Length(min=5, max=160),
                            missing='')
    target = date_property(title=_('target'), missing=None)
    status = enum_property(VotingStatus, title=_('voting_status'))
    department_id = int_property(title=_('department'))
    phase_type_id = int_property(title=_('voting_phase_type'))
    secret = bool_property(title=_('secret_voting_possible'))
    description = string_property(title=_('description'),
                                  validator=Length(min=10, max=65536),
                                  missing='')
    voting_module_data = json_property(title=_('voting_module_data'),
                                       missing={})
Esempio n. 15
0
def submit_login(self, request):
    try:
        user_found = self.find_user()
    except ValueError:
        return Response(status=400)

    is_insecure_empty_password_ok = request.app.settings.app.insecure_development_mode

    if user_found and self.verify_password(is_insecure_empty_password_ok):

        @request.after
        def remember(response):
            identity = morepath.Identity(self.user.id, user=self.user)
            request.app.remember_identity(response, request, identity)

        request.flash(_("alert_logged_in"), "success")
        return redirect(self.back_url or "/")

    else:
        request.flash(_("alert_login_failed"), "danger")
        return LoginCell(self, request).show()
def items_for_voting_phase_select_widgets(phase_types, departments, voting_phase=None):
    if voting_phase is not None and voting_phase.target:
        voting_states = [vs for vs in VotingStatus if vs != VotingStatus.PREPARING]
    else:
        voting_states = [VotingStatus.PREPARING]

    status_items = [(e.name, _('_'.join(['voting_status', e.value]))) for e in voting_states]

    phase_type_items = [(pt.id, pt.name) for pt in phase_types]
    department_items = [(d.id, d.name) for d in departments]

    return {'status': status_items, 'phase_type': phase_type_items, 'department': department_items}
def items_for_proposition_select_widgets(departments, tags, proposition_types=None, selected_tags=None):
    area_items = []

    for department in sorted(departments, key=attrgetter('name')):
        for area in sorted(department.areas, key=attrgetter('name')):
            area_items.append((area.id, f"{department.name} - {area.name}"))

    status_items = [(e.name, _('_'.join(['proposition_status', e.value]))) for e in PropositionStatus]
    visibility_items = [(e.name, _('_'.join(['proposition_visibility', e.value]))) for e in PropositionVisibility]

    tag_items = [(t.name, t.name) for t in tags]

    if selected_tags is not None:
        tag_names_to_create = set(selected_tags) - set(t.name for t in tags)
        tag_items.extend((t, t) for t in tag_names_to_create)

    items = {'area': area_items, 'status': status_items, 'tags': tag_items, 'visibility': visibility_items}

    if proposition_types:
        proposition_type_items = [(t.id, t.name) for t in proposition_types]
        items['proposition_type'] = proposition_type_items

    return items
class PropositionNewSchema(Schema):
    area_id = int_property(title=_('subject_area'))
    title = string_property(title=_('title'), validator=Length(min=5, max=512))
    external_discussion_url = string_property(
        title=_('external_discussion_url'), validator=colander.url)
    abstract = string_property(title=_('abstract'),
                               validator=Length(min=5, max=2048))
    content = string_property(title=_('content'),
                              validator=Length(min=10, max=65536))
    motivation = string_property(title=_('motivation'), missing='')
    tags = set_property(title=_('tags'), missing=tuple())
    relation_type = string_property(validator=OneOf(['replaces', 'modifies']),
                                    missing=None)
    related_proposition_id = int_property(missing=None)
Esempio n. 19
0
class PropositionEditSchema(PropositionSchema):
    voting_identifier = string_property(title=_('voting_identifier'),
                                        validator=Length(max=10),
                                        missing=None)
    submitter_invitation_key = string_property(
        title=_('submitter_invitation_key'), missing=None)
    external_discussion_url = string_property(
        title=_('external_discussion_url'), validator=colander.url, missing='')
    status = enum_property(PropositionStatus, title=_('status'))
    visibility = enum_property(PropositionVisibility, title=_('visibility'))
    external_fields = json_property(title=_('external_fields'), missing={})
Esempio n. 20
0
class PropositionNewDraftSchema(Schema):
    title = string_property(title=_('title'), validator=Length(min=5, max=255))
    content = string_property(title=_('content'),
                              validator=Length(min=10, max=100_000))
    motivation = string_property(title=_('motivation'),
                                 missing='',
                                 validator=Length(max=100_000))
    tags = set_property(title=_('tags'), missing=tuple())
    abstract = string_property(title=_('abstract'),
                               validator=Length(max=500),
                               missing='')
    editing_remarks = string_property(
        title=_('editing_remarks'),
        description=_('editing_remarks_description'),
        missing='',
        validator=Length(max=2000))
    document_id = int_property()
    section = string_property()
Esempio n. 21
0
 def __init__(self, request, action):
     super().__init__({{ cookiecutter.ConceptName }}Schema(), request, action, buttons=[Button(title=_("submit"))])
Esempio n. 22
0
class PolicySchema(Schema):
    name = string_property(title=_('name'), validator=Length(max=64))
    description = string_property(title=_('description'), validator=Length(max=4000), missing='')
    majority = enum_property(Majority, title=_('majority'))
    proposition_expiration = int_property(title=_('proposition_expiration'))
    qualification_minimum = int_property(title=_('qualification_minimum'))
    qualification_quorum = decimal_property(title=_('qualification_quorum'))
    range_max = int_property(title=_('range_max'))
    range_small_max = int_property(title=_('range_small_max'))
    range_small_options = int_property(title=_('range_small_options'))
    secret_minimum = int_property(title=_('secret_minimum'))
    secret_quorum = decimal_property(title=_('secret_quorum'))
    submitter_minimum = int_property(title=_('submitter_minimum'))
    voting_duration = int_property(title=_('voting_duration'))
    voting_system = enum_property(VotingSystem, title=_('voting_system'))
Esempio n. 23
0
class PageSchema(Schema):
    name = string_property(title=_('name'), validator=Length(min=3, max=255))
    lang = string_property(title=_('lang'), validator=Length(min=2, max=16))
    title = string_property(title=_('title'), validator=Length(max=255), missing='')
    text = string_property(title=_('text'), missing='')
    permissions = string_property(title=_('permissions'), missing='{}')
Esempio n. 24
0
 def __init__(self, request, action):
     super().__init__(BallotSchema(),
                      request,
                      action,
                      buttons=[Button(title=_("submit"))])
 def __init__(self, request, action):
     super().__init__(CustomizableTextSchema(),
                      request,
                      action,
                      buttons=[Button(title=_("submit"))])
class PropositionEditSchema(PropositionNewSchema):
    voting_identifier = string_property(title=_('voting_identifier'),
                                        validator=Length(max=10),
                                        missing=None)
    status = enum_property(PropositionStatus, title=_('status'))
 def __init__(self, request, action):
     super().__init__(PropositionNoteSchema(),
                      request,
                      action,
                      buttons=[Button(title=_("submit"))])
 def __init__(self, request, action):
     super().__init__(ArgumentSchema(),
                      request,
                      action,
                      buttons=[Button(title=_("submit"))])
     self.set_widgets(argument_widgets)
def items_for_proposition_note_select_widgets(model):
    return {
        'vote': [(name, _('vote_by_user_' + name.lower()))
                 for name, member in VoteByUser.__members__.items()]
    }
Esempio n. 30
0
class DepartmentSchema(Schema):
    name = string_property(title=_('name'), validator=Length(min=3, max=255))
    description = string_property(title=_('description'),
                                  validator=Length(min=10, max=2000),
                                  missing='')