Skip to content

Commit

Permalink
People: Adds filtering for organizations or sub organizations
Browse files Browse the repository at this point in the history
TYPE: Feature
LINK: ogc-1695
  • Loading branch information
Tschuppi81 committed Jul 5, 2024
1 parent b7b0624 commit 238d714
Show file tree
Hide file tree
Showing 16 changed files with 373 additions and 13 deletions.
15 changes: 15 additions & 0 deletions src/onegov/agency/theme/styles/agency.scss
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,18 @@ ul.agency-nav {
text-overflow: clip;
white-space: normal;
}


/*
Agency Form
*/

// hide the organisation field
.row.field-organisation {
display: none;
}

// hide the sub organisation field
.row.field-sub_organisation {
display: none;
}
2 changes: 2 additions & 0 deletions src/onegov/org/forms/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class PersonForm(Form):
last_name = StringField(_("Last name"), [InputRequired()])

function = StringField(_("Function"))
organisation = StringField(_("Organisation"))
sub_organisation = StringField(_("Sub organisation"))

email = EmailField(_("E-Mail"))
phone = StringField(_("Phone"))
Expand Down
15 changes: 15 additions & 0 deletions src/onegov/org/locale/de_CH/LC_MESSAGES/onegov.org.po
Original file line number Diff line number Diff line change
Expand Up @@ -4127,6 +4127,9 @@ msgstr "Referenz Anfrage"
msgid "No people added yet."
msgstr "Es wurden noch keine Personen hinzugefügt."

msgid "No people found for current filter selection."
msgstr "Keine Personen für aktuelle Filterauswahl gefunden."

msgid "Export a vCard of this person"
msgstr "Elektronische Visitenkarte (vCard)"

Expand Down Expand Up @@ -5792,6 +5795,18 @@ msgstr "Ein Konto wurde für Sie erstellt"
msgid "The user was created successfully"
msgstr "Der Benutzer wurde erfolgreich erstellt"

msgid "Organisation"
msgstr "Organisation"

msgid "Sub organisation"
msgstr "Unterorganisation"

msgid "Select organisation"
msgstr "Organisation wählen"

msgid "Select sub organisation"
msgstr "Unterorganisation wählen"

#~ msgid "A new entry has been added to the \"${directory.title}\" directory:"
#~ msgstr ""
#~ "Ein neuer Eintrag wurde im Verzeichnis \"${directory.title}\" hinzugefügt:"
Expand Down
15 changes: 15 additions & 0 deletions src/onegov/org/locale/fr_CH/LC_MESSAGES/onegov.org.po
Original file line number Diff line number Diff line change
Expand Up @@ -4139,6 +4139,9 @@ msgstr "Référence"
msgid "No people added yet."
msgstr "Aucune personne n'a encore été ajoutée."

msgid "No people found for current filter selection."
msgstr "Aucune personne n'a été trouvée pour la sélection de filtre actuelle."

msgid "Export a vCard of this person"
msgstr "Exporter une vCard de cette personne"

Expand Down Expand Up @@ -5816,6 +5819,18 @@ msgstr "Un compte a été créé pour vous"
msgid "The user was created successfully"
msgstr "L'utilisateur a bien été créé"

msgid "Organisation"
msgstr "Organisation"

msgid "Sub organisation"
msgstr "Sous-organisation"

msgid "Select organisation"
msgstr "Sélectionner une organisation"

msgid "Select sub organisation"
msgstr "Sélectionner une sous-organisation"

#~ msgid "A new entry has been added to the \"${directory.title}\" directory:"
#~ msgstr ""
#~ "Une nouvelle entrée a été ajoutée au répertoire « ${directory.title} » :"
Expand Down
15 changes: 15 additions & 0 deletions src/onegov/org/locale/it_CH/LC_MESSAGES/onegov.org.po
Original file line number Diff line number Diff line change
Expand Up @@ -4129,6 +4129,9 @@ msgstr "Riferimento della richiesta"
msgid "No people added yet."
msgstr "Nessuna persona aggiunta ancora."

msgid "No people found for current filter selection."
msgstr "Non sono state trovate persone per la selezione del filtro corrente."

msgid "Export a vCard of this person"
msgstr "Esporta una vCard di questa persona"

Expand Down Expand Up @@ -5807,6 +5810,18 @@ msgstr "È stato creato un account per te"
msgid "The user was created successfully"
msgstr "Utente creato correttamente"

msgid "Organisation"
msgstr "Organizzazione"

msgid "Sub organisation"
msgstr "Sotto organizzazione"

msgid "Select organisation"
msgstr "Selezionare l'organizzazione"

msgid "Select sub organisation"
msgstr "Selezionare la sotto-organizzazione"

