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().
This commit is contained in:
parent
f0c3def935
commit
a2b8dee022
3 changed files with 71 additions and 7 deletions
|
@ -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',),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -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)
|
||||
|
|
11
bds/tests.py
11
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)
|
||||
|
|
Loading…
Reference in a new issue