This file contains 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 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 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 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 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 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 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.%s@yopmail.com' \ | |
% (obj.first_name.lower(), obj.last_name.lower())) | |
password = factory.PostGenerationMethodCall('set_password', 'azerty42') |
This file contains 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 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. |
This file contains 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 GetClientFromCard_1_Test(LiveServerTestCase): | |
''' Test du WS GetClientFromCard_1 ''' | |
def setUp(self): | |
api_test_scenario() | |
self.url = BASE_T_URL + 'get_client_from_card/' | |
def test_scan_invalid_card(self): | |
''' Scan d'un numéro de carte inconnu ''' | |
resp = requests.get(self.url + '999', auth=OWNER_AUTH) |