Skip to content

Commit

Permalink
Remove cantons filter (SEA-1472, SEA-1449).
Browse files Browse the repository at this point in the history
It filtered only the consultations, but not other entities,
— a subtlety which might be confusing to users.
  • Loading branch information
cyrillkuettel committed Aug 21, 2024
1 parent 4f31b5b commit cca5153
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
10 changes: 1 addition & 9 deletions src/privatim/forms/filter_form.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from wtforms import SelectField, DateField

from privatim.forms.constants import cantons_named
from wtforms import DateField
from privatim.forms.core import Form
from wtforms.validators import Optional

Expand All @@ -23,12 +21,6 @@ def __init__(
session = request.dbsession
super().__init__(request.POST, meta={'dbsession': session})

canton: SelectField = SelectField(
_('Canton'),
choices=[('all', _('all'))] + cantons_named,
validators=[Optional()],
)

consultation: CheckboxField = CheckboxField(
_('Consultation'),
)
Expand Down
7 changes: 0 additions & 7 deletions src/privatim/views/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ def activities_view(request: 'IRequest') -> 'RenderDataOrRedirect':
if request.GET.get('end_date')
else None
)
form.canton.data = request.GET.get('canton', 'all')
else:
# Default GET response, show everything, no filter.
form.consultation.data = True
Expand All @@ -120,7 +119,6 @@ def activities_view(request: 'IRequest') -> 'RenderDataOrRedirect':
'end_date': (
form.end_date.data.isoformat() if form.end_date.data else ''
),
'canton': form.canton.data,
}
return HTTPFound(
location=request.route_url('activities', _query=query_params)
Expand All @@ -131,7 +129,6 @@ def activities_view(request: 'IRequest') -> 'RenderDataOrRedirect':
include_comments = form.comment.data
start_date = form.start_date.data
end_date = form.end_date.data
canton = form.canton.data

start_datetime = (
datetime.combine(start_date, time.min, tzinfo=ZoneInfo("UTC"))
Expand All @@ -157,10 +154,6 @@ def activities_view(request: 'IRequest') -> 'RenderDataOrRedirect':
end_datetime,
Consultation.updated,
)
if canton != 'all':
consultation_query = consultation_query.filter(
Consultation.secondary_tags.any(canton)
)
activities.extend(
session.execute(consultation_query).unique().scalars().all()
)
Expand Down
35 changes: 31 additions & 4 deletions tests/views/client/test_views_homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
def test_filter(client):
session = client.db
client.login_admin()
# Add a meeting and a consultation
cons = create_consultation(tags=['ZH'])
session.add(cons)

meeting = create_meeting()
session.add(meeting)
session.commit()

# test the filter by tags (cantons)
# this one has no tags, should not appear in filter
cons = Consultation(
title='2nd Consultation',
creator=client.user
Expand All @@ -24,11 +23,10 @@ def test_filter(client):

page = client.get('/activities')
form = page.forms['filter_activities']
form['canton'] = 'ZH'
form['consultation'] = True
form['meeting'] = False
form['comment'] = False
page = form.submit().follow()
form.submit().follow()

page = client.get('/activities')

Expand All @@ -43,6 +41,35 @@ def test_filter(client):
page = client.get('/activities')
assert 'Powerpoint Parade' in page

# Test comment filter

page = client.get(f'/consultation/{cons.id}')
page.form['content'] = 'What an interesting thought'
page.form.submit()
page = client.get('/activities')
assert 'What an interesting thought' in page

form['consultation'] = True
form['meeting'] = True
form['comment'] = False
page = form.submit().follow()
assert 'What an interesting thought' not in page
assert 'Test Consultation' in page
assert '2nd Consultation' in page
assert 'Powerpoint Parade' in page

# Test all filters enabled
page = client.get('/activities')
form = page.forms['filter_activities']
form['consultation'] = True
form['meeting'] = True
form['comment'] = True
page = form.submit().follow()
assert 'What an interesting thought' in page
assert 'Test Consultation' in page
assert '2nd Consultation' in page
assert 'Powerpoint Parade' in page


def test_translation_navbar(client):
client.login_admin()
Expand Down

0 comments on commit cca5153

Please sign in to comment.