Merge branch 'michele.orru/gestioCOF-supportBDS' into supportBDS

This commit is contained in:
Qwann 2017-02-11 20:17:23 +01:00
commit d46ab87e9b
6 changed files with 124 additions and 13 deletions

View file

@ -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',),
),
]

View file

@ -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)

View file

@ -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)

View file

@ -170,10 +170,11 @@ class UserProfileAdmin(UserAdmin):
list_display = ('profile_num',) + UserAdmin.list_display \
+ ('profile_login_clipper', 'profile_phone', 'profile_occupation',
'profile_mailing_cof', 'profile_mailing_bda',
'profile_mailing_bda_revente', 'is_cof', 'is_buro', )
'profile_mailing_bda_revente', 'is_buro', )
list_display_links = ('username', 'email', 'first_name', 'last_name')
list_filter = UserAdmin.list_filter \
+ ('profile__cof__is_cof',
+ (
# 'profile__cof__is_cof',
'profile__cof__is_buro',
'profile__cof__mailing',
'profile__cof__mailing_bda')

View file

@ -6,7 +6,7 @@ from __future__ import unicode_literals
from django.db import models
from django.dispatch import receiver
from django.contrib.auth.models import User
from django.contrib.auth.models import Group, Permission, User
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import python_2_unicode_compatible
import django.utils.six as six
@ -43,7 +43,6 @@ class CofProfile(models.Model):
mailing = models.BooleanField("Recevoir les mails COF", default=False)
# XXX. remove the following and use django auth.
is_buro = models.BooleanField("Membre du Burô", default=False)
is_cof = models.BooleanField("Membre du COF", default=False)
# XXX. remove the following and put in a BDA profile
mailing_bda = models.BooleanField("Recevoir les mails BdA", default=False)
mailing_bda_revente = models.BooleanField(
@ -55,12 +54,25 @@ class CofProfile(models.Model):
_("Remarques et précisions pour les petits cours"),
blank=True, default="")
# is_cof = models.BooleanField("Membre du COF", default=False)
@property
def is_cof(self):
return self.profile.user.has_perm('cof.member')
@is_cof.setter
def is_cof(self, really):
if really:
g = Group.objects.get(name='cof_members')
self.groups.add(g)
class Meta:
verbose_name = "Profil COF"
verbose_name_plural = "Profils COF"
def __str__(self):
return self.user.username
return self.profile.user.username
@python_2_unicode_compatible

View file

@ -1,3 +1,37 @@
from django.contrib.auth.models import Group, Permission, User
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
# Create your tests here.
from cof.models import CofProfile
from gestion.tests import create_profile
def create_cofprofile(username):
p = create_profile(username)
return CofProfile.objects.create(profile=p)
class TestCofProfile(TestCase):
def test_str(self):
# creates a group of cof members
group = Group.objects.create(name='cof_members')
# create a specific permission for all COF members.
ct = ContentType.objects.get(app_label='cof', model='CofProfile')
perm = Permission.objects.create(name='Cof Member',
codename='member',
content_type=ct)
# bind the two mutherfucker.
group.permissions = [perm]
# now test it for real
cofp = create_cofprofile('foo')
# XXX. should by default new CofProfiles be COF members?
self.assertFalse(cofp.profile.user.has_perm('cof.member'))
# adding/removing a user from the group should impact the
# permission
cofp.profile.user.groups.add(group)
cofp.save()
cofp = CofProfile.objects.first()
self.assertTrue(cofp.profile.user.has_perm('cof.member'))