Пример #1
0
class ISyncSettings(form.Schema):
    """Interface for the control panel form.
    """
    remote = schema.TextLine(
        title=_(u'SAPL JSON Endpoint'),
        description=_(u'URL to the JSON Endpoint for SAPL.'),
        default=u'',
    )

    path = schema.TextLine(
        title=_(u'Local SAPL Storage'),
        description=_(u'Path to store SAPL information. i.e.: /processo-legislativo'),
        required=True,
        default=u'',
    )
    def parliamentarians(self):
        """Return list of parliamentarians of the legislature.
        """
        results = []
        for member in self.context.members:
            obj = member.to_object
            if obj is not None:
                results.append(dict(
                    full_name=obj.full_name,
                    url=obj.absolute_url(),
                    name=obj.title,
                    party=obj.get_party(),
                    status=_(u'Active') if obj.is_active else _(u'Inactive'),
                ))
            else:
                continue

        return results
    def parliamentarians(self):
        """Return list of parliamentarians of the legislature.
        """
        results = []
        for member in self.context.members:
            obj = member.to_object
            if obj is not None:
                results.append(
                    dict(
                        full_name=obj.full_name,
                        url=obj.absolute_url(),
                        name=obj.title,
                        party=obj.get_party(),
                        status=_(u'Active')
                        if obj.is_active else _(u'Inactive'),
                    ))
            else:
                continue

        return results
class IPartyAffiliationItem(model.Schema):
    """Define a party affiliation record."""

    party = schema.TextLine(
        title=_(u'Party'),
        required=True,
    )

    form.widget(date_affiliation=DateFieldWidget)
    date_affiliation = schema.Date(
        title=_(u'Date of affiliation'),
        min=START_REPUBLIC_BRAZIL,
        required=True,
    )

    form.widget(date_disaffiliation=DateFieldWidget)
    date_disaffiliation = schema.Date(
        title=_(u'Date of disaffiliation'),
        min=START_REPUBLIC_BRAZIL,
        required=False,
    )
class IBoardMember(model.Schema):
    """Define a board member record."""

    # XXX: this should be the right way to do it but we have an issue
    #      involving at least 2 packages: plone.formwidget.contenttree
    #      and zope.pagetemplate
    #      see: https://stackoverflow.com/questions/22769633/using-relations-in-a-datagridfield
    # member = RelationChoice(
    #     title=_(u'Member'),
    #     required=True,
    #     source=ObjPathSourceBinder(object_provides=IParliamentarian.__identifier__),
    # )

    member = schema.TextLine(
        title=_(u'Member'),
        required=True,
    )

    position = schema.TextLine(
        title=_(u'Position'),
        required=True,
    )
class ISession(model.Schema):
    """Represents a legislative session."""

    title = schema.TextLine(
        title=_(u'Number'),
        description=_(u''),
        required=True,
    )

    description = schema.Text(
        title=_(u'Description'),
        description=_(u''),
        required=False,
    )

    form.widget(start_date=DateFieldWidget)
    start_date = schema.Date(
        title=_(u'Start date'),
        description=_(u''),
        required=True,
    )

    form.widget(end_date=DateFieldWidget)
    end_date = schema.Date(
        title=_(u'End date'),
        description=_(u''),
        required=True,
    )

    form.widget(legislative_board=DataGridFieldFactory)
    legislative_board = schema.List(
        title=_(u'Legislative Board'),
        description=_(u''),
        required=False,
        value_type=DictRow(title=u'legislative_board_row', schema=IBoardMember),
        default=[],
    )
class ILegislature(model.Schema):
    """Represents a legislature."""

    title = schema.TextLine(
        title=_(u'Number'),
        description=_(u''),
        required=True,
    )

    description = schema.Text(
        title=_(u'Description'),
        description=_(u''),
        required=False,
    )
    form.widget(start_date=DateFieldWidget)
    start_date = schema.Date(
        title=_(u'Start date'),
        description=_(u''),
        required=True,
    )

    form.widget(end_date=DateFieldWidget)
    end_date = schema.Date(
        title=_(u'End date'),
        description=_(u''),
        required=True,
    )

    members = RelationList(
        title=_(u'Members'),
        required=False,
        default=[],
        value_type=RelationChoice(
            title=_(u'Members'),
            source=ObjPathSourceBinder(object_provides=IParliamentarian.__identifier__),
        ),
    )
    def long_title(self):
        """Return a string formed by the number of the session and the
        years. If the legislature is the current one, it also displays this
        information.
        """
        title, start, end = self.title, self.start_date.year, self.end_date.year
        # FIXME: the translation is not being applied
        # infix = _(u'session_infix_long_title', default=u' Legislative Session')
        infix = ''
        long_title = u'{0}{1} ({2} - {3})'.format(title, infix, start, end)
        if self.is_current:
            # XXX: can't put this translation to work
            # long_title += u' ({0})'.format(_(u'Current'))
            long_title += u' ({0})'.format(_(u'Atual'))

        return long_title
class IParliamentarian(model.Schema):
    """Represents a parliamentarian."""

    title = schema.TextLine(
        title=_(u'Name'),
        description=_(u''),
        required=True,
    )

    full_name = schema.TextLine(
        title=_(u'Full Name'),
        description=_(u''),
        required=True,
    )

    form.widget(birthday=DateFieldWidget)
    birthday = schema.Date(
        title=_(u'Birthday'),
        constraint=check_birthday,
        required=True,
        min=MIN_DATE,
        max=MAX_DATE,
    )

    form.widget(description=WysiwygFieldWidget)
    description = schema.Text(
        title=_(u'Bio'),
        description=_(u''),
        required=False,
    )

    image = NamedBlobImage(
        title=_(u'Portrait'),
        description=_(u''),
        required=False,
    )

    email = schema.TextLine(
        title=_(u'E-mail'),
        description=_(u''),
        required=False,
    )

    site = schema.TextLine(
        title=_(u'Site'),
        description=_(u''),
        required=False,
    )

    address = schema.TextLine(
        title=_(u'Address'),
        description=_(u''),
        required=True,
    )

    postal_code = schema.TextLine(
        title=_(u'Postal code'),
        description=_(u''),
        required=True,
    )

    telephone = schema.ASCIILine(
        title=_(u'Telephone'),
        description=_(u''),
        required=True,
    )

    form.widget(party_affiliation=DataGridFieldFactory)
    party_affiliation = schema.List(
        title=_(u'Party affiliation'),
        description=_(u''),
        required=True,
        value_type=DictRow(title=u'party_affiliation_row', schema=IPartyAffiliationItem),
        default=[],
    )
Пример #10
0
class SyncSettingsEditForm(controlpanel.RegistryEditForm):
    schema = ISyncSettings
    label = _(u'SAPL Sync settings')
    description = _(u'Settings for SAPL Sync Integration.')