Skip to content

Commit

Permalink
Merge pull request #2237 from laws-africa/work-facets-sortby
Browse files Browse the repository at this point in the history
don't add second round of negations for sortby on the WorkFilterForm
  • Loading branch information
goose-life authored Sep 16, 2024
2 parents f4fddbe + 789ee48 commit 2db15c7
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions indigo_app/forms/works.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,13 +826,8 @@ class WorkFilterForm(forms.Form, FormAsUrlMixin):
status = forms.MultipleChoiceField(label=_("Point in time status"), choices=[
('published', _('Published')), ('draft', _('Draft'))
])
sortby = forms.ChoiceField(choices=[
('-created_at', _('Created at (newest first)')), ('created_at', _('Created at (oldest first)')),
('-updated_at', _('Updated at (newest first)')), ('updated_at', _('Updated at (oldest first)')),
('title', _('Title (A-Z)')), ('-title', _('Title (Z-A)')),
('date', _('Date (oldest first)')), ('-date', _('Date (newest first)')),
('number', _('Number (ascending)')), ('-number', _('Number (descending)')),
])
# add the choices separately as we manually include the opposite of each option
sortby = forms.ChoiceField()
principal = forms.MultipleChoiceField(label=_("Principal"), required=False, choices=[
('principal', _('Principal')), ('not_principal', _('Not Principal'))
])
Expand Down Expand Up @@ -872,6 +867,8 @@ def __init__(self, country, *args, **kwargs):
]
# ensure all choice fields have negated choices
self.add_negated_choices()
# add these choices after adding negations, as we manually include the opposite of each option
self.add_sortby_choices()

def add_subtypes(self):
if not self.country or self.country.code == 'all':
Expand All @@ -885,6 +882,15 @@ def add_subtypes(self):
self.fields['subtype'].choices = doctypes + subtypes
self.subtypes = Subtype.objects.all()

def add_sortby_choices(self):
self.fields['sortby'].choices = [
('-created_at', _('Created at (newest first)')), ('created_at', _('Created at (oldest first)')),
('-updated_at', _('Updated at (newest first)')), ('updated_at', _('Updated at (oldest first)')),
('-date', _('Date (newest first)')), ('date', _('Date (oldest first)')),
('title', _('Title (A-Z)')), ('-title', _('Title (Z-A)')),
('number', _('Number (ascending)')), ('-number', _('Number (descending)')),
]

def add_negated_choices(self):
for fld in self.fields.values():
choices = getattr(fld, 'choices', None)
Expand Down

0 comments on commit 2db15c7

Please sign in to comment.