pas.utils

Attributes

CLEX_URL

Functions

_is_kantonsrat_role(→ bool)

A Kantonsrat role has meta.org_type == 'Kantonsrat' (set

is_active_kantonsrat_member(→ bool)

get_active_kantonsrat_parliamentarians(...)

fetch_clex_kantonsrat_members(→ set[tuple[str, str]])

Fetch active Kantonsrat members from the CLEX frontend.

format_swiss_number(→ str)

round_to_five_rappen(→ decimal.Decimal)

Round a decimal value to the nearest 5 Rappen (0.05 CHF).

is_commission_president(→ bool)

Check if a parliamentarian is president of the commission for the given

get_parliamentarians_with_settlements(...)

Get all parliamentarians who were active and had settlements

get_parties_with_settlements(...)

Get all parties that had active members with attendances during the

is_parliamentarian(→ bool)

Check if a user has parliamentarian role.

is_parliamentarian_role(→ bool)

Check if a role is a parliamentarian role.

get_active_commission_memberships(...)

Get active commission memberships for a parliamentarian user.

get_commissions_with_memberships(...)

Get all commissions that had active memberships during the

Module Contents

pas.utils._is_kantonsrat_role(role: onegov.pas.models.parliamentarian_role.PASParliamentarianRole | onegov.parliament.models.parliamentarian_role.ParliamentarianRole) bool[source]

A Kantonsrat role has meta.org_type == ‘Kantonsrat’ (set by the KUB importer).

pas.utils.is_active_kantonsrat_member(parliamentarian: onegov.pas.models.parliamentarian.PASParliamentarian | onegov.parliament.models.parliamentarian.Parliamentarian, reference_date: datetime.date | None = None) bool[source]
pas.utils.get_active_kantonsrat_parliamentarians(app: onegov.core.Framework, reference_date: datetime.date | None = None) list[onegov.pas.models.parliamentarian.PASParliamentarian][source]
pas.utils.CLEX_URL = 'https://zg-compwork.clex.ch/frontend/people'[source]
pas.utils.fetch_clex_kantonsrat_members(reference_date: datetime.date | None = None) set[tuple[str, str]][source]

Fetch active Kantonsrat members from the CLEX frontend.

Returns set of (last_name, first_name) tuples for members without an exit date or with an exit date >= reference_date.

pas.utils.format_swiss_number(value: decimal.Decimal | int) str[source]
pas.utils.round_to_five_rappen(value: decimal.Decimal | int) decimal.Decimal[source]

Round a decimal value to the nearest 5 Rappen (0.05 CHF).

pas.utils.is_commission_president(parliamentarian: onegov.pas.models.parliamentarian.PASParliamentarian, attendance_or_commission_id: onegov.pas.models.attendence.Attendence | uuid.UUID, settlement_run: onegov.pas.models.SettlementRun) bool[source]

Check if a parliamentarian is president of the commission for the given attendance or commission_id during the settlement run period.

pas.utils.get_parliamentarians_with_settlements(session: sqlalchemy.orm.Session, start_date: datetime.date, end_date: datetime.date, settlement_run_id: uuid.UUID | None = None) list[onegov.pas.models.parliamentarian.PASParliamentarian][source]

Get all parliamentarians who were active and had settlements (attendances or presidential allowances) during the specified period.

pas.utils.get_parties_with_settlements(session: sqlalchemy.orm.Session, start_date: datetime.date, end_date: datetime.date) list[onegov.pas.models.party.Party][source]

Get all parties that had active members with attendances during the specified period.

This function ensures accurate party filtering by checking that parliamentarians were active members of their party at the time of each attendance, properly handling cases where parliamentarians switch parties or have changing membership dates.

pas.utils.is_parliamentarian(user: onegov.user.User | None) bool[source]

Check if a user has parliamentarian role.

pas.utils.is_parliamentarian_role(role: str | None) bool[source]

Check if a role is a parliamentarian role.

pas.utils.get_active_commission_memberships(user: onegov.user.User | None) list[onegov.pas.models.commission_membership.PASCommissionMembership][source]

Get active commission memberships for a parliamentarian user.

pas.utils.get_commissions_with_memberships(session: sqlalchemy.orm.Session, start_date: datetime.date, end_date: datetime.date) list[onegov.pas.models.commission.PASCommission][source]

Get all commissions that had active memberships during the specified period.

This function ensures accurate commission filtering by checking that commissions had active members during the period, properly handling cases where memberships have changing dates.