diff --git a/api/views.py b/api/views.py index 0f6301bc..e9528622 100644 --- a/api/views.py +++ b/api/views.py @@ -421,7 +421,7 @@ class UserViewSet(viewsets.ReadOnlyModelViewSet): class HomeCreationViewSet(viewsets.ReadOnlyModelViewSet): """Exposes infos of `users.models.Users` objects to create homes. """ - queryset = users.User.objects.all() + queryset = users.User.objects.filter(state = 0) serializer_class = serializers.HomeCreationSerializer class ClubViewSet(viewsets.ReadOnlyModelViewSet): diff --git a/cotisations/models.py b/cotisations/models.py index fe89aa5d..06791f89 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -243,6 +243,9 @@ def facture_post_save(**kwargs): """ facture = kwargs['instance'] user = facture.user + if facture.valid and facture.vente_set.filter(Q(type_cotisation='All') | Q(type_cotisation='Adhesion')).exists(): + user.state = 0 + user.save() user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) @@ -473,6 +476,11 @@ def vente_post_save(**kwargs): purchase.cotisation.save() user = purchase.facture.user user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) + if purchase.facture.valid and (purchase.type_cotisation == 'All' or purchase.type_cotisation == 'Adhesion'): + user = purchase.facture.user + if user.state == 3: + user.state = 0 + user.save() # TODO : change vente to purchase diff --git a/users/migrations/0077_auto_20180824_1750.py b/users/migrations/0077_auto_20180824_1750.py new file mode 100644 index 00000000..b9510257 --- /dev/null +++ b/users/migrations/0077_auto_20180824_1750.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-08-24 15:50 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0076_auto_20180818_1321'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='state', + field=models.IntegerField(choices=[(0, 'STATE_ACTIVE'), (1, 'STATE_DISABLED'), (2, 'STATE_ARCHIVE'), (3, 'STATE_NOT_YET_ACTIVE')], default=3), + ), + ] diff --git a/users/models.py b/users/models.py index de342031..3e6128a3 100755 --- a/users/models.py +++ b/users/models.py @@ -186,10 +186,12 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, STATE_ACTIVE = 0 STATE_DISABLED = 1 STATE_ARCHIVE = 2 + STATE_NOT_YET_ACTIVE = 3 STATES = ( (0, 'STATE_ACTIVE'), (1, 'STATE_DISABLED'), (2, 'STATE_ARCHIVE'), + (3, 'STATE_NOT_YET_ACTIVE'), ) surname = models.CharField(max_length=255) @@ -231,7 +233,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, blank=True ) pwd_ntlm = models.CharField(max_length=255) - state = models.IntegerField(choices=STATES, default=STATE_ACTIVE) + state = models.IntegerField(choices=STATES, default=STATE_NOT_YET_ACTIVE) registered = models.DateTimeField(auto_now_add=True) telephone = models.CharField(max_length=15, blank=True, null=True) uid_number = models.PositiveIntegerField( @@ -329,7 +331,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, @property def is_active(self): """ Renvoie si l'user est à l'état actif""" - return self.state == self.STATE_ACTIVE + return self.state == self.STATE_ACTIVE or self.state == self.STATE_NOT_YET_ACTIVE @property def is_staff(self): diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html index 0f4f8b2c..76b3daeb 100644 --- a/users/templates/users/profil.html +++ b/users/templates/users/profil.html @@ -211,11 +211,14 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endif %}