This commit is contained in:
Ludovic Stephan 2017-01-31 16:35:52 -02:00
parent 0ac1eaf414
commit 47d7a3ec6e

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']