Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

budgeting//contrib/filters: add random ordering to ProposalFilterSet … #4582

Merged
merged 2 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions meinberlin/apps/budgeting/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ def list(self, request, *args, **kwargs):
if has_feature_active(self.module, Proposal, 'support'):
ordering_choices += ('-positive_rating_count', _('Most support')),
ordering_choices += ('-comment_count', _('Most commented')), \
('-daily_random', _('Random')),
('dailyrandom', _('Random')),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 It doesn't matter if it's ascending or descending random. 🤣


filters['ordering'] = {
'label': _('Ordering'),
'choices': ordering_choices,
'default': '-daily_random',
'default': 'dailyrandom',
}

response = super().list(request, args, kwargs)
Expand Down Expand Up @@ -171,7 +171,7 @@ class ProposalViewSet(ModuleMixin,
ordering_fields = ('created',
'comment_count',
'positive_rating_count',
'daily_random',)
'dailyrandom',)
search_fields = ('name', 'ref_number')

def get_permission_object(self):
Expand Down
5 changes: 3 additions & 2 deletions meinberlin/apps/budgeting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def get_ordering_choices(view):
choices = (('-created', _('Most recent')),)
if view.module.has_feature('rate', models.Proposal):
choices += ('-positive_rating_count', _('Most popular')),
choices += ('-comment_count', _('Most commented')),
choices += ('-comment_count', _('Most commented')), \
('dailyrandom', _('Random')),
return choices


Expand All @@ -31,7 +32,7 @@ class ProposalFilterSet(a4_filters.DefaultsFilterSet):
}
category = category_filters.CategoryFilter()
labels = label_filters.LabelFilter()
ordering = a4_filters.DynamicChoicesOrderingFilter(
ordering = a4_filters.DistinctOrderingWithDailyRandomFilter(
choices=get_ordering_choices
)
is_archived = django_filters.BooleanFilter(
Expand Down
2 changes: 1 addition & 1 deletion meinberlin/apps/contrib/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def filter_queryset(self, request, queryset, view):
ordering = self.get_ordering(request, queryset, view)

if ordering:
if ordering == ['-daily_random']:
if ordering == ['dailyrandom']:
pks = list(queryset.values_list('pk', flat=True))
random.seed(str(date.today()))
random.shuffle(pks)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@fortawesome/fontawesome-free": "5.15.4",
"@maplibre/maplibre-gl-leaflet": "0.0.17",
"acorn": "8.8.0",
"adhocracy4": "liqd/adhocracy4#f70e903002cd9cb2ac1cbd3e2f4e697ce04703ba",
"adhocracy4": "liqd/adhocracy4#0fe27f18b7dc6bb5ace1cfd5801065bda92af0d1",
"autoprefixer": "10.4.12",
"babel-loader": "8.2.5",
"bootstrap": "5.2.2",
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# A4
git+https://github.com/liqd/adhocracy4.git@f70e903002cd9cb2ac1cbd3e2f4e697ce04703ba#egg=adhocracy4
git+https://github.com/liqd/adhocracy4.git@0fe27f18b7dc6bb5ace1cfd5801065bda92af0d1#egg=adhocracy4

# Additional requirements
bcrypt==4.0.1
Expand Down
8 changes: 4 additions & 4 deletions tests/budgeting/test_proposals_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def test_proposal_list_mixins(apiclient, phase_factory, proposal_factory,
[('-created', _('Most recent')),
('-positive_rating_count', _('Most popular')),
('-comment_count', _('Most commented')),
('-daily_random', _('Random'))]
assert response.data['filters']['ordering']['default'] == '-daily_random'
('dailyrandom', _('Random'))]
assert response.data['filters']['ordering']['default'] == 'dailyrandom'

# locale info
assert 'locale' in response.data
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_proposal_list_filtering(apiclient, module, proposal_factory,
assert response.data['results'][0]['pk'] == proposal_commented.pk

# daily random
querystring = '?ordering=-daily_random'
querystring = '?ordering=dailyrandom'
url_tmp = url + querystring
with freeze_time('2020-01-01 00:00:00 UTC'):
response = apiclient.get(url_tmp)
Expand Down Expand Up @@ -264,7 +264,7 @@ def test_proposal_list_filtering(apiclient, module, proposal_factory,
assert response.data['results'][0]['pk'] == proposal_popular_labels.pk
assert response.data['results'][1]['pk'] == proposal_archived_labels.pk

querystring = '?ordering=-daily_random&category=' + \
querystring = '?ordering=dailyrandom&category=' + \
str(category2.pk)
url_tmp = url + querystring
with freeze_time('2020-01-01 00:00:00 UTC'):
Expand Down