mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-04 17:06:27 +00:00
Cree une fonction pour set active les utilisateurs cotisant
This commit is contained in:
parent
5ab8bb4f0e
commit
0ffdde5a6a
3 changed files with 14 additions and 11 deletions
|
@ -29,6 +29,7 @@ the response (JSON or other), the CSRF exempting, ...
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db.models import Q
|
||||||
from rest_framework.authtoken.views import ObtainAuthToken
|
from rest_framework.authtoken.views import ObtainAuthToken
|
||||||
from rest_framework.authtoken.models import Token
|
from rest_framework.authtoken.models import Token
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
@ -421,7 +422,7 @@ class UserViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
class HomeCreationViewSet(viewsets.ReadOnlyModelViewSet):
|
class HomeCreationViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
"""Exposes infos of `users.models.Users` objects to create homes.
|
"""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
|
serializer_class = serializers.HomeCreationSerializer
|
||||||
|
|
||||||
class ClubViewSet(viewsets.ReadOnlyModelViewSet):
|
class ClubViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
|
|
@ -243,10 +243,8 @@ def facture_post_save(**kwargs):
|
||||||
"""
|
"""
|
||||||
facture = kwargs['instance']
|
facture = kwargs['instance']
|
||||||
user = facture.user
|
user = facture.user
|
||||||
if facture.valid and facture.vente_set.filter(Q(type_cotisation='All') | Q(type_cotisation='Adhesion')).exists():
|
user.set_active()
|
||||||
user.state = 0
|
user.ldap_sync(base=True, access_refresh=True, mac_refresh=False)
|
||||||
user.save()
|
|
||||||
user.ldap_sync(base=False, access_refresh=True, mac_refresh=False)
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_delete, sender=Facture)
|
@receiver(post_delete, sender=Facture)
|
||||||
|
@ -475,12 +473,8 @@ def vente_post_save(**kwargs):
|
||||||
purchase.create_cotis()
|
purchase.create_cotis()
|
||||||
purchase.cotisation.save()
|
purchase.cotisation.save()
|
||||||
user = purchase.facture.user
|
user = purchase.facture.user
|
||||||
user.ldap_sync(base=False, access_refresh=True, mac_refresh=False)
|
user.set_active()
|
||||||
if purchase.facture.valid and (purchase.type_cotisation == 'All' or purchase.type_cotisation == 'Adhesion'):
|
user.ldap_sync(base=True, access_refresh=True, mac_refresh=False)
|
||||||
user = purchase.facture.user
|
|
||||||
if user.state == 3:
|
|
||||||
user.state = 0
|
|
||||||
user.save()
|
|
||||||
|
|
||||||
|
|
||||||
# TODO : change vente to purchase
|
# TODO : change vente to purchase
|
||||||
|
|
|
@ -333,6 +333,14 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
""" Renvoie si l'user est à l'état actif"""
|
""" Renvoie si l'user est à l'état actif"""
|
||||||
return self.state == self.STATE_ACTIVE or self.state == self.STATE_NOT_YET_ACTIVE
|
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
|
@property
|
||||||
def is_staff(self):
|
def is_staff(self):
|
||||||
""" Fonction de base django, renvoie si l'user est admin"""
|
""" Fonction de base django, renvoie si l'user est admin"""
|
||||||
|
|
Loading…
Reference in a new issue