notice.collections

Attributes

_StrColumnLike

_N

Classes

OfficialNoticeCollection

Manage a list of official notices.

Functions

get_unique_notice_name(→ str)

Create a unique, URL-friendly name.

Module Contents

notice.collections._StrColumnLike[source]
notice.collections._N[source]
notice.collections.get_unique_notice_name(name: str, session: sqlalchemy.orm.Session, model_class: type[onegov.notice.models.OfficialNotice]) str[source]

Create a unique, URL-friendly name.

class notice.collections.OfficialNoticeCollection(session: sqlalchemy.orm.Session, page: int = 0, state: NoticeState | None = None, term: str | None = None, order: str | None = None, direction: Literal['asc', 'desc'] | None = None, issues: Collection[str] | None = None, categories: Collection[str] | None = None, organizations: Collection[str] | None = None, user_ids: list[uuid.UUID] | None = None, group_ids: list[uuid.UUID] | None = None)[source]

Bases: onegov.core.collection.Pagination[_N]

Manage a list of official notices.

__eq__(other: object) bool[source]

Returns True if the current and the other Pagination instance are equal. Used to find the current page in a list of pages.

subset() Query[_N][source]

Returns an SQLAlchemy query containing all records that should be considered for pagination.

property page_index: int[source]

Returns the current page index (starting at 0).

page_by_index(index: int) typing_extensions.Self[source]

Returns the page at the given index. A page here means an instance of the class inheriting from the Pagination base class.

for_state(state: onegov.notice.models.NoticeState) typing_extensions.Self[source]

Returns a new instance of the collection with the given state.

for_term(term: str | None) typing_extensions.Self[source]

Returns a new instance of the collection with the given term.

for_order(order: str, direction: Literal['asc', 'desc'] | None = None) typing_extensions.Self[source]

Returns a new instance of the collection with the given ordering. Inverts the direction if the new ordering is the same as the old one and an explicit ordering is not defined.

for_organizations(organizations: Collection[str] | None) typing_extensions.Self[source]

Returns a new instance of the collection with the given organizations.

for_categories(categories: Collection[str] | None) typing_extensions.Self[source]

Returns a new instance of the collection with the given categories.

property model_class: type[_N][source]
property term_columns: list[_StrColumnLike][source]

The columns used for full text search.

filter_query(query: Query[_N]) Query[_N][source]

Filters the given query by the state of the collection.

order_query(query: Query[_N]) Query[_N][source]

Orders the given query by the state of the collection.

query() Query[_N][source]

Returns a filtered and sorted query.

Filters by: - notice.state matches state - notice.user_id is in user_ids - notice.group_id is in group_ids - notice.issues has any of the issues - term is in title, text, category, organization, groupname, usernames

Orders by: - any notice columns - group name (group.name) - users real name (user.realname) - username (user.username) - username or users real name (user.name)

_get_unique_name(name: str) str[source]

Create a unique, URL-friendly name.

add(title: str, text: str | None, **optional: Any) _N[source]

Add a new notice.

A unique, URL-friendly name is created automatically for this notice using the title and optionally numbers for duplicate names.

Returns the created notice.

delete(notice: onegov.notice.models.OfficialNotice) None[source]

Delete an notice.

by_name(name: str) _N | None[source]

Returns a notice by its URL-friendly name.

by_id(id: uuid.UUID) _N | None[source]

Returns a notice by its id.