Merge branch 'Aufinal/fix_87' into 'k-fet'

Fixes #87

Le field `groups` de `UserGroupForm` accepte les valeurs vides, ce qui permet la destitution de K-Fêt.

See merge request !157
This commit is contained in:
Aurélien Delobelle 2017-02-02 12:28:56 +01:00
commit 1bf5352097

View file

@ -1,21 +1,17 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import *
from decimal import Decimal
from django import forms
from django.core.exceptions import ValidationError
from django.core.validators import MinLengthValidator
from django.contrib.auth.models import User, Group, Permission
from django.contrib.contenttypes.models import ContentType
from django.forms import modelformset_factory, inlineformset_factory
from django.forms.models import BaseInlineFormSet
from django.forms import modelformset_factory
from django.utils import timezone
from kfet.models import (Account, Checkout, Article, OperationGroup, Operation,
from kfet.models import (
Account, Checkout, Article, OperationGroup, Operation,
CheckoutStatement, ArticleCategory, Settings, AccountNegative, Transfer,
TransferGroup, Supplier, Inventory, InventoryArticle)
TransferGroup, Supplier)
from gestioncof.models import CofProfile
# -----
@ -131,7 +127,16 @@ class UserRestrictTeamForm(UserForm):
class UserGroupForm(forms.ModelForm):
groups = forms.ModelMultipleChoiceField(
Group.objects.filter(name__icontains='K-Fêt'))
Group.objects.filter(name__icontains='K-Fêt'),
required=False)
def clean_groups(self):
groups = self.cleaned_data.get('groups')
# Si aucun groupe, on le dénomme
if not groups:
groups = self.instance.groups.exclude(name__icontains='K-Fêt')
return groups
class Meta:
model = User
fields = ['groups']