8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 07:23:46 +00:00

Cree une fonction pour set active les utilisateurs cotisant

This commit is contained in:
Gabriel Detraz 2018-08-31 13:26:54 +02:00 committed by root
parent 5ab8bb4f0e
commit 0ffdde5a6a
3 changed files with 14 additions and 11 deletions

View file

@ -29,6 +29,7 @@ the response (JSON or other), the CSRF exempting, ...
import datetime
from django.conf import settings
from django.db.models import Q
from rest_framework.authtoken.views import ObtainAuthToken
from rest_framework.authtoken.models import Token
from rest_framework.response import Response
@ -421,7 +422,7 @@ class UserViewSet(viewsets.ReadOnlyModelViewSet):
class HomeCreationViewSet(viewsets.ReadOnlyModelViewSet):
"""Exposes infos of `users.models.Users` objects to create homes.
"""
queryset = users.User.objects.filter(state = 0)
queryset = users.User.objects.exclude(Q(state=User.STATE_DISABLED) | Q(state=User.STATE_NOT_YET_ACTIVE))
serializer_class = serializers.HomeCreationSerializer
class ClubViewSet(viewsets.ReadOnlyModelViewSet):

View file

@ -243,10 +243,8 @@ 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)
user.set_active()
user.ldap_sync(base=True, access_refresh=True, mac_refresh=False)
@receiver(post_delete, sender=Facture)
@ -475,12 +473,8 @@ def vente_post_save(**kwargs):
purchase.create_cotis()
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()
user.set_active()
user.ldap_sync(base=True, access_refresh=True, mac_refresh=False)
# TODO : change vente to purchase

View file

@ -333,6 +333,14 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
""" Renvoie si l'user est à l'état actif"""
return self.state == self.STATE_ACTIVE or self.state == self.STATE_NOT_YET_ACTIVE
def set_active(self):
"""Enable this user if he subscribed successfully one time before
Active l'utilisateur définitivement si il a adhéré au moins une fois"""
if self.state == self.STATE_NOT_YET_ACTIVE:
if self.facture_set.filter(valid=True).filter(Q(vente__type_cotisation='All') | Q(vente__type_cotisation='Adhesion')).exists():
self.state = self.STATE_ACTIVE
self.save()
@property
def is_staff(self):
""" Fonction de base django, renvoie si l'user est admin"""