Skip to content

Commit

Permalink
Proposition: show department and area as badges
Browse files Browse the repository at this point in the history
Department and area are displayed as badges now, like special kinds of tags.

Clicking on a department filters by department and clicking on the area
filters by department and subject area (area is always bound to a
department).

Clicking on a tag now behaves differently: it also filters by department
and subject area as this will be the most common use case: see other
propositions about the same topic, in the same subject area.
Searching for topics globally is generally less helpful but still possible by
removing the department filter with another click.
  • Loading branch information
dpausp committed Jun 24, 2022
1 parent d43c849 commit 76f2bce
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 23 deletions.
21 changes: 18 additions & 3 deletions src/ekklesia_portal/concepts/proposition/proposition_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class PropositionCell(LayoutCell):
secret_voting = Cell.template_fragment('proposition_secret_voting')
support = Cell.template_fragment('proposition_support')
toolbar = Cell.fragment('proposition_toolbar')
tag_list = Cell.fragment('proposition_tag_list')
badges = Cell.fragment('proposition_badges')
small = Cell.fragment('proposition_small')
card = Cell.fragment('proposition_card')

Expand Down Expand Up @@ -103,6 +103,12 @@ def detail_top(self):
template = f"proposition/detail_top/proposition_detail_top_{variant}.j2.jade"
return self.render_template(template)

def department_name(self):
return self._model.ballot.area.department.name

def subject_area_name(self):
return self._model.ballot.area.name

def associated_url(self):
return self.link(self._model, 'associated')

Expand Down Expand Up @@ -161,8 +167,16 @@ def ballot_title(self):
def discussion_url(self):
return self.link(self._model)

def propositions_tag_url(self, tag):
return self.class_link(Propositions, dict(tags=tag.name))
def propositions_badge_url(self, department_name, subject_area_name=None, tag_name=None):
params = {"department": department_name}

if subject_area_name:
params["subject_area"] = subject_area_name

if tag_name:
params["tags"] = tag_name

return self.class_link(Propositions, params)

def current_user_is_supporter(self):
if self.current_user is None:
Expand Down Expand Up @@ -271,6 +285,7 @@ def show_goto_arguments(self):
)

