Refine collection visibility and team selection
This commit is contained in:
+15
-1
@@ -134,6 +134,20 @@ class KanbanForm(forms.ModelForm):
|
||||
|
||||
|
||||
class CollectionForm(forms.ModelForm):
|
||||
def __init__(self, *args, user=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if user and user.is_authenticated:
|
||||
team_slugs = user.team_memberships.values_list('team__slug', flat=True)
|
||||
self.fields['tags'].queryset = Tag.objects.filter(name__in=team_slugs).order_by('name')
|
||||
else:
|
||||
self.fields['tags'].queryset = Tag.objects.none()
|
||||
|
||||
def clean_tags(self):
|
||||
tags = self.cleaned_data['tags']
|
||||
if tags.count() > 1:
|
||||
raise forms.ValidationError(_('Select at most one team.'))
|
||||
return tags
|
||||
|
||||
class Meta:
|
||||
model = Collection
|
||||
fields = ['title', 'description', 'visibility', 'tags']
|
||||
@@ -141,7 +155,7 @@ class CollectionForm(forms.ModelForm):
|
||||
'title': _('Title'),
|
||||
'description': _('Description'),
|
||||
'visibility': _('Visibility'),
|
||||
'tags': _('Tags'),
|
||||
'tags': _('Team'),
|
||||
}
|
||||
widgets = {
|
||||
'title': forms.TextInput(attrs={'class': 'form-control'}),
|
||||
|
||||
Reference in New Issue
Block a user