Skip to content

Commit

Permalink
fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
Tschuppi81 committed Jul 5, 2024
1 parent 770970a commit 57d7450
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/onegov/org/views/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_items(self) -> list[Person]:
orgs = (PersonCollection(request.session)
.unique_organisations())
sub_orgs = (PersonCollection(request.session)
.unique_sub_organisations(selected_org))
.unique_sub_organisations(str(selected_org)))

return {
'title': _("People"),
Expand Down
23 changes: 12 additions & 11 deletions src/onegov/people/collections/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from onegov.core.collection import GenericCollection
from onegov.people.models import Person


from typing import Any
from typing import TypeVar
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from uuid import UUID

Expand All @@ -19,12 +19,11 @@ def model_class(self) -> type[PersonT]:
raise NotImplementedError()

def add( # type:ignore[override]
self,
first_name: str,
last_name: str,
**optional: Any
self,
first_name: str,
last_name: str,
**optional: Any
) -> PersonT:

person = self.model_class(
first_name=first_name,
last_name=last_name,
Expand Down Expand Up @@ -56,17 +55,19 @@ class PersonCollection(BasePersonCollection[Person]):
def model_class(self) -> type[Person]:
return Person

def unique_organisations(self) -> tuple[str]:
def unique_organisations(self) -> tuple[str | None, ...]:
query = self.session.query(Person.organisation)
query = query.filter(Person.organisation.isnot(None)).distinct()
query = query.order_by(Person.organisation)
return tuple(p.organisation for p in query if p.organisation != '')
return tuple(org[0] for org in query if org[0] != '')

def unique_sub_organisations(self, of_org=None) -> tuple[str]:
def unique_sub_organisations(
self,
of_org: str | None = None
) -> tuple[str | None, ...]:
query = self.session.query(Person.sub_organisation)
if of_org:
query = query.filter(Person.organisation == of_org)
query = query.filter(Person.sub_organisation.isnot(None)).distinct()
query = query.order_by(Person.sub_organisation)
return tuple(p.sub_organisation
for p in query if p.sub_organisation != '')
return tuple(s_org[0] for s_org in query if s_org[0] != '')

0 comments on commit 57d7450

Please sign in to comment.