Intitial teams support #147

Merged
Oleg-Komarov merged 34 commits from teams-support into main 2024-05-23 19:43:54 +02:00
Showing only changes of commit 23f8f2eb06 - Show all commits

View File

@ -117,7 +117,7 @@ class ExtensionUpdateForm(forms.ModelForm):
)
msg_need_previews = _('Please add at least one preview.')
msg_duplicate_file = _('Please select another file instead of the duplicate.')
invalid_team_value = '-1'
invalid_team_value = '-'
class Meta:
model = extensions.models.Extension
@ -167,16 +167,16 @@ class ExtensionUpdateForm(forms.ModelForm):
user_teams = self.request.user.teams.all()
if self.request.user in self.instance.authors.all() and len(user_teams) > 0:
team_pk = None
team_slug = None
if self.instance.team:
team_pk = self.instance.team.pk
choices = [(None, self.request.user), *[(team.pk, team.name) for team in user_teams]]
team_slug = self.instance.team.slug
choices = [(None, self.request.user), *[(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(
choices=choices,
required=False,
initial=team_pk,
initial=team_slug,
)
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'))
return
team_pk = self.cleaned_data['team']
if team_pk == self.invalid_team_value:
team_slug = self.cleaned_data['team']
if team_slug == self.invalid_team_value:
self.add_error('team', _('Please select a value'))
return
if team_pk:
team = self.request.user.teams.filter(pk=team_pk).first()
if team_slug:
team = self.request.user.teams.filter(slug=team_slug).first()
if not team:
self.add_error('team', _('User does not belong to the team'))
return