From fa3aca906f0cc10d4bb6f8e2f2a26edbd5899f8e Mon Sep 17 00:00:00 2001 From: grisel-davy Date: Thu, 30 Aug 2018 17:25:15 +0200 Subject: [PATCH] =?UTF-8?q?Les=20nouveau=20users=20ne=20sont=20pas=20adh?= =?UTF-8?q?=C3=A9rents=20et=20n'ont=20pas=20de=20home?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/views.py | 2 +- cotisations/models.py | 8 ++++++++ users/migrations/0077_auto_20180824_1750.py | 20 ++++++++++++++++++++ users/models.py | 6 ++++-- users/templates/users/profil.html | 11 +++++++---- 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 users/migrations/0077_auto_20180824_1750.py 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 %} {% trans "State" %} {% if users.state == 0 %} - {% trans "Active" %} + {% trans "Active" %} {% elif users.state == 1 %} - {% trans "Disabled" %} - {% else %} - {% trans "Archived" %} + {% trans "Disabled" %} + {% elif users.state == 2 %} + {% trans "Archived" %} + {% elif users.state == 3 %} + {% trans "Not yet Member" %} + {% endif %}