This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# models.py | |
class User(AbstractBaseUser, PermissionsMixin): | |
# ... | |
def is_owner(self): | |
''' Retourne True si cet utilisateur est lié à un BizProfile ''' | |
try: | |
self.bizprofile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# models.py | |
class Points(TimeStampedModel): | |
class Meta: | |
# Empêche les doublons au niveau DB (sécurité) | |
unique_together = ('benef_card', 'spendable_at') | |
# ... | |
def save(self, *args, **kwargs): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Event(TimeStampedModel): | |
''' Classe abstraite servant de base aux modèles ScanEvent et | |
UseRewardEvent. N'est pas représenté en base puisqu'abstrait. ''' | |
is_cancelled = models.BooleanField(default=False) | |
# ... autres attributs communs | |
class Meta: | |
abstract = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@classmethod | |
def gen_id(cls): | |
''' Retourne un ID (unique donc) généré aléatoirement entre first_id et | |
last_id. Est appelé à chaque fois qu'une carte est générée. WARN : les | |
performances de cette méthode se dégraderont au fil du nombre d'objets.Les bornes pourront être changées si cela devient un problème.''' | |
first_id = 10000000000 # min = 10000000000 (11 digits) | |
last_id = 100000000000 # max = 99999999999 (11 digits) | |
while True: # WARN : attention aux risques de boucles infinies |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# views.py | |
# Création du 'modèle' de tuple | |
ClientInfosTuple = namedtuple( | |
'ClientInfosTuple', # Nom du tuple | |
['client_str', 'birth_date', 'gender', 'nb_points', 'first_scan', | |
'last_scan', 'nb_scans', 'nb_redeemdeals']) | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Command(BaseCommand): | |
''' Commande permettant de réinitialiser les crédits des owners à leur | |
quantité initiale le 1er jour du mois. | |
A exécuter dans une tâche planifiée le 1er jour du mois (ou tous les jours le cas échéant) ''' | |
help = ("Reinitialise les crédits des owners à leur quantité initiale le" | |
"1er jour du mois") | |
def handle(self, *args, **options): | |
if is_first_day_of_month(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# scenarios.py | |
def demo_scenario(): | |
''' Création des données initiales pour l'environnement de démo. ''' | |
user01 = UserFactory.create(first_name="Gerard", last_name="Philippe", birth_date=date(1945, 4, 30), gender="M") | |
user02 = UserFactory.create(first_name="Sonia", last_name="Roland", birth_date=date(1979, 4, 8), gender="F") | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# factories.py | |
class UserFactory(factory.DjangoModelFactory): | |
class Meta: | |
model = User # Le modèle à Utiliser | |
first_name = factory.Sequence(lambda n: 'Prenom%d' % n) # itération automatique | |
last_name = factory.Sequence(lambda n: 'Nom%d' % n) | |
email = factory.LazyAttribute(lambda obj: '%s.%[email protected]' \ | |
% (obj.first_name.lower(), obj.last_name.lower())) | |
password = factory.PostGenerationMethodCall('set_password', 'azerty42') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if msg.tags == 'error' %} | |
<div class='alert alert-danger alert-dismissable text-center'> | |
<a class="close" data-dismiss="alert" href="#">×</a> | |
<i class='icon-remove-sign'></i> | |
{{ msg }} | |
</div> | |
{% endif %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
messages.error(request, ERR_NON_PAY) # ERR_NON_PAY est une variable dans strings.py. |