#~ msgid "A new entry has been added to the \"${directory.title}\" directory:"
#~ msgstr ""
#~ "Un nuovo elemento è stato aggiunto alla cartella \"${directory.title}\":"
Expand Down
8 changes: 8 additions & 0 deletions src/onegov/org/templates/macros.pt
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,10 @@
<li tal:condition="person.function" class="person-card-function">
<em>${person.function}</em>
</li>
<li tal:condition="person.organisation" class="person-card-organisation">
<span i18n:attributes="title" title="Organisation">${person.organisation}</span>
<span i18n:attributes="title" title="Sub organisation">${person.sub_organisation}</span>
</li>
<li tal:condition="person.email and 'email' not in exclude" class="person-card-email">
<a href="mailto:${person.email}">${person.email}</a>
</li>
Expand Down Expand Up @@ -775,6 +779,10 @@
<li tal:condition="person.function" class="person-card-function">
<em>${person.function}</em>
</li>
<li tal:condition="person.organisation and 'organisation' not in exclude" class="person-card-organisation">
<span i18n:attributes="title" title="Organisation">${person.organisation}</span>
<span i18n:attributes="title" title="Sub organisation" tal:condition="person.sub_organisation and 'sub_organisation' not in exclude">${person.sub_organisation}</span>
</li>
<li class="person-card-personal">
<span tal:condition="person.born and 'born' not in exclude">${person.born}</span>
<span tal:condition="person.academic_title and 'academic_title' not in exclude">${person.academic_title}</span>
Expand Down
18 changes: 17 additions & 1 deletion src/onegov/org/templates/people.pt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@
${title}
</tal:b>
<tal:b metal:fill-slot="content">
<p tal:condition="not:people" i18n:translate="">No people added yet.</p>
<p tal:condition="not:count" i18n:translate="">No people added yet.</p>
<p tal:condition="not:people" i18n:translate="">No people found for current filter selection.</p>

<form method="get" style="max-width: 40%">
<select name="organisation" i18n:attributes="title" title="Select organisation" onchange="this.form.submit()">
<option value="" i18n:translate="">Select organisation</option>
<tal:block tal:repeat="org organisations">
<option tal:attributes="value org; selected python:org == selected_organisation">${org}</option>
</tal:block>
</select>
<select name="sub_organisation" i18n:attributes="title" title="Select sub organisation" onchange="this.form.submit()">
<option value="" i18n:translate="">Select sub organisation</option>
<tal:block tal:repeat="sub_org sub_organisations">
<option tal:attributes="value sub_org; selected python:sub_org == selected_sub_organisation">${sub_org}</option>
</tal:block>
</select>
</form>

<div tal:condition="people" class="people-list">
<div metal:use-macro="layout.macros['atoz']" tal:define="items people">
Expand Down
8 changes: 8 additions & 0 deletions src/onegov/org/theme/styles/org.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2450,6 +2450,14 @@ $person-email-icon: '\f003';
margin-bottom: 1em;
}

.person-card-organisation {
margin-bottom: 1em;

span:not(:last-child)::after {
content: ' -';
}
}

.person-card-personal {
margin-bottom: 1em;

Expand Down
14 changes: 12 additions & 2 deletions src/onegov/org/views/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ def view_people(
layout: PersonCollectionLayout | None = None
) -> 'RenderData':

people = self.query().order_by(Person.last_name, Person.first_name).all()
selected_org = str(request.params.get('organisation', ''))
selected_sub_org = str(request.params.get('sub_organisation', ''))

people = self.people_by_organisation(selected_org, selected_sub_org)
orgs = self.unique_organisations()
sub_orgs = self.unique_sub_organisations(selected_org)

class AtoZPeople(AtoZ[Person]):

Expand All @@ -38,8 +43,13 @@ def get_items(self) -> list[Person]:

return {
'title': _("People"),
'count': len(people),
'people': AtoZPeople(request).get_items_by_letter().items(),
'layout': layout or PersonCollectionLayout(self, request)
'layout': layout or PersonCollectionLayout(self, request),
'organisations': orgs,
'sub_organisations': sub_orgs,
'selected_organisation': selected_org,
'selected_sub_organisation': selected_sub_org
}


Expand Down
38 changes: 36 additions & 2 deletions src/onegov/people/collections/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
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
Expand All @@ -24,7 +23,6 @@ def add( # type:ignore[override]
last_name: str,
**optional: Any
) -> PersonT:

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

def people_by_organisation(
self,
org: str | None,
sub_org: str | None
) -> list[Person]:
"""
Returns all persons of a given organisation and sub-organisation.
If organisation and sub-organisation are both None, all persons are
returned.
"""
query = self.session.query(Person).order_by(Person.last_name,
Person.first_name)
if org:
query = query.filter(Person.organisation == org)
if sub_org:
query = query.filter(Person.sub_organisation == sub_org)
return query.all()

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(org[0] for org in query if org[0] != '')

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(s_org[0] for s_org in query if s_org[0] != '')
6 changes: 6 additions & 0 deletions src/onegov/people/models/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ def spoken_title(self) -> str:
#: the function of the person
function: 'Column[str | None]' = Column(Text, nullable=True)

#: an organisation the person belongs to
organisation: 'Column[str | None]' = Column(Text, nullable=True)

# a sub organisation the person belongs to
sub_organisation: 'Column[str | None]' = Column(Text, nullable=True)

#: the political party the person belongs to
political_party: 'Column[str | None]' = Column(Text, nullable=True)

Expand Down
12 changes: 12 additions & 0 deletions src/onegov/people/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,15 @@ def extend_agency_and_person_with_more_fields(context: UpgradeContext) -> None:
Column(column, Text, nullable=True),
default=lambda x: ''
)


