Merge branch 'aureplop/fix-unreachable-objects-form-creation' into 'test/views'

Fix fields cleaning with unreachable items when…

See merge request !260
This commit is contained in:
Martin Pepin 2017-10-12 19:21:16 +02:00
commit 47e48e36b2

View file

@ -136,6 +136,8 @@ class UserGroupForm(forms.ModelForm):
def clean_groups(self): def clean_groups(self):
kfet_groups = self.cleaned_data.get('groups') kfet_groups = self.cleaned_data.get('groups')
if self.instance.pk is None:
return kfet_groups
other_groups = self.instance.groups.exclude(name__icontains='K-Fêt') other_groups = self.instance.groups.exclude(name__icontains='K-Fêt')
return list(kfet_groups) + list(other_groups) return list(kfet_groups) + list(other_groups)
@ -173,6 +175,8 @@ class GroupForm(forms.ModelForm):
# other_groups = self.instance.permissions.difference( # other_groups = self.instance.permissions.difference(
# self.fields['permissions'].queryset # self.fields['permissions'].queryset
# ) # )
if self.instance.pk is None:
return kfet_perms
other_perms = self.instance.permissions.exclude( other_perms = self.instance.permissions.exclude(
pk__in=[p.pk for p in self.fields['permissions'].queryset], pk__in=[p.pk for p in self.fields['permissions'].queryset],
) )