diff --git a/indigo_app/forms/works.py b/indigo_app/forms/works.py index b7227ea3a..f62870022 100644 --- a/indigo_app/forms/works.py +++ b/indigo_app/forms/works.py @@ -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')) ]) @@ -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': @@ -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)