@upgrade_task('Add organisation columns to people')
def add_organisation_columns_to_people(context: UpgradeContext) -> None:
if not context.has_column('people', 'organisation'):
context.operations.add_column('people', Column(
'organisation', Text, nullable=True
))
if not context.has_column('people', 'sub_organisation'):
context.operations.add_column('people', Column(
'sub_organisation', Text, nullable=True
))
8 changes: 8 additions & 0 deletions src/onegov/town6/templates/macros.pt
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,10 @@
<li tal:condition="person.function" class="person-card-function">
<span title="${person.function}">${person.function}</span>
</li>
<li tal:condition="person.organisation" class="person-card-organisation">
<span i18n:attributes="title" title="Organisation">${person.organisation}</span>
<span i18n:attributes="title" title="Sub organisation">${person.sub_organisation}</span>
</li>
<li tal:condition="person.email and 'email' not in exclude" class="person-card-email">
<a href="mailto:${person.email}">${person.email}</a>
</li>
Expand All @@ -995,6 +999,10 @@
<li tal:condition="person.function" class="person-card-function">
<em>${person.function}</em>
</li>
<li tal:condition="person.organisation and 'organisation' not in exclude" class="person-card-organisation">
<span i18n:attributes="title" title="Organisation">${person.organisation}</span>
<span i18n:attributes="title" title="Sub organisation" tal:condition="person.sub_organisation and 'sub_organisation' not in exclude">${person.sub_organisation}</span>
</li>
<li class="person-card-personal">
<span tal:condition="person.born and 'born' not in exclude">${person.born}</span>
<span tal:condition="person.academic_title and 'academic_title' not in exclude">${person.academic_title}</span>
Expand Down
18 changes: 17 additions & 1 deletion src/onegov/town6/templates/people.pt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@
${title}
</tal:b>
<tal:b metal:fill-slot="content">
<p tal:condition="not:people" i18n:translate="">No people added yet.</p>
<p tal:condition="not:count" i18n:translate="">No people added yet.</p>
<p tal:condition="not:people" i18n:translate="">No people found for current filter selection.</p>

<form method="get" style="max-width: 40%">
<select name="organisation" i18n:attributes="title" title="Select organisation" onchange="this.form.submit()">
<option value="" i18n:translate="">Select organisation</option>
<tal:block tal:repeat="org organisations">
<option tal:attributes="value org; selected python:org == selected_organisation">${org}</option>
</tal:block>
</select>
<select name="sub_organisation" i18n:attributes="title" title="Select sub organisation" onchange="this.form.submit()">
<option value="" i18n:translate="">Select sub organisation</option>
<tal:block tal:repeat="sub_org sub_organisations">
<option tal:attributes="value sub_org; selected python:sub_org == selected_sub_organisation">${sub_org}</option>
</tal:block>
</select>
</form>

<div tal:condition="people" class="people-list">
<div metal:use-macro="layout.macros['atoz']" tal:define="items people">
Expand Down
11 changes: 11 additions & 0 deletions src/onegov/town6/theme/styles/person.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ $person-email-icon: '\f0e0';
margin-bottom: 1em;
}

.person-card-organisation {
margin-bottom: 1em;

span:not(:last-child)::after {
content: ' -';
}
}

.person-card-personal {
margin-bottom: 1em;

Expand All @@ -63,6 +71,9 @@ $person-email-icon: '\f0e0';
span {
white-space: pre-line;
}
span:not(:last-child)::after {
content: ',';
}
}

.person-card-notes {
Expand Down
Loading

0 comments on commit 238d714

Please sign in to comment.