2019-09-21 21:10:28 +00:00
# -*- coding: utf-8 -*-
# Generated by Django 1.11.23 on 2019-09-21 18:23
from __future__ import unicode_literals
from django . conf import settings
from django . db import migrations , models
import django . db . models . deletion
from django . utils import timezone
import re2o . mixins
def create_current_mandate ( apps , schema_editor ) :
2019-11-04 16:55:03 +00:00
AssoOption = apps . get_model ( " preferences " , " AssoOption " )
Mandate = apps . get_model ( " preferences " , " Mandate " )
Adherent = apps . get_model ( " users " , " Adherent " )
2019-09-23 22:04:00 +00:00
assooption = AssoOption . objects . get_or_create ( ) [ 0 ]
pres_name = assooption . pres_name
2019-11-04 16:55:03 +00:00
l = pres_name . split ( " " )
2019-09-21 21:10:28 +00:00
try :
name , surname = l [ 0 ] , l [ 1 ]
2019-11-04 16:55:03 +00:00
president = Adherent . objects . get (
name__icontains = name , surname__icontains = surname
2019-09-21 21:10:28 +00:00
)
2019-11-04 16:55:03 +00:00
Mandate . objects . create ( president = president , start_date = timezone . now ( ) )
2019-09-21 21:10:28 +00:00
except Exception as e :
2019-11-04 16:55:03 +00:00
print (
" Warning : I was unable to find an adherent corresponding to %s . You might want to edit your preferences afterward. I will disable the sending of vouchers by email. "
% pres_name
)
CotisationsOption = apps . get_model ( " preferences " , " CotisationsOption " )
2019-09-23 22:04:00 +00:00
cotisoption = CotisationsOption . objects . get_or_create ( ) [ 0 ]
cotisoption . send_voucher_mail = False
cotisoption . save ( )
2019-09-21 21:10:28 +00:00
class Migration ( migrations . Migration ) :
dependencies = [
migrations . swappable_dependency ( settings . AUTH_USER_MODEL ) ,
2019-11-04 16:55:03 +00:00
( " preferences " , " 0062_auto_20190910_1909 " ) ,
2019-09-21 21:10:28 +00:00
]
operations = [
migrations . CreateModel (
2019-11-04 16:55:03 +00:00
name = " Mandate " ,
2019-09-21 21:10:28 +00:00
fields = [
2019-11-04 16:55:03 +00:00
(
" id " ,
models . AutoField (
auto_created = True ,
primary_key = True ,
serialize = False ,
verbose_name = " ID " ,
) ,
) ,
( " start_date " , models . DateTimeField ( verbose_name = " start date " ) ) ,
(
" end_date " ,
models . DateTimeField (
blank = True , null = True , verbose_name = " end date "
) ,
) ,
(
" president " ,
models . ForeignKey (
blank = True ,
help_text = " Displayed on subscription vouchers " ,
null = True ,
on_delete = django . db . models . deletion . SET_NULL ,
to = settings . AUTH_USER_MODEL ,
verbose_name = " President of the association " ,
) ,
) ,
2019-09-21 21:10:28 +00:00
] ,
options = {
2019-11-04 16:55:03 +00:00
" verbose_name " : " Mandate " ,
" verbose_name_plural " : " Mandates " ,
" permissions " : ( ( " view_mandate " , " Can view a mandate " ) , ) ,
2019-09-21 21:10:28 +00:00
} ,
bases = ( re2o . mixins . RevMixin , re2o . mixins . AclMixin , models . Model ) ,
) ,
migrations . RunPython ( create_current_mandate ) ,
2019-09-23 20:49:59 +00:00
migrations . AlterField (
2019-11-04 16:55:03 +00:00
model_name = " cotisationsoption " ,
name = " send_voucher_mail " ,
field = models . BooleanField (
default = False ,
help_text = " Be carefull, if no mandate is defined on the preferences page, errors will be triggered when generating vouchers. " ,
verbose_name = " Send voucher by email when the invoice is controlled. " ,
) ,
2019-09-23 22:04:00 +00:00
) ,
2019-11-04 16:55:03 +00:00
migrations . RemoveField ( model_name = " assooption " , name = " pres_name " ) ,
2019-09-21 21:10:28 +00:00
]