Skip to content

Commit

Permalink
use only a single formset
Browse files Browse the repository at this point in the history
  • Loading branch information
helrond committed Nov 16, 2024
1 parent 18949e7 commit 3d2c343
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions bag_transfer/bagit_profiles/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def __init__(self, *args, **kwargs):
self.legend_text = "Allowed algorithm(s) for manifest files *"
self.help_text_id = "manifests_allowed-help"
self.fields['name'].required = True
self.fields['name'].choices = [choice for choice in self.fields['name'].choices if choice[0]] # Exclude blank choice


class ManifestsRequiredForm(forms.ModelForm):
Expand All @@ -106,6 +107,7 @@ def __init__(self, *args, **kwargs):
self.legend_text = "Manifests Required"
self.help_text_id = "manifests_required-help"
self.fields['name'].required = True
self.fields['name'].choices = [choice for choice in self.fields['name'].choices if choice[0]] # Exclude blank choice


class AcceptSerializationForm(forms.ModelForm):
Expand Down Expand Up @@ -232,41 +234,39 @@ def save(self, commit=True):
BagItProfile,
ManifestsAllowed,
fields=("name",),
max_num=len(ManifestsAllowed.MANIFESTS_ALLOWED_CHOICES),
min_num=1,
validate_min=True,
max_num=1,
form=ManifestsAllowedForm,
)

ManifestsRequiredFormset = forms.inlineformset_factory(
BagItProfile,
ManifestsRequired,
fields=("name",),
max_num=len(ManifestsRequired.MANIFESTS_REQUIRED_CHOICES),
max_num=1,
form=ManifestsRequiredForm,
)

AcceptSerializationFormset = forms.inlineformset_factory(
BagItProfile,
AcceptSerialization,
fields=("name",),
max_num=len(AcceptSerialization.ACCEPT_SERIALIZATION_CHOICES),
max_num=1,
form=AcceptSerializationForm,
)

AcceptBagItVersionFormset = forms.inlineformset_factory(
BagItProfile,
AcceptBagItVersion,
fields=("name",),
max_num=len(AcceptBagItVersion.BAGIT_VERSION_NAME_CHOICES),
max_num=1,
form=AcceptBagItVersionForm,
)

TagManifestsRequiredFormset = forms.inlineformset_factory(
BagItProfile,
TagManifestsRequired,
fields=("name",),
max_num=len(TagManifestsRequired.TAG_MANIFESTS_REQUIRED_CHOICES),
max_num=1,
form=TagManifestsRequiredForm,
)

Expand Down

0 comments on commit 3d2c343

Please sign in to comment.