Intitial teams support #147
@ -117,7 +117,7 @@ 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 = '-1'
|
invalid_team_value = '-'
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = extensions.models.Extension
|
model = extensions.models.Extension
|
||||||
@ -167,16 +167,16 @@ class ExtensionUpdateForm(forms.ModelForm):
|
|||||||
|
|
||||||
user_teams = self.request.user.teams.all()
|
user_teams = self.request.user.teams.all()
|
||||||
if self.request.user in self.instance.authors.all() and len(user_teams) > 0:
|
if self.request.user in self.instance.authors.all() and len(user_teams) > 0:
|
||||||
team_pk = None
|
team_slug = None
|
||||||
if self.instance.team:
|
if self.instance.team:
|
||||||
team_pk = self.instance.team.pk
|
team_slug = self.instance.team.slug
|
||||||
choices = [(None, self.request.user), *[(team.pk, team.name) for team in user_teams]]
|
choices = [(None, self.request.user), *[(team.slug, team.name) for team in user_teams]]
|
||||||
if self.add_invalid_team_choice:
|
if self.add_invalid_team_choice:
|
||||||
choices.insert(0, (self.invalid_team_value, '-----'))
|
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,
|
||||||
initial=team_pk,
|
initial=team_slug,
|
||||||
)
|
)
|
||||||
|
|
||||||
def is_valid(self, *args, **kwargs) -> bool:
|
def is_valid(self, *args, **kwargs) -> bool:
|
||||||
@ -224,12 +224,12 @@ class ExtensionUpdateForm(forms.ModelForm):
|
|||||||
self.add_error('team', _('Not allowed to set the team'))
|
self.add_error('team', _('Not allowed to set the team'))
|
||||||
return
|
return
|
||||||
|
|
||||||
team_pk = self.cleaned_data['team']
|
team_slug = self.cleaned_data['team']
|
||||||
if team_pk == self.invalid_team_value:
|
if team_slug == self.invalid_team_value:
|
||||||
self.add_error('team', _('Please select a value'))
|
self.add_error('team', _('Please select a value'))
|
||||||
return
|
return
|
||||||
if team_pk:
|
if team_slug:
|
||||||
team = self.request.user.teams.filter(pk=team_pk).first()
|
team = self.request.user.teams.filter(slug=team_slug).first()
|
||||||
if not team:
|
if not team:
|
||||||
self.add_error('team', _('User does not belong to the team'))
|
self.add_error('team', _('User does not belong to the team'))
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user