Intitial teams support #147
@ -117,7 +117,6 @@ class ExtensionUpdateForm(forms.ModelForm):
|
|||||||
)
|
)
|
||||||
msg_need_previews = _('Please add at least one preview.')
|
msg_need_previews = _('Please add at least one preview.')
|
||||||
msg_duplicate_file = _('Please select another file instead of the duplicate.')
|
msg_duplicate_file = _('Please select another file instead of the duplicate.')
|
||||||
invalid_team_value = '-'
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = extensions.models.Extension
|
model = extensions.models.Extension
|
||||||
@ -129,7 +128,6 @@ class ExtensionUpdateForm(forms.ModelForm):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Pass the request and initialise all the nested form(set)s."""
|
"""Pass the request and initialise all the nested form(set)s."""
|
||||||
self.request = kwargs.pop('request')
|
self.request = kwargs.pop('request')
|
||||||
self.add_invalid_team_choice = kwargs.pop('add_invalid_team_choice', False)
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
if self.request.POST:
|
if self.request.POST:
|
||||||
edit_preview_formset = EditPreviewFormSet(
|
edit_preview_formset = EditPreviewFormSet(
|
||||||
@ -170,9 +168,7 @@ class ExtensionUpdateForm(forms.ModelForm):
|
|||||||
team_slug = None
|
team_slug = None
|
||||||
if self.instance.team:
|
if self.instance.team:
|
||||||
team_slug = self.instance.team.slug
|
team_slug = self.instance.team.slug
|
||||||
choices = [(None, self.request.user), *[(team.slug, team.name) for team in user_teams]]
|
choices = [(None, 'None'), *[(team.slug, team.name) for team in user_teams]]
|
||||||
if self.add_invalid_team_choice:
|
|
||||||
choices.insert(0, (self.invalid_team_value, '-----'))
|
|
||||||
self.fields['team'] = forms.ChoiceField(
|
self.fields['team'] = forms.ChoiceField(
|
||||||
choices=choices,
|
choices=choices,
|
||||||
required=False,
|
required=False,
|
||||||
@ -225,9 +221,6 @@ class ExtensionUpdateForm(forms.ModelForm):
|
|||||||
return
|
return
|
||||||
|
|
||||||
team_slug = self.cleaned_data['team']
|
team_slug = self.cleaned_data['team']
|
||||||
if team_slug == self.invalid_team_value:
|
|
||||||
self.add_error('team', _('Please select one of the valid values'))
|
|
||||||
return
|
|
||||||
if team_slug:
|
if team_slug:
|
||||||
team = self.request.user.teams.filter(slug=team_slug).first()
|
team = self.request.user.teams.filter(slug=team_slug).first()
|
||||||
if not team:
|
if not team:
|
||||||
|
@ -375,7 +375,6 @@ class DraftExtensionView(
|
|||||||
extension_form = ExtensionUpdateForm(
|
extension_form = ExtensionUpdateForm(
|
||||||
instance=self.extension,
|
instance=self.extension,
|
||||||
request=self.request,
|
request=self.request,
|
||||||
add_invalid_team_choice=True,
|
|
||||||
)
|
)
|
||||||
context['extension_form'] = extension_form
|
context['extension_form'] = extension_form
|
||||||
context['edit_preview_formset'] = extension_form.edit_preview_formset
|
context['edit_preview_formset'] = extension_form.edit_preview_formset
|
||||||
@ -392,7 +391,6 @@ class DraftExtensionView(
|
|||||||
self.request.FILES,
|
self.request.FILES,
|
||||||
instance=self.extension,
|
instance=self.extension,
|
||||||
request=self.request,
|
request=self.request,
|
||||||
add_invalid_team_choice=True,
|
|
||||||
)
|
)
|
||||||
if form.is_valid() and extension_form.is_valid():
|
if form.is_valid() and extension_form.is_valid():
|
||||||
return self.form_valid(form, extension_form)
|
return self.form_valid(form, extension_form)
|
||||||
|
Loading…
Reference in New Issue
Block a user