From a2b8dee02232689ea82652801a583a6bd7e97599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michele=20Orr=C3=B9?= Date: Sat, 11 Feb 2017 17:13:48 +0100 Subject: [PATCH] Fix #134. Fill bds.models with the required fields; add migration scripts, and a stupid unittests that checks the model really works. Note: old fields will migrate to datetime.now(). --- bds/migrations/0001_initial.py | 12 ++++++-- bds/models.py | 55 +++++++++++++++++++++++++++++++--- bds/tests.py | 11 ++++++- 3 files changed, 71 insertions(+), 7 deletions(-) diff --git a/bds/migrations/0001_initial.py b/bds/migrations/0001_initial.py index 31d0d9a4..e0d3ddd9 100644 --- a/bds/migrations/0001_initial.py +++ b/bds/migrations/0001_initial.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from django.db import migrations, models +import bds.models class Migration(migrations.Migration): @@ -14,8 +15,15 @@ class Migration(migrations.Migration): migrations.CreateModel( name='BdsProfile', fields=[ - ('profile', models.OneToOneField(serialize=False, to='gestion.Profile', primary_key=True)), + ('id', models.AutoField(serialize=False, auto_created=True, verbose_name='ID', primary_key=True)), + ('ASPSL_number', models.CharField(null=True, blank=True, verbose_name='Numéro AS PSL', max_length=50)), + ('FFSU_number', models.CharField(null=True, blank=True, verbose_name='Numéro FFSU', max_length=50)), + ('have_certificate', models.BooleanField(verbose_name='Certificat médical', default=False)), + ('certificate_file', models.FileField(blank=True, upload_to=bds.models.BdsProfile.issue_file_name, verbose_name='Fichier de certificat médical')), + ('cotisation_period', models.CharField(choices=[('ANN', 'Année'), ('SE1', 'Premier semestre'), ('SE2', 'Deuxième semestre')], verbose_name='Inscription', max_length=3, default='ANN')), + ('registration_date', models.DateField(verbose_name="Date d'inscription", auto_now_add=True)), + ('payment_method', models.CharField(choices=[('CASH', 'Liquide'), ('BANK', 'Transfer bancaire'), ('CHEQUE', 'Cheque'), ('OTHER', 'Autre')], verbose_name='Methode de paiement', max_length=6, default='CASH')), + ('profile', models.OneToOneField(related_name='bds', to='gestion.Profile')), ], - bases=('gestion.profile',), ), ] diff --git a/bds/models.py b/bds/models.py index 62b2665c..783bc078 100644 --- a/bds/models.py +++ b/bds/models.py @@ -1,9 +1,56 @@ -from django.db import models +import os.path +from datetime import datetime +from django.db import models from gestion.models import Profile -class BdsProfile(Profile): - profile = models.OneToOneField(Profile, on_delete=models.CASCADE) +class BdsProfile(models.Model): + profile = models.OneToOneField(Profile, + related_name='bds', + on_delete=models.CASCADE) - # mailing = models.BooleanField("Recevoir les mails BDS", default=False) + def issue_file_name(sportif, filename): + fn, extension = os.path.splitext(filename) + year = str(datetime.now().year) + return "certifs/" + sportif.__str__() + '-' + year + extension + + COTIZ_DURATION_CHOICES = ( + ('ANN', 'Année'), + ('SE1', 'Premier semestre'), + ('SE2', 'Deuxième semestre'), + ) + + PAYMENT_METHOD_CHOICES = ( + ('CASH', 'Liquide'), + ('BANK', 'Transfer bancaire'), + ('CHEQUE', 'Cheque'), + ('OTHER', 'Autre'), + ) + + ASPSL_number = models.CharField("Numéro AS PSL", + max_length=50, + blank=True, + null=True) + FFSU_number = models.CharField("Numéro FFSU", + max_length=50, + blank=True, + null=True) + + have_certificate = models.BooleanField("Certificat médical", + default=False) + certificate_file = models.FileField("Fichier de certificat médical", + upload_to=issue_file_name, + blank=True) + + cotisation_period = models.CharField("Inscription", + default="ANN", + choices=COTIZ_DURATION_CHOICES, + max_length=3) + registration_date = models.DateField(auto_now_add=True, + verbose_name="Date d'inscription") + + payment_method = models.CharField('Methode de paiement', + default='CASH', + choices=PAYMENT_METHOD_CHOICES, + max_length=6) diff --git a/bds/tests.py b/bds/tests.py index 7ce503c2..b26d0c61 100644 --- a/bds/tests.py +++ b/bds/tests.py @@ -1,3 +1,12 @@ from django.test import TestCase -# Create your tests here. +from gestion.tests import create_profile + +from .models import BdsProfile + +class TestBdsProfile(TestCase): + def test_profile(self): + # each bdspofile should have an associated profile + p = create_profile('foo') + bdsp = BdsProfile.objects.create(profile=p) + self.assertEqual(p.bds, bdsp)