def show_create_associated_proposition(self):
return True
return self._model.status in (
PropositionStatus.DRAFT, PropositionStatus.SUBMITTED, PropositionStatus.QUALIFIED,
PropositionStatus.SCHEDULED
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ul
li
a.department(
href = propositions_badge_url(department_name)
title = _("department")
)= department_name

li
a.area(
href = propositions_badge_url(department_name, subject_area_name)
title = _("subject_area")
)= subject_area_name

for tag in tags
li
a.tag(
href = propositions_badge_url(
department_name, subject_area_name, tag.name
)
title = _("tag")
)= tag.name


// generated from jade
//- vim: set filetype=jade sw=2 ts=2 sts=2 expandtab:
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
= status()

.proposition_body
= tag_list()

.proposition_badges
= badges()

h4.proposition_title
a(href=self_link)= full_title
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion src/ekklesia_portal/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class Ballot(Base): # conflicting qualified propositions
proposition_type: PropositionType = relationship("PropositionType", back_populates="ballots")

area_id: int = C(Integer, ForeignKey('subjectareas.id'))
area = relationship("SubjectArea", back_populates="ballots") # contains department
area: SubjectArea = relationship("SubjectArea", back_populates="ballots") # contains department

# optional, if assigned, set proposition to planned
voting_id: int = C(Integer, ForeignKey('votingphases.id'))
Expand Down
25 changes: 21 additions & 4 deletions src/ekklesia_portal/sass/portal.sass
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,27 @@ ul.proposition_filter
hr.argument_separator
border-top: 2px solid $light

span.tag_text
@extend .badge
@extend .badge-secondary
margin-left: 0.5rem
.proposition_badges
ul
@extend .list-inline

li
@extend .list-inline-item

.badge
padding: 0.4em 0.6em

.department
@extend .badge-primary
@extend .badge

.area
@extend .badge-secondary
@extend .badge

.tag
@extend .badge-light
@extend .badge

.top_navbar
@extend .navbar
Expand Down
10 changes: 8 additions & 2 deletions src/ekklesia_portal/translations/de/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-06-02 16:13+0000\n"
"POT-Creation-Date: 2022-06-24 02:11+0200\n"
"PO-Revision-Date: 2015-09-06 22:42+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: de\n"
Expand Down Expand Up @@ -106,6 +106,7 @@ msgstr "Ergebnis"
#: src/ekklesia_portal/concepts/document/document_contracts.py:11
#: src/ekklesia_portal/concepts/proposition/proposition_contracts.py:34
#: src/ekklesia_portal/concepts/proposition/templates/edit_proposition.j2.jade:7
#: src/ekklesia_portal/concepts/proposition/templates/proposition_badges.j2.jade:4
#: src/ekklesia_portal/concepts/proposition/templates/proposition_submit_draft.j2.jade:15
#: src/ekklesia_portal/concepts/subject_area/templates/subject_area.j2.jade:3
#: src/ekklesia_portal/concepts/subject_area/templates/subject_area.j2.jade:5
Expand Down Expand Up @@ -188,6 +189,7 @@ msgstr "Anzahl der Anträge"
#: src/ekklesia_portal/concepts/department/templates/department.j2.jade:3
#: src/ekklesia_portal/concepts/department/templates/department.j2.jade:5
#: src/ekklesia_portal/concepts/proposition/templates/edit_proposition.j2.jade:5
#: src/ekklesia_portal/concepts/proposition/templates/proposition_badges.j2.jade:2
#: src/ekklesia_portal/concepts/proposition/templates/proposition_submit_draft.j2.jade:13
#: src/ekklesia_portal/concepts/subject_area/subject_area_contracts.py:10
#: src/ekklesia_portal/concepts/voting_phase/voting_phase_contracts.py:15
Expand Down Expand Up @@ -770,7 +772,11 @@ msgstr "Melden"
msgid "note_button"
msgstr "Notizen"

#: src/ekklesia_portal/concepts/proposition/templates/proposition_card.j2.jade:10
#: src/ekklesia_portal/concepts/proposition/templates/proposition_badges.j2.jade:8
msgid "tag"
msgstr "Schlagwort (Tag)"

#: src/ekklesia_portal/concepts/proposition/templates/proposition_card.j2.jade:12
msgid "title_motivation"
msgstr "Begründung"

Expand Down
11 changes: 9 additions & 2 deletions src/ekklesia_portal/translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-06-02 16:13+0000\n"
"POT-Creation-Date: 2022-06-24 02:11+0200\n"
"PO-Revision-Date: 2015-09-06 22:42+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en\n"
Expand Down Expand Up @@ -106,6 +106,7 @@ msgstr "result"
#: src/ekklesia_portal/concepts/document/document_contracts.py:11
#: src/ekklesia_portal/concepts/proposition/proposition_contracts.py:34
#: src/ekklesia_portal/concepts/proposition/templates/edit_proposition.j2.jade:7
#: src/ekklesia_portal/concepts/proposition/templates/proposition_badges.j2.jade:4
#: src/ekklesia_portal/concepts/proposition/templates/proposition_submit_draft.j2.jade:15
#: src/ekklesia_portal/concepts/subject_area/templates/subject_area.j2.jade:3
#: src/ekklesia_portal/concepts/subject_area/templates/subject_area.j2.jade:5
Expand Down Expand Up @@ -188,6 +189,7 @@ msgstr "Number of propositions"
#: src/ekklesia_portal/concepts/department/templates/department.j2.jade:3
#: src/ekklesia_portal/concepts/department/templates/department.j2.jade:5
#: src/ekklesia_portal/concepts/proposition/templates/edit_proposition.j2.jade:5
#: src/ekklesia_portal/concepts/proposition/templates/proposition_badges.j2.jade:2
#: src/ekklesia_portal/concepts/proposition/templates/proposition_submit_draft.j2.jade:13
#: src/ekklesia_portal/concepts/subject_area/subject_area_contracts.py:10
#: src/ekklesia_portal/concepts/voting_phase/voting_phase_contracts.py:15
Expand Down Expand Up @@ -769,7 +771,12 @@ msgstr "Report"
msgid "note_button"
msgstr "Notes"

#: src/ekklesia_portal/concepts/proposition/templates/proposition_card.j2.jade:10
#: src/ekklesia_portal/concepts/proposition/templates/proposition_badges.j2.jade:8
#, fuzzy
msgid "tag"
msgstr "Tags"

#: src/ekklesia_portal/concepts/proposition/templates/proposition_card.j2.jade:12
msgid "title_motivation"
msgstr "Motivation"

Expand Down
17 changes: 15 additions & 2 deletions tests/concepts/proposition/test_propositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from assert_helpers import assert_difference, assert_no_difference
from ekklesia_portal.datamodel import Changeset, Proposition, SecretVoter, Supporter, Tag
from webtest_helpers import assert_deform
from bs4 import BeautifulSoup


def test_index(client):
Expand Down Expand Up @@ -121,15 +122,27 @@ def test_index_export_csv_as_global_admin(client, logged_in_global_admin):
assert "\"PP002\";\"egon\";" in res


def assert_proposition_in_html(proposition, html):
proposition_link = html.find(class_="proposition_title").find("a")
def assert_proposition_in_html(proposition: Proposition, html: BeautifulSoup):
proposition_el = html.find(id=f"proposition_{proposition.id}")
proposition_link = proposition_el.find(class_="proposition_title").find("a")
assert proposition_link.text == proposition.title
assert str(proposition.id) in proposition_link["href"]
proposition_details_text = html.find(class_="proposition_details").text
assert proposition.content in proposition_details_text
assert "Motivation" in proposition_details_text
assert proposition.motivation in proposition_details_text

badges = proposition_el.find(class_="proposition_badges")
assert badges, "badges not found"
department_badge = badges.find(class_="department")
assert department_badge, "department link not found"
assert department_badge.text == proposition.ballot.area.department.name, "department name doesn't match"
area_badge = badges.find(class_="area")
assert area_badge, "area link not found"
assert area_badge.text == proposition.ballot.area.name, "area name doesn't match"
tag_badges = badges.find_all(class_="tag")
assert {t.name for t in proposition.tags} == {b.text for b in tag_badges}, "tag names don't match"


def test_show(client, proposition):
res = client.get(f"/p/{proposition.id}/{proposition_slug(proposition)}")
Expand Down

0 comments on commit 76f2bce

Please sign in to comment.