Skip to content

Commit

Permalink
Fixed admin reservation metadata empty set issue (#278)
Browse files Browse the repository at this point in the history
Changes:
- set supported and required fields to not be required
- fixed empty field sets causing an error
  • Loading branch information
SanttuA authored Aug 23, 2023
1 parent 4ea48e9 commit e030a41
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions resources/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,17 +380,21 @@ class TermsOfUseAdmin(PopulateCreatedAndModifiedMixin, CommonExcludeMixin, Trans

class ReservationMetadataSetForm(forms.ModelForm):
supported_fields = forms.ModelMultipleChoiceField(
ReservationMetadataField.objects.all(), widget=FilteredSelectMultiple(_('Supported fields'), False))
ReservationMetadataField.objects.all(),
widget=FilteredSelectMultiple(_('Supported fields'), False),
required=False)
required_fields = forms.ModelMultipleChoiceField(
ReservationMetadataField.objects.all(), widget=FilteredSelectMultiple(_('Required fields'), False))
ReservationMetadataField.objects.all(),
widget=FilteredSelectMultiple(_('Required fields'), False),
required=False)

class Meta:
model = ReservationMetadataSet
exclude = CommonExcludeMixin.exclude + ('id',)

def clean(self):
supported = set(self.cleaned_data.get('supported_fields'))
required = set(self.cleaned_data.get('required_fields'))
supported = set(self.cleaned_data.get('supported_fields', []))
required = set(self.cleaned_data.get('required_fields', []))
if not required.issubset(supported):
raise ValidationError(_('Required fields must be a subset of supported fields'))
return self.cleaned_data
Expand Down

0 comments on commit e030a41

Please sign in to comment.