From bee26409ec2381644c807679861749ffcbc7fc75 Mon Sep 17 00:00:00 2001 From: ffont Date: Wed, 22 Nov 2023 15:20:55 +0100 Subject: [PATCH] Fix bug in sound edit form --- sounds/forms.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sounds/forms.py b/sounds/forms.py index 2f805b9df..71c00c721 100644 --- a/sounds/forms.py +++ b/sounds/forms.py @@ -306,13 +306,15 @@ def __init__(self, *args, **kwargs): # Prepare pack field if user_packs: user_packs = user_packs.extra(select={'lower_name': 'lower(name)'}).order_by('lower_name') - self.fields['pack'].choices = [(PackForm.NO_PACK_CHOICE_VALUE, '--- No pack ---'), - (PackForm.NEW_PACK_CHOICE_VALUE, 'Create a new pack...')] + \ - ([(pack.id, pack.name) for pack in user_packs] if user_packs else []) - # The attrs below are used so that some elements of the dropdown are displayed in gray and to enable - # pre-selecting options using keyboard - self.fields['pack'].widget.attrs = {'data-grey-items': f'{PackForm.NO_PACK_CHOICE_VALUE},{PackForm.NEW_PACK_CHOICE_VALUE}', - 'data-select-with-keyboard': True} + else: + user_packs = [] + self.fields['pack'].choices = [(PackForm.NO_PACK_CHOICE_VALUE, '--- No pack ---'), + (PackForm.NEW_PACK_CHOICE_VALUE, 'Create a new pack...')] + \ + ([(pack.id, pack.name) for pack in user_packs] if user_packs else []) + # The attrs below are used so that some elements of the dropdown are displayed in gray and to enable + # pre-selecting options using keyboard + self.fields['pack'].widget.attrs = {'data-grey-items': f'{PackForm.NO_PACK_CHOICE_VALUE},{PackForm.NEW_PACK_CHOICE_VALUE}', + 'data-select-with-keyboard': True} def clean(self): data = self.cleaned_data