mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
All: Apply Black coding rules
This commit is contained in:
@ -21,4 +21,3 @@
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
|
||||
|
@ -29,7 +29,12 @@ from haystack.admin import SearchModelAdmin
|
||||
|
||||
|
||||
class SubscriptionAdmin(SearchModelAdmin):
|
||||
search_fields = ["member__username", "subscription_start", "subscription_end", "subscription_type"]
|
||||
search_fields = [
|
||||
"member__username",
|
||||
"subscription_start",
|
||||
"subscription_end",
|
||||
"subscription_type",
|
||||
]
|
||||
|
||||
|
||||
admin.site.register(Subscription, SubscriptionAdmin)
|
||||
|
@ -7,28 +7,78 @@ import django.contrib.auth.models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0001_initial'),
|
||||
]
|
||||
dependencies = [("core", "0001_initial")]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Subscription',
|
||||
name="Subscription",
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='ID', auto_created=True)),
|
||||
('subscription_type', models.CharField(choices=[('amicale/doceo', 'Amicale/DOCEO member'), ('assidu', 'Assidu member'), ('crous', 'CROUS member'), ('cursus-alternant', 'Branch cursus'), ('cursus-branche', 'Branch cursus'), ('cursus-tronc-commun', 'Common core cursus'), ('deux-semestres', 'Two semesters'), ('membre-honoraire', 'Honorary member'), ('reseau-ut', 'UT network member'), ('sbarro/esta', 'Sbarro/ESTA member'), ('un-semestre', 'One semester')], max_length=255, verbose_name='subscription type')),
|
||||
('subscription_start', models.DateField(verbose_name='subscription start')),
|
||||
('subscription_end', models.DateField(verbose_name='subscription end')),
|
||||
('payment_method', models.CharField(choices=[('CHECK', 'Check'), ('CARD', 'Credit card'), ('CASH', 'Cash'), ('EBOUTIC', 'Eboutic'), ('OTHER', 'Other')], max_length=255, verbose_name='payment method')),
|
||||
('location', models.CharField(choices=[('BELFORT', 'Belfort'), ('SEVENANS', 'Sevenans'), ('MONTBELIARD', 'Montbéliard')], max_length=20, verbose_name='location')),
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
auto_created=True,
|
||||
),
|
||||
),
|
||||
(
|
||||
"subscription_type",
|
||||
models.CharField(
|
||||
choices=[
|
||||
("amicale/doceo", "Amicale/DOCEO member"),
|
||||
("assidu", "Assidu member"),
|
||||
("crous", "CROUS member"),
|
||||
("cursus-alternant", "Branch cursus"),
|
||||
("cursus-branche", "Branch cursus"),
|
||||
("cursus-tronc-commun", "Common core cursus"),
|
||||
("deux-semestres", "Two semesters"),
|
||||
("membre-honoraire", "Honorary member"),
|
||||
("reseau-ut", "UT network member"),
|
||||
("sbarro/esta", "Sbarro/ESTA member"),
|
||||
("un-semestre", "One semester"),
|
||||
],
|
||||
max_length=255,
|
||||
verbose_name="subscription type",
|
||||
),
|
||||
),
|
||||
(
|
||||
"subscription_start",
|
||||
models.DateField(verbose_name="subscription start"),
|
||||
),
|
||||
("subscription_end", models.DateField(verbose_name="subscription end")),
|
||||
(
|
||||
"payment_method",
|
||||
models.CharField(
|
||||
choices=[
|
||||
("CHECK", "Check"),
|
||||
("CARD", "Credit card"),
|
||||
("CASH", "Cash"),
|
||||
("EBOUTIC", "Eboutic"),
|
||||
("OTHER", "Other"),
|
||||
],
|
||||
max_length=255,
|
||||
verbose_name="payment method",
|
||||
),
|
||||
),
|
||||
(
|
||||
"location",
|
||||
models.CharField(
|
||||
choices=[
|
||||
("BELFORT", "Belfort"),
|
||||
("SEVENANS", "Sevenans"),
|
||||
("MONTBELIARD", "Montbéliard"),
|
||||
],
|
||||
max_length=20,
|
||||
verbose_name="location",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'ordering': ['subscription_start'],
|
||||
},
|
||||
options={"ordering": ["subscription_start"]},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='subscription',
|
||||
name='member',
|
||||
field=models.ForeignKey(to='core.User', related_name='subscriptions'),
|
||||
model_name="subscription",
|
||||
name="member",
|
||||
field=models.ForeignKey(to="core.User", related_name="subscriptions"),
|
||||
),
|
||||
]
|
||||
|
@ -6,14 +6,21 @@ from django.db import migrations, models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subscription', '0001_initial'),
|
||||
]
|
||||
dependencies = [("subscription", "0001_initial")]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='subscription',
|
||||
name='location',
|
||||
field=models.CharField(max_length=20, verbose_name='location', choices=[('BELFORT', 'Belfort'), ('SEVENANS', 'Sevenans'), ('MONTBELIARD', 'Montbéliard'), ('EBOUTIC', 'Eboutic')]),
|
||||
),
|
||||
model_name="subscription",
|
||||
name="location",
|
||||
field=models.CharField(
|
||||
max_length=20,
|
||||
verbose_name="location",
|
||||
choices=[
|
||||
("BELFORT", "Belfort"),
|
||||
("SEVENANS", "Sevenans"),
|
||||
("MONTBELIARD", "Montbéliard"),
|
||||
("EBOUTIC", "Eboutic"),
|
||||
],
|
||||
),
|
||||
)
|
||||
]
|
||||
|
@ -6,14 +6,28 @@ from django.db import migrations, models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subscription', '0002_auto_20160830_1719'),
|
||||
]
|
||||
dependencies = [("subscription", "0002_auto_20160830_1719")]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='subscription',
|
||||
name='subscription_type',
|
||||
field=models.CharField(max_length=255, choices=[('amicale/doceo', 'Amicale/DOCEO member'), ('assidu', 'Assidu member'), ('crous', 'CROUS member'), ('cursus-alternant', 'Alternating cursus'), ('cursus-branche', 'Branch cursus'), ('cursus-tronc-commun', 'Common core cursus'), ('deux-semestres', 'Two semesters'), ('membre-honoraire', 'Honorary member'), ('reseau-ut', 'UT network member'), ('sbarro/esta', 'Sbarro/ESTA member'), ('un-semestre', 'One semester')], verbose_name='subscription type'),
|
||||
),
|
||||
model_name="subscription",
|
||||
name="subscription_type",
|
||||
field=models.CharField(
|
||||
max_length=255,
|
||||
choices=[
|
||||
("amicale/doceo", "Amicale/DOCEO member"),
|
||||
("assidu", "Assidu member"),
|
||||
("crous", "CROUS member"),
|
||||
("cursus-alternant", "Alternating cursus"),
|
||||
("cursus-branche", "Branch cursus"),
|
||||
("cursus-tronc-commun", "Common core cursus"),
|
||||
("deux-semestres", "Two semesters"),
|
||||
("membre-honoraire", "Honorary member"),
|
||||
("reseau-ut", "UT network member"),
|
||||
("sbarro/esta", "Sbarro/ESTA member"),
|
||||
("un-semestre", "One semester"),
|
||||
],
|
||||
verbose_name="subscription type",
|
||||
),
|
||||
)
|
||||
]
|
||||
|
@ -6,14 +6,30 @@ from django.db import migrations, models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subscription', '0003_auto_20160902_1914'),
|
||||
]
|
||||
dependencies = [("subscription", "0003_auto_20160902_1914")]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='subscription',
|
||||
name='subscription_type',
|
||||
field=models.CharField(verbose_name='subscription type', choices=[('amicale/doceo', 'Amicale/DOCEO member'), ('assidu', 'Assidu member'), ('crous', 'CROUS member'), ('cursus-alternant', 'Alternating cursus'), ('cursus-branche', 'Branch cursus'), ('cursus-tronc-commun', 'Common core cursus'), ('deux-semestres', 'Two semesters'), ('membre-honoraire', 'Honorary member'), ('reseau-ut', 'UT network member'), ('sbarro/esta', 'Sbarro/ESTA member'), ('sixieme-de-semestre', 'One month for free'), ('un-semestre', 'One semester'), ('un-semestre-welcome', 'One semester Welcome Week')], max_length=255),
|
||||
),
|
||||
model_name="subscription",
|
||||
name="subscription_type",
|
||||
field=models.CharField(
|
||||
verbose_name="subscription type",
|
||||
choices=[
|
||||
("amicale/doceo", "Amicale/DOCEO member"),
|
||||
("assidu", "Assidu member"),
|
||||
("crous", "CROUS member"),
|
||||
("cursus-alternant", "Alternating cursus"),
|
||||
("cursus-branche", "Branch cursus"),
|
||||
("cursus-tronc-commun", "Common core cursus"),
|
||||
("deux-semestres", "Two semesters"),
|
||||
("membre-honoraire", "Honorary member"),
|
||||
("reseau-ut", "UT network member"),
|
||||
("sbarro/esta", "Sbarro/ESTA member"),
|
||||
("sixieme-de-semestre", "One month for free"),
|
||||
("un-semestre", "One semester"),
|
||||
("un-semestre-welcome", "One semester Welcome Week"),
|
||||
],
|
||||
max_length=255,
|
||||
),
|
||||
)
|
||||
]
|
||||
|
@ -6,14 +6,29 @@ from django.db import migrations, models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subscription', '0004_auto_20170821_1849'),
|
||||
]
|
||||
dependencies = [("subscription", "0004_auto_20170821_1849")]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='subscription',
|
||||
name='subscription_type',
|
||||
field=models.CharField(choices=[('amicale/doceo', 'Amicale/DOCEO member'), ('assidu', 'Assidu member'), ('crous', 'CROUS member'), ('cursus-alternant', 'Alternating cursus'), ('cursus-branche', 'Branch cursus'), ('cursus-tronc-commun', 'Common core cursus'), ('deux-semestres', 'Two semesters'), ('membre-honoraire', 'Honorary member'), ('reseau-ut', 'UT network member'), ('sbarro/esta', 'Sbarro/ESTA member'), ('un-semestre', 'One semester'), ('un-semestre-welcome', 'One semester Welcome Week')], max_length=255, verbose_name='subscription type'),
|
||||
),
|
||||
model_name="subscription",
|
||||
name="subscription_type",
|
||||
field=models.CharField(
|
||||
choices=[
|
||||
("amicale/doceo", "Amicale/DOCEO member"),
|
||||
("assidu", "Assidu member"),
|
||||
("crous", "CROUS member"),
|
||||
("cursus-alternant", "Alternating cursus"),
|
||||
("cursus-branche", "Branch cursus"),
|
||||
("cursus-tronc-commun", "Common core cursus"),
|
||||
("deux-semestres", "Two semesters"),
|
||||
("membre-honoraire", "Honorary member"),
|
||||
("reseau-ut", "UT network member"),
|
||||
("sbarro/esta", "Sbarro/ESTA member"),
|
||||
("un-semestre", "One semester"),
|
||||
("un-semestre-welcome", "One semester Welcome Week"),
|
||||
],
|
||||
max_length=255,
|
||||
verbose_name="subscription type",
|
||||
),
|
||||
)
|
||||
]
|
||||
|
@ -6,14 +6,30 @@ from django.db import migrations, models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subscription', '0005_auto_20170821_2054'),
|
||||
]
|
||||
dependencies = [("subscription", "0005_auto_20170821_2054")]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='subscription',
|
||||
name='subscription_type',
|
||||
field=models.CharField(verbose_name='subscription type', choices=[('amicale/doceo', 'Amicale/DOCEO member'), ('assidu', 'Assidu member'), ('crous', 'CROUS member'), ('cursus-alternant', 'Alternating cursus'), ('cursus-branche', 'Branch cursus'), ('cursus-tronc-commun', 'Common core cursus'), ('deux-mois-essai', 'Two month for free'), ('deux-semestres', 'Two semesters'), ('membre-honoraire', 'Honorary member'), ('reseau-ut', 'UT network member'), ('sbarro/esta', 'Sbarro/ESTA member'), ('un-semestre', 'One semester'), ('un-semestre-welcome', 'One semester Welcome Week')], max_length=255),
|
||||
),
|
||||
model_name="subscription",
|
||||
name="subscription_type",
|
||||
field=models.CharField(
|
||||
verbose_name="subscription type",
|
||||
choices=[
|
||||
("amicale/doceo", "Amicale/DOCEO member"),
|
||||
("assidu", "Assidu member"),
|
||||
("crous", "CROUS member"),
|
||||
("cursus-alternant", "Alternating cursus"),
|
||||
("cursus-branche", "Branch cursus"),
|
||||
("cursus-tronc-commun", "Common core cursus"),
|
||||
("deux-mois-essai", "Two month for free"),
|
||||
("deux-semestres", "Two semesters"),
|
||||
("membre-honoraire", "Honorary member"),
|
||||
("reseau-ut", "UT network member"),
|
||||
("sbarro/esta", "Sbarro/ESTA member"),
|
||||
("un-semestre", "One semester"),
|
||||
("un-semestre-welcome", "One semester Welcome Week"),
|
||||
],
|
||||
max_length=255,
|
||||
),
|
||||
)
|
||||
]
|
||||
|
@ -7,14 +7,31 @@ from django.db import migrations, models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subscription', '0006_auto_20170902_1222'),
|
||||
]
|
||||
dependencies = [("subscription", "0006_auto_20170902_1222")]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='subscription',
|
||||
name='subscription_type',
|
||||
field=models.CharField(choices=[('amicale/doceo', 'Amicale/DOCEO member'), ('assidu', 'Assidu member'), ('benevoles-euroks', "Eurok's volunteer"), ('crous', 'CROUS member'), ('cursus-alternant', 'Alternating cursus'), ('cursus-branche', 'Branch cursus'), ('cursus-tronc-commun', 'Common core cursus'), ('deux-mois-essai', 'Two month for free'), ('deux-semestres', 'Two semesters'), ('membre-honoraire', 'Honorary member'), ('reseau-ut', 'UT network member'), ('sbarro/esta', 'Sbarro/ESTA member'), ('un-semestre', 'One semester'), ('un-semestre-welcome', 'One semester Welcome Week')], max_length=255, verbose_name='subscription type'),
|
||||
),
|
||||
model_name="subscription",
|
||||
name="subscription_type",
|
||||
field=models.CharField(
|
||||
choices=[
|
||||
("amicale/doceo", "Amicale/DOCEO member"),
|
||||
("assidu", "Assidu member"),
|
||||
("benevoles-euroks", "Eurok's volunteer"),
|
||||
("crous", "CROUS member"),
|
||||
("cursus-alternant", "Alternating cursus"),
|
||||
("cursus-branche", "Branch cursus"),
|
||||
("cursus-tronc-commun", "Common core cursus"),
|
||||
("deux-mois-essai", "Two month for free"),
|
||||
("deux-semestres", "Two semesters"),
|
||||
("membre-honoraire", "Honorary member"),
|
||||
("reseau-ut", "UT network member"),
|
||||
("sbarro/esta", "Sbarro/ESTA member"),
|
||||
("un-semestre", "One semester"),
|
||||
("un-semestre-welcome", "One semester Welcome Week"),
|
||||
],
|
||||
max_length=255,
|
||||
verbose_name="subscription type",
|
||||
),
|
||||
)
|
||||
]
|
||||
|
@ -7,14 +7,32 @@ from django.db import migrations, models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subscription', '0007_auto_20180706_1135'),
|
||||
]
|
||||
dependencies = [("subscription", "0007_auto_20180706_1135")]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='subscription',
|
||||
name='subscription_type',
|
||||
field=models.CharField(choices=[('amicale/doceo', 'Amicale/DOCEO member'), ('assidu', 'Assidu member'), ('benevoles-euroks', "Eurok's volunteer"), ('crous', 'CROUS member'), ('cursus-alternant', 'Alternating cursus'), ('cursus-branche', 'Branch cursus'), ('cursus-tronc-commun', 'Common core cursus'), ('deux-mois-essai', 'Two month for free'), ('deux-semestres', 'Two semesters'), ('membre-honoraire', 'Honorary member'), ('reseau-ut', 'UT network member'), ('sbarro/esta', 'Sbarro/ESTA member'), ('six-semaines-essai', 'Six weeks for free'), ('un-semestre', 'One semester'), ('un-semestre-welcome', 'One semester Welcome Week')], max_length=255, verbose_name='subscription type'),
|
||||
),
|
||||
model_name="subscription",
|
||||
name="subscription_type",
|
||||
field=models.CharField(
|
||||
choices=[
|
||||
("amicale/doceo", "Amicale/DOCEO member"),
|
||||
("assidu", "Assidu member"),
|
||||
("benevoles-euroks", "Eurok's volunteer"),
|
||||
("crous", "CROUS member"),
|
||||
("cursus-alternant", "Alternating cursus"),
|
||||
("cursus-branche", "Branch cursus"),
|
||||
("cursus-tronc-commun", "Common core cursus"),
|
||||
("deux-mois-essai", "Two month for free"),
|
||||
("deux-semestres", "Two semesters"),
|
||||
("membre-honoraire", "Honorary member"),
|
||||
("reseau-ut", "UT network member"),
|
||||
("sbarro/esta", "Sbarro/ESTA member"),
|
||||
("six-semaines-essai", "Six weeks for free"),
|
||||
("un-semestre", "One semester"),
|
||||
("un-semestre-welcome", "One semester Welcome Week"),
|
||||
],
|
||||
max_length=255,
|
||||
verbose_name="subscription type",
|
||||
),
|
||||
)
|
||||
]
|
||||
|
@ -7,14 +7,33 @@ from django.db import migrations, models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subscription', '0008_auto_20180831_2016'),
|
||||
]
|
||||
dependencies = [("subscription", "0008_auto_20180831_2016")]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='subscription',
|
||||
name='subscription_type',
|
||||
field=models.CharField(choices=[('amicale/doceo', 'Amicale/DOCEO member'), ('assidu', 'Assidu member'), ('benevoles-euroks', "Eurok's volunteer"), ('crous', 'CROUS member'), ('cursus-alternant', 'Alternating cursus'), ('cursus-branche', 'Branch cursus'), ('cursus-tronc-commun', 'Common core cursus'), ('deux-mois-essai', 'Two months for free'), ('deux-semestres', 'Two semesters'), ('membre-honoraire', 'Honorary member'), ('reseau-ut', 'UT network member'), ('sbarro/esta', 'Sbarro/ESTA member'), ('six-semaines-essai', 'Six weeks for free'), ('un-jour', 'Un jour'), ('un-semestre', 'One semester'), ('un-semestre-welcome', 'One semester Welcome Week')], max_length=255, verbose_name='subscription type'),
|
||||
),
|
||||
model_name="subscription",
|
||||
name="subscription_type",
|
||||
field=models.CharField(
|
||||
choices=[
|
||||
("amicale/doceo", "Amicale/DOCEO member"),
|
||||
("assidu", "Assidu member"),
|
||||
("benevoles-euroks", "Eurok's volunteer"),
|
||||
("crous", "CROUS member"),
|
||||
("cursus-alternant", "Alternating cursus"),
|
||||
("cursus-branche", "Branch cursus"),
|
||||
("cursus-tronc-commun", "Common core cursus"),
|
||||
("deux-mois-essai", "Two months for free"),
|
||||
("deux-semestres", "Two semesters"),
|
||||
("membre-honoraire", "Honorary member"),
|
||||
("reseau-ut", "UT network member"),
|
||||
("sbarro/esta", "Sbarro/ESTA member"),
|
||||
("six-semaines-essai", "Six weeks for free"),
|
||||
("un-jour", "Un jour"),
|
||||
("un-semestre", "One semester"),
|
||||
("un-semestre-welcome", "One semester Welcome Week"),
|
||||
],
|
||||
max_length=255,
|
||||
verbose_name="subscription type",
|
||||
),
|
||||
)
|
||||
]
|
||||
|
@ -7,14 +7,33 @@ from django.db import migrations, models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subscription', '0009_auto_20180920_1421'),
|
||||
]
|
||||
dependencies = [("subscription", "0009_auto_20180920_1421")]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='subscription',
|
||||
name='subscription_type',
|
||||
field=models.CharField(choices=[('amicale/doceo', 'Amicale/DOCEO member'), ('assidu', 'Assidu member'), ('benevoles-euroks', "Eurok's volunteer"), ('crous', 'CROUS member'), ('cursus-alternant', 'Alternating cursus'), ('cursus-branche', 'Branch cursus'), ('cursus-tronc-commun', 'Common core cursus'), ('deux-mois-essai', 'Two months for free'), ('deux-semestres', 'Two semesters'), ('membre-honoraire', 'Honorary member'), ('reseau-ut', 'UT network member'), ('sbarro/esta', 'Sbarro/ESTA member'), ('six-semaines-essai', 'Six weeks for free'), ('un-jour', 'One day'), ('un-semestre', 'One semester'), ('un-semestre-welcome', 'One semester Welcome Week')], max_length=255, verbose_name='subscription type'),
|
||||
),
|
||||
model_name="subscription",
|
||||
name="subscription_type",
|
||||
field=models.CharField(
|
||||
choices=[
|
||||
("amicale/doceo", "Amicale/DOCEO member"),
|
||||
("assidu", "Assidu member"),
|
||||
("benevoles-euroks", "Eurok's volunteer"),
|
||||
("crous", "CROUS member"),
|
||||
("cursus-alternant", "Alternating cursus"),
|
||||
("cursus-branche", "Branch cursus"),
|
||||
("cursus-tronc-commun", "Common core cursus"),
|
||||
("deux-mois-essai", "Two months for free"),
|
||||
("deux-semestres", "Two semesters"),
|
||||
("membre-honoraire", "Honorary member"),
|
||||
("reseau-ut", "UT network member"),
|
||||
("sbarro/esta", "Sbarro/ESTA member"),
|
||||
("six-semaines-essai", "Six weeks for free"),
|
||||
("un-jour", "One day"),
|
||||
("un-semestre", "One semester"),
|
||||
("un-semestre-welcome", "One semester Welcome Week"),
|
||||
],
|
||||
max_length=255,
|
||||
verbose_name="subscription type",
|
||||
),
|
||||
)
|
||||
]
|
||||
|
@ -41,74 +41,101 @@ from core.utils import get_start_of_semester
|
||||
|
||||
def validate_type(value):
|
||||
if value not in settings.SITH_SUBSCRIPTIONS.keys():
|
||||
raise ValidationError(_('Bad subscription type'))
|
||||
raise ValidationError(_("Bad subscription type"))
|
||||
|
||||
|
||||
def validate_payment(value):
|
||||
if value not in settings.SITH_SUBSCRIPTION_PAYMENT_METHOD:
|
||||
raise ValidationError(_('Bad payment method'))
|
||||
raise ValidationError(_("Bad payment method"))
|
||||
|
||||
|
||||
class Subscription(models.Model):
|
||||
member = models.ForeignKey(User, related_name='subscriptions')
|
||||
subscription_type = models.CharField(_('subscription type'),
|
||||
max_length=255,
|
||||
choices=((k, v['name']) for k, v in sorted(settings.SITH_SUBSCRIPTIONS.items())))
|
||||
subscription_start = models.DateField(_('subscription start'))
|
||||
subscription_end = models.DateField(_('subscription end'))
|
||||
payment_method = models.CharField(_('payment method'),
|
||||
max_length=255,
|
||||
choices=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD)
|
||||
location = models.CharField(choices=settings.SITH_SUBSCRIPTION_LOCATIONS,
|
||||
max_length=20, verbose_name=_('location'))
|
||||
member = models.ForeignKey(User, related_name="subscriptions")
|
||||
subscription_type = models.CharField(
|
||||
_("subscription type"),
|
||||
max_length=255,
|
||||
choices=(
|
||||
(k, v["name"]) for k, v in sorted(settings.SITH_SUBSCRIPTIONS.items())
|
||||
),
|
||||
)
|
||||
subscription_start = models.DateField(_("subscription start"))
|
||||
subscription_end = models.DateField(_("subscription end"))
|
||||
payment_method = models.CharField(
|
||||
_("payment method"),
|
||||
max_length=255,
|
||||
choices=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD,
|
||||
)
|
||||
location = models.CharField(
|
||||
choices=settings.SITH_SUBSCRIPTION_LOCATIONS,
|
||||
max_length=20,
|
||||
verbose_name=_("location"),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ['subscription_start', ]
|
||||
ordering = ["subscription_start"]
|
||||
|
||||
def clean(self):
|
||||
try:
|
||||
for s in Subscription.objects.filter(member=self.member).exclude(pk=self.pk).all():
|
||||
if s.is_valid_now() and s.subscription_end - timedelta(weeks=settings.SITH_SUBSCRIPTION_END) > date.today():
|
||||
raise ValidationError(_("You can not subscribe many time for the same period"))
|
||||
for s in (
|
||||
Subscription.objects.filter(member=self.member)
|
||||
.exclude(pk=self.pk)
|
||||
.all()
|
||||
):
|
||||
if (
|
||||
s.is_valid_now()
|
||||
and s.subscription_end
|
||||
- timedelta(weeks=settings.SITH_SUBSCRIPTION_END)
|
||||
> date.today()
|
||||
):
|
||||
raise ValidationError(
|
||||
_("You can not subscribe many time for the same period")
|
||||
)
|
||||
except: # This should not happen, because the form should have handled the data before, but sadly, it still
|
||||
# calls the model validation :'(
|
||||
# TODO see SubscriptionForm's clean method
|
||||
# calls the model validation :'(
|
||||
# TODO see SubscriptionForm's clean method
|
||||
raise ValidationError(_("Subscription error"))
|
||||
|
||||
def save(self):
|
||||
super(Subscription, self).save()
|
||||
from counter.models import Customer
|
||||
|
||||
if not Customer.objects.filter(user=self.member).exists():
|
||||
last_id = Customer.objects.count() + 1504 # Number to keep a continuity with the old site
|
||||
Customer(user=self.member, account_id=Customer.generate_account_id(last_id + 1), amount=0).save()
|
||||
form = PasswordResetForm({'email': self.member.email})
|
||||
last_id = (
|
||||
Customer.objects.count() + 1504
|
||||
) # Number to keep a continuity with the old site
|
||||
Customer(
|
||||
user=self.member,
|
||||
account_id=Customer.generate_account_id(last_id + 1),
|
||||
amount=0,
|
||||
).save()
|
||||
form = PasswordResetForm({"email": self.member.email})
|
||||
if form.is_valid():
|
||||
form.save(use_https=True, email_template_name='core/new_user_email.jinja',
|
||||
subject_template_name='core/new_user_email_subject.jinja', from_email="ae@utbm.fr")
|
||||
form.save(
|
||||
use_https=True,
|
||||
email_template_name="core/new_user_email.jinja",
|
||||
subject_template_name="core/new_user_email_subject.jinja",
|
||||
from_email="ae@utbm.fr",
|
||||
)
|
||||
self.member.make_home()
|
||||
if settings.IS_OLD_MYSQL_PRESENT:
|
||||
import MySQLdb
|
||||
|
||||
try: # Create subscription on the old site: TODO remove me!
|
||||
LOCATION = {
|
||||
"SEVENANS": 5,
|
||||
"BELFORT": 6,
|
||||
"MONTBELIARD": 9,
|
||||
"EBOUTIC": 5,
|
||||
}
|
||||
LOCATION = {"SEVENANS": 5, "BELFORT": 6, "MONTBELIARD": 9, "EBOUTIC": 5}
|
||||
TYPE = {
|
||||
'un-semestre': 0,
|
||||
'deux-semestres': 1,
|
||||
'cursus-tronc-commun': 2,
|
||||
'cursus-branche': 3,
|
||||
'membre-honoraire': 4,
|
||||
'assidu': 5,
|
||||
'amicale/doceo': 6,
|
||||
'reseau-ut': 7,
|
||||
'crous': 8,
|
||||
'sbarro/esta': 9,
|
||||
'cursus-alternant': 10,
|
||||
'welcome-semestre': 11,
|
||||
'deux-mois-essai': 12,
|
||||
"un-semestre": 0,
|
||||
"deux-semestres": 1,
|
||||
"cursus-tronc-commun": 2,
|
||||
"cursus-branche": 3,
|
||||
"membre-honoraire": 4,
|
||||
"assidu": 5,
|
||||
"amicale/doceo": 6,
|
||||
"reseau-ut": 7,
|
||||
"crous": 8,
|
||||
"sbarro/esta": 9,
|
||||
"cursus-alternant": 10,
|
||||
"welcome-semestre": 11,
|
||||
"deux-mois-essai": 12,
|
||||
}
|
||||
PAYMENT = {
|
||||
"CHECK": 1,
|
||||
@ -121,25 +148,36 @@ class Subscription(models.Model):
|
||||
|
||||
db = MySQLdb.connect(**settings.OLD_MYSQL_INFOS)
|
||||
c = db.cursor()
|
||||
c.execute("""INSERT INTO ae_cotisations (id_utilisateur, date_cotis, date_fin_cotis, mode_paiement_cotis,
|
||||
type_cotis, id_comptoir) VALUES (%s, %s, %s, %s, %s, %s)""", (self.member.id, self.subscription_start,
|
||||
self.subscription_end, PAYMENT[self.payment_method], TYPE[self.subscription_type],
|
||||
LOCATION[self.location]))
|
||||
c.execute(
|
||||
"""INSERT INTO ae_cotisations (id_utilisateur, date_cotis, date_fin_cotis, mode_paiement_cotis,
|
||||
type_cotis, id_comptoir) VALUES (%s, %s, %s, %s, %s, %s)""",
|
||||
(
|
||||
self.member.id,
|
||||
self.subscription_start,
|
||||
self.subscription_end,
|
||||
PAYMENT[self.payment_method],
|
||||
TYPE[self.subscription_type],
|
||||
LOCATION[self.location],
|
||||
),
|
||||
)
|
||||
db.commit()
|
||||
except Exception as e:
|
||||
with open(settings.BASE_DIR + "/subscription_fail.log", "a") as f:
|
||||
print("FAIL to add subscription to %s to old site" % (self.member), file=f)
|
||||
print(
|
||||
"FAIL to add subscription to %s to old site" % (self.member),
|
||||
file=f,
|
||||
)
|
||||
print("Reason: %s" % (repr(e)), file=f)
|
||||
db.rollback()
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('core:user_edit', kwargs={'user_id': self.member.pk})
|
||||
return reverse("core:user_edit", kwargs={"user_id": self.member.pk})
|
||||
|
||||
def __str__(self):
|
||||
if hasattr(self, "member") and self.member is not None:
|
||||
return self.member.username + ' - ' + str(self.pk)
|
||||
return self.member.username + " - " + str(self.pk)
|
||||
else:
|
||||
return 'No user - ' + str(self.pk)
|
||||
return "No user - " + str(self.pk)
|
||||
|
||||
@staticmethod
|
||||
def compute_start(d=None, duration=1, user=None):
|
||||
@ -176,21 +214,43 @@ class Subscription(models.Model):
|
||||
if start is None:
|
||||
start = Subscription.compute_start(duration=duration, user=user)
|
||||
|
||||
return start + relativedelta(months=round(6*duration),days=math.ceil((6*duration - round(6*duration)) * 30))
|
||||
|
||||
return start + relativedelta(
|
||||
months=round(6 * duration),
|
||||
days=math.ceil((6 * duration - round(6 * duration)) * 30),
|
||||
)
|
||||
|
||||
def can_be_edited_by(self, user):
|
||||
return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_root
|
||||
|
||||
def is_valid_now(self):
|
||||
return self.subscription_start <= date.today() and date.today() <= self.subscription_end
|
||||
return (
|
||||
self.subscription_start <= date.today()
|
||||
and date.today() <= self.subscription_end
|
||||
)
|
||||
|
||||
|
||||
def guy_test(date, duration=4):
|
||||
print(str(date) + " - " + str(duration) + " -> " + str(Subscription.compute_start(date, duration)))
|
||||
print(
|
||||
str(date)
|
||||
+ " - "
|
||||
+ str(duration)
|
||||
+ " -> "
|
||||
+ str(Subscription.compute_start(date, duration))
|
||||
)
|
||||
|
||||
|
||||
def bibou_test(duration, date=date.today()):
|
||||
print(str(date) + " - " + str(duration) + " -> " + str(Subscription.compute_end(duration, Subscription.compute_start(date, duration))))
|
||||
print(
|
||||
str(date)
|
||||
+ " - "
|
||||
+ str(duration)
|
||||
+ " -> "
|
||||
+ str(
|
||||
Subscription.compute_end(
|
||||
duration, Subscription.compute_start(date, duration)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def guy():
|
||||
@ -202,7 +262,7 @@ def guy():
|
||||
guy_test(date(2015, 2, 11))
|
||||
guy_test(date(2015, 8, 17))
|
||||
guy_test(date(2015, 9, 17))
|
||||
print('=' * 80)
|
||||
print("=" * 80)
|
||||
guy_test(date(2015, 7, 11), 1)
|
||||
guy_test(date(2015, 8, 11), 2)
|
||||
guy_test(date(2015, 2, 17), 3)
|
||||
@ -211,7 +271,7 @@ def guy():
|
||||
guy_test(date(2015, 2, 11), 2)
|
||||
guy_test(date(2015, 8, 17), 3)
|
||||
guy_test(date(2015, 9, 17), 4)
|
||||
print('=' * 80)
|
||||
print("=" * 80)
|
||||
bibou_test(1, date(2015, 2, 18))
|
||||
bibou_test(2, date(2015, 2, 18))
|
||||
bibou_test(3, date(2015, 2, 18))
|
||||
@ -220,7 +280,7 @@ def guy():
|
||||
bibou_test(2, date(2015, 9, 18))
|
||||
bibou_test(3, date(2015, 9, 18))
|
||||
bibou_test(4, date(2015, 9, 18))
|
||||
print('=' * 80)
|
||||
print("=" * 80)
|
||||
bibou_test(1, date(2000, 2, 29))
|
||||
bibou_test(2, date(2000, 2, 29))
|
||||
bibou_test(1, date(2000, 5, 31))
|
||||
|
@ -34,6 +34,7 @@ from django.core.management import call_command
|
||||
|
||||
class FakeDate(date):
|
||||
"""A fake replacement for date that can be mocked for testing."""
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
return date.__new__(date, *args, **kwargs)
|
||||
|
||||
@ -43,8 +44,7 @@ def date_mock_today(year, month, day):
|
||||
|
||||
|
||||
class SubscriptionUnitTest(TestCase):
|
||||
|
||||
@mock.patch('subscription.models.date', FakeDate)
|
||||
@mock.patch("subscription.models.date", FakeDate)
|
||||
def test_start_dates_sliding_without_start(self):
|
||||
date_mock_today(2015, 9, 18)
|
||||
d = Subscription.compute_start(duration=1)
|
||||
@ -52,12 +52,14 @@ class SubscriptionUnitTest(TestCase):
|
||||
self.assertTrue(Subscription.compute_start(duration=2) == date(2015, 9, 18))
|
||||
|
||||
def test_start_dates_sliding_with_start(self):
|
||||
self.assertTrue(Subscription.compute_start(date(2015, 5, 17), 1) ==
|
||||
date(2015, 5, 17))
|
||||
self.assertTrue(Subscription.compute_start(date(2015, 5, 17), 2) ==
|
||||
date(2015, 5, 17))
|
||||
self.assertTrue(
|
||||
Subscription.compute_start(date(2015, 5, 17), 1) == date(2015, 5, 17)
|
||||
)
|
||||
self.assertTrue(
|
||||
Subscription.compute_start(date(2015, 5, 17), 2) == date(2015, 5, 17)
|
||||
)
|
||||
|
||||
@mock.patch('subscription.models.date', FakeDate)
|
||||
@mock.patch("subscription.models.date", FakeDate)
|
||||
def test_start_dates_not_sliding_without_start(self):
|
||||
date_mock_today(2015, 5, 17)
|
||||
self.assertTrue(Subscription.compute_start(duration=3) == date(2015, 2, 15))
|
||||
@ -67,10 +69,14 @@ class SubscriptionUnitTest(TestCase):
|
||||
self.assertTrue(Subscription.compute_start(duration=4) == date(2015, 8, 15))
|
||||
|
||||
def test_start_dates_not_sliding_with_start(self):
|
||||
self.assertTrue(Subscription.compute_start(date(2015, 5, 17), 3) == date(2015, 2, 15))
|
||||
self.assertTrue(Subscription.compute_start(date(2015, 1, 11), 3) == date(2014, 8, 15))
|
||||
self.assertTrue(
|
||||
Subscription.compute_start(date(2015, 5, 17), 3) == date(2015, 2, 15)
|
||||
)
|
||||
self.assertTrue(
|
||||
Subscription.compute_start(date(2015, 1, 11), 3) == date(2014, 8, 15)
|
||||
)
|
||||
|
||||
@mock.patch('subscription.models.date', FakeDate)
|
||||
@mock.patch("subscription.models.date", FakeDate)
|
||||
def test_end_dates_sliding(self):
|
||||
date_mock_today(2015, 9, 18)
|
||||
d = Subscription.compute_end(2)
|
||||
@ -78,7 +84,7 @@ class SubscriptionUnitTest(TestCase):
|
||||
d = Subscription.compute_end(1)
|
||||
self.assertTrue(d == date(2016, 3, 18))
|
||||
|
||||
@mock.patch('subscription.models.date', FakeDate)
|
||||
@mock.patch("subscription.models.date", FakeDate)
|
||||
def test_end_dates_not_sliding_without_start(self):
|
||||
date_mock_today(2015, 9, 18)
|
||||
d = Subscription.compute_end(duration=3)
|
||||
@ -86,7 +92,7 @@ class SubscriptionUnitTest(TestCase):
|
||||
d = Subscription.compute_end(duration=4)
|
||||
self.assertTrue(d == date(2017, 8, 15))
|
||||
|
||||
@mock.patch('subscription.models.date', FakeDate)
|
||||
@mock.patch("subscription.models.date", FakeDate)
|
||||
def test_end_dates_with_float(self):
|
||||
date_mock_today(2015, 9, 18)
|
||||
d = Subscription.compute_end(duration=0.33)
|
||||
@ -102,6 +108,7 @@ class SubscriptionUnitTest(TestCase):
|
||||
d = Subscription.compute_end(duration=4, start=date(2015, 9, 18))
|
||||
self.assertTrue(d == date(2017, 9, 18))
|
||||
|
||||
|
||||
class SubscriptionIntegrationTest(TestCase):
|
||||
def setUp(self):
|
||||
call_command("populate")
|
||||
@ -109,98 +116,130 @@ class SubscriptionIntegrationTest(TestCase):
|
||||
|
||||
def test_duration_two_months(self):
|
||||
|
||||
s = Subscription(member=User.objects.filter(pk=self.user.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[3],
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
|
||||
s = Subscription(
|
||||
member=User.objects.filter(pk=self.user.pk).first(),
|
||||
subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[3],
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0],
|
||||
)
|
||||
s.subscription_start = date(2017, 8, 29)
|
||||
s.subscription_end = s.compute_end(duration=0.33,
|
||||
start=s.subscription_start)
|
||||
s.subscription_end = s.compute_end(duration=0.33, start=s.subscription_start)
|
||||
s.save()
|
||||
self.assertTrue(s.subscription_end == date(2017, 10, 29))
|
||||
|
||||
def test_duration_two_months(self):
|
||||
|
||||
s = Subscription(member=User.objects.filter(pk=self.user.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[3],
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
|
||||
s = Subscription(
|
||||
member=User.objects.filter(pk=self.user.pk).first(),
|
||||
subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[3],
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0],
|
||||
)
|
||||
s.subscription_start = date(2017, 8, 29)
|
||||
s.subscription_end = s.compute_end(duration=settings.SITH_SUBSCRIPTIONS['un-jour']['duration'],
|
||||
start=s.subscription_start)
|
||||
s.subscription_end = s.compute_end(
|
||||
duration=settings.SITH_SUBSCRIPTIONS["un-jour"]["duration"],
|
||||
start=s.subscription_start,
|
||||
)
|
||||
s.save()
|
||||
self.assertTrue(s.subscription_end == date(2017, 8, 30))
|
||||
|
||||
def test_duration_three_months(self):
|
||||
|
||||
s = Subscription(member=User.objects.filter(pk=self.user.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[3],
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
|
||||
s = Subscription(
|
||||
member=User.objects.filter(pk=self.user.pk).first(),
|
||||
subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[3],
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0],
|
||||
)
|
||||
s.subscription_start = date(2017, 8, 29)
|
||||
s.subscription_end = s.compute_end(duration=0.5,
|
||||
start=s.subscription_start)
|
||||
s.subscription_end = s.compute_end(duration=0.5, start=s.subscription_start)
|
||||
s.save()
|
||||
self.assertTrue(s.subscription_end == date(2017, 11, 29))
|
||||
|
||||
def test_duration_four_months(self):
|
||||
|
||||
s = Subscription(member=User.objects.filter(pk=self.user.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[3],
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
|
||||
s = Subscription(
|
||||
member=User.objects.filter(pk=self.user.pk).first(),
|
||||
subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[3],
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0],
|
||||
)
|
||||
s.subscription_start = date(2017, 8, 29)
|
||||
s.subscription_end = s.compute_end(duration=0.67,
|
||||
start=s.subscription_start)
|
||||
s.subscription_end = s.compute_end(duration=0.67, start=s.subscription_start)
|
||||
s.save()
|
||||
self.assertTrue(s.subscription_end == date(2017, 12, 30))
|
||||
|
||||
|
||||
def test_duration_six_weeks(self):
|
||||
|
||||
s = Subscription(member=User.objects.filter(pk=self.user.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[3],
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
|
||||
s = Subscription(
|
||||
member=User.objects.filter(pk=self.user.pk).first(),
|
||||
subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[3],
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0],
|
||||
)
|
||||
s.subscription_start = date(2018, 9, 1)
|
||||
s.subscription_end = s.compute_end(duration=0.23,
|
||||
start=s.subscription_start)
|
||||
s.subscription_end = s.compute_end(duration=0.23, start=s.subscription_start)
|
||||
s.save()
|
||||
self.assertTrue(s.subscription_end == date(2018, 10, 13))
|
||||
|
||||
@mock.patch('subscription.models.date', FakeDate)
|
||||
@mock.patch("subscription.models.date", FakeDate)
|
||||
def test_dates_sliding_with_subscribed_user(self):
|
||||
user = User.objects.filter(pk=self.user.pk).first()
|
||||
s = Subscription(member=user, subscription_type='deux-semestres',
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
|
||||
s = Subscription(
|
||||
member=user,
|
||||
subscription_type="deux-semestres",
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0],
|
||||
)
|
||||
s.subscription_start = date(2015, 8, 29)
|
||||
s.subscription_end = s.compute_end(duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]['duration'],
|
||||
start=s.subscription_start)
|
||||
s.subscription_end = s.compute_end(
|
||||
duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]["duration"],
|
||||
start=s.subscription_start,
|
||||
)
|
||||
s.save()
|
||||
self.assertTrue(s.subscription_end == date(2016, 8, 29))
|
||||
date_mock_today(2016, 8, 25)
|
||||
d = Subscription.compute_end(duration=settings.SITH_SUBSCRIPTIONS['deux-semestres']['duration'],
|
||||
user=user)
|
||||
|
||||
d = Subscription.compute_end(
|
||||
duration=settings.SITH_SUBSCRIPTIONS["deux-semestres"]["duration"],
|
||||
user=user,
|
||||
)
|
||||
|
||||
self.assertTrue(d == date(2017, 8, 29))
|
||||
|
||||
@mock.patch('subscription.models.date', FakeDate)
|
||||
@mock.patch("subscription.models.date", FakeDate)
|
||||
def test_dates_renewal_sliding_during_two_free_monthes(self):
|
||||
user = User.objects.filter(pk=self.user.pk).first()
|
||||
s = Subscription(member=user, subscription_type='deux-mois-essai',
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
|
||||
s = Subscription(
|
||||
member=user,
|
||||
subscription_type="deux-mois-essai",
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0],
|
||||
)
|
||||
s.subscription_start = date(2015, 8, 29)
|
||||
s.subscription_end = s.compute_end(duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]['duration'],
|
||||
start=s.subscription_start)
|
||||
s.subscription_end = s.compute_end(
|
||||
duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]["duration"],
|
||||
start=s.subscription_start,
|
||||
)
|
||||
s.save()
|
||||
self.assertTrue(s.subscription_end == date(2015, 10, 29))
|
||||
date_mock_today(2015, 9, 25)
|
||||
d = Subscription.compute_end(duration=settings.SITH_SUBSCRIPTIONS['deux-semestres']['duration'],
|
||||
user=user)
|
||||
d = Subscription.compute_end(
|
||||
duration=settings.SITH_SUBSCRIPTIONS["deux-semestres"]["duration"],
|
||||
user=user,
|
||||
)
|
||||
self.assertTrue(d == date(2016, 10, 29))
|
||||
|
||||
@mock.patch('subscription.models.date', FakeDate)
|
||||
@mock.patch("subscription.models.date", FakeDate)
|
||||
def test_dates_renewal_sliding_after_two_free_monthes(self):
|
||||
user = User.objects.filter(pk=self.user.pk).first()
|
||||
s = Subscription(member=user, subscription_type='deux-mois-essai',
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
|
||||
s = Subscription(
|
||||
member=user,
|
||||
subscription_type="deux-mois-essai",
|
||||
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0],
|
||||
)
|
||||
s.subscription_start = date(2015, 8, 29)
|
||||
s.subscription_end = s.compute_end(duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]['duration'],
|
||||
start=s.subscription_start)
|
||||
s.subscription_end = s.compute_end(
|
||||
duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]["duration"],
|
||||
start=s.subscription_start,
|
||||
)
|
||||
s.save()
|
||||
self.assertTrue(s.subscription_end == date(2015, 10, 29))
|
||||
date_mock_today(2015, 11, 5)
|
||||
d = Subscription.compute_end(duration=settings.SITH_SUBSCRIPTIONS['deux-semestres']['duration'],
|
||||
user=user)
|
||||
d = Subscription.compute_end(
|
||||
duration=settings.SITH_SUBSCRIPTIONS["deux-semestres"]["duration"],
|
||||
user=user,
|
||||
)
|
||||
self.assertTrue(d == date(2016, 11, 5))
|
||||
|
||||
|
@ -28,6 +28,6 @@ from subscription.views import *
|
||||
|
||||
urlpatterns = [
|
||||
# Subscription views
|
||||
url(r'^$', NewSubscription.as_view(), name='subscription'),
|
||||
url(r'stats', SubscriptionsStatsView.as_view(), name='stats'),
|
||||
url(r"^$", NewSubscription.as_view(), name="subscription"),
|
||||
url(r"stats", SubscriptionsStatsView.as_view(), name="stats"),
|
||||
]
|
||||
|
@ -40,29 +40,40 @@ from core.models import User
|
||||
class SelectionDateForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SelectionDateForm, self).__init__(*args, **kwargs)
|
||||
self.fields['start_date'] = forms.DateTimeField(
|
||||
['%Y-%m-%d %H:%M:%S'], label=_("Start date"),
|
||||
widget=SelectDateTime, required=True)
|
||||
self.fields['end_date'] = forms.DateTimeField(
|
||||
['%Y-%m-%d %H:%M:%S'], label=_("End date"),
|
||||
widget=SelectDateTime, required=True)
|
||||
self.fields["start_date"] = forms.DateTimeField(
|
||||
["%Y-%m-%d %H:%M:%S"],
|
||||
label=_("Start date"),
|
||||
widget=SelectDateTime,
|
||||
required=True,
|
||||
)
|
||||
self.fields["end_date"] = forms.DateTimeField(
|
||||
["%Y-%m-%d %H:%M:%S"],
|
||||
label=_("End date"),
|
||||
widget=SelectDateTime,
|
||||
required=True,
|
||||
)
|
||||
|
||||
|
||||
class SubscriptionForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Subscription
|
||||
fields = ['member', 'subscription_type', 'payment_method', 'location']
|
||||
member = AutoCompleteSelectField('users', required=False, help_text=None)
|
||||
fields = ["member", "subscription_type", "payment_method", "location"]
|
||||
|
||||
member = AutoCompleteSelectField("users", required=False, help_text=None)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SubscriptionForm, self).__init__(*args, **kwargs)
|
||||
# Add fields to allow basic user creation
|
||||
self.fields['last_name'] = forms.CharField(max_length=User._meta.get_field('last_name').max_length)
|
||||
self.fields['first_name'] = forms.CharField(max_length=User._meta.get_field('first_name').max_length)
|
||||
self.fields['email'] = forms.EmailField()
|
||||
self.fields.move_to_end('subscription_type')
|
||||
self.fields.move_to_end('payment_method')
|
||||
self.fields.move_to_end('location')
|
||||
self.fields["last_name"] = forms.CharField(
|
||||
max_length=User._meta.get_field("last_name").max_length
|
||||
)
|
||||
self.fields["first_name"] = forms.CharField(
|
||||
max_length=User._meta.get_field("first_name").max_length
|
||||
)
|
||||
self.fields["email"] = forms.EmailField()
|
||||
self.fields.move_to_end("subscription_type")
|
||||
self.fields.move_to_end("payment_method")
|
||||
self.fields.move_to_end("location")
|
||||
|
||||
def clean_member(self):
|
||||
subscriber = self.cleaned_data.get("member")
|
||||
@ -72,19 +83,26 @@ class SubscriptionForm(forms.ModelForm):
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(SubscriptionForm, self).clean()
|
||||
if (cleaned_data.get("member") is None
|
||||
and "last_name" not in self.errors.as_data()
|
||||
and "first_name" not in self.errors.as_data()
|
||||
and "email" not in self.errors.as_data()):
|
||||
if (
|
||||
cleaned_data.get("member") is None
|
||||
and "last_name" not in self.errors.as_data()
|
||||
and "first_name" not in self.errors.as_data()
|
||||
and "email" not in self.errors.as_data()
|
||||
):
|
||||
self.errors.pop("member", None)
|
||||
if self.errors:
|
||||
return cleaned_data
|
||||
if User.objects.filter(email=cleaned_data.get("email")).first() is not None:
|
||||
self.add_error("email", ValidationError(_("A user with that email address already exists")))
|
||||
self.add_error(
|
||||
"email",
|
||||
ValidationError(_("A user with that email address already exists")),
|
||||
)
|
||||
else:
|
||||
u = User(last_name=self.cleaned_data.get("last_name"),
|
||||
first_name=self.cleaned_data.get("first_name"),
|
||||
email=self.cleaned_data.get("email"))
|
||||
u = User(
|
||||
last_name=self.cleaned_data.get("last_name"),
|
||||
first_name=self.cleaned_data.get("first_name"),
|
||||
email=self.cleaned_data.get("email"),
|
||||
)
|
||||
u.generate_username()
|
||||
u.set_password(str(random.randrange(1000000, 10000000)))
|
||||
u.save()
|
||||
@ -96,12 +114,16 @@ class SubscriptionForm(forms.ModelForm):
|
||||
if cleaned_data.get("member") is None:
|
||||
# This should be handled here, but it is done in the Subscription model's clean method
|
||||
# TODO investigate why!
|
||||
raise ValidationError(_("You must either choose an existing user or create a new one properly"))
|
||||
raise ValidationError(
|
||||
_(
|
||||
"You must either choose an existing user or create a new one properly"
|
||||
)
|
||||
)
|
||||
return cleaned_data
|
||||
|
||||
|
||||
class NewSubscription(CreateView):
|
||||
template_name = 'subscription/subscription.jinja'
|
||||
template_name = "subscription/subscription.jinja"
|
||||
form_class = SubscriptionForm
|
||||
|
||||
def dispatch(self, request, *arg, **kwargs):
|
||||
@ -111,18 +133,26 @@ class NewSubscription(CreateView):
|
||||
raise PermissionDenied
|
||||
|
||||
def get_initial(self):
|
||||
if 'member' in self.request.GET.keys():
|
||||
return {'member': self.request.GET['member'], 'subscription_type': 'deux-semestres'}
|
||||
return {'subscription_type': 'deux-semestres'}
|
||||
if "member" in self.request.GET.keys():
|
||||
return {
|
||||
"member": self.request.GET["member"],
|
||||
"subscription_type": "deux-semestres",
|
||||
}
|
||||
return {"subscription_type": "deux-semestres"}
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.subscription_start = Subscription.compute_start(
|
||||
duration=settings.SITH_SUBSCRIPTIONS[form.instance.subscription_type]['duration'],
|
||||
user=form.instance.member)
|
||||
duration=settings.SITH_SUBSCRIPTIONS[form.instance.subscription_type][
|
||||
"duration"
|
||||
],
|
||||
user=form.instance.member,
|
||||
)
|
||||
form.instance.subscription_end = Subscription.compute_end(
|
||||
duration=settings.SITH_SUBSCRIPTIONS[form.instance.subscription_type]['duration'],
|
||||
duration=settings.SITH_SUBSCRIPTIONS[form.instance.subscription_type][
|
||||
"duration"
|
||||
],
|
||||
start=form.instance.subscription_start,
|
||||
user=form.instance.member
|
||||
user=form.instance.member,
|
||||
)
|
||||
return super(NewSubscription, self).form_valid(form)
|
||||
|
||||
@ -133,41 +163,41 @@ class SubscriptionsStatsView(FormView):
|
||||
|
||||
def dispatch(self, request, *arg, **kwargs):
|
||||
import datetime
|
||||
|
||||
self.start_date = datetime.datetime.today()
|
||||
self.end_date = self.start_date
|
||||
res = super(SubscriptionsStatsView, self).dispatch(
|
||||
request, *arg, **kwargs)
|
||||
res = super(SubscriptionsStatsView, self).dispatch(request, *arg, **kwargs)
|
||||
if request.user.is_root or request.user.is_board_member:
|
||||
return res
|
||||
raise PermissionDenied
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.form = self.get_form()
|
||||
self.start_date = self.form['start_date']
|
||||
self.end_date = self.form['end_date']
|
||||
res = super(SubscriptionsStatsView, self).post(
|
||||
request, *args, **kwargs)
|
||||
self.start_date = self.form["start_date"]
|
||||
self.end_date = self.form["end_date"]
|
||||
res = super(SubscriptionsStatsView, self).post(request, *args, **kwargs)
|
||||
if request.user.is_root or request.user.is_board_member:
|
||||
return res
|
||||
raise PermissionDenied
|
||||
|
||||
def get_initial(self):
|
||||
init = {
|
||||
'start_date': self.start_date.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'end_date': self.end_date.strftime('%Y-%m-%d %H:%M:%S')
|
||||
"start_date": self.start_date.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"end_date": self.end_date.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
}
|
||||
return init
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
from subscription.models import Subscription
|
||||
|
||||
kwargs = super(SubscriptionsStatsView, self).get_context_data(**kwargs)
|
||||
kwargs['subscriptions_total'] = Subscription.objects.filter(
|
||||
subscription_end__gte=self.end_date,
|
||||
subscription_start__lte=self.start_date)
|
||||
kwargs['subscriptions_types'] = settings.SITH_SUBSCRIPTIONS
|
||||
kwargs['payment_types'] = settings.SITH_COUNTER_PAYMENT_METHOD
|
||||
kwargs['locations'] = settings.SITH_SUBSCRIPTION_LOCATIONS
|
||||
kwargs["subscriptions_total"] = Subscription.objects.filter(
|
||||
subscription_end__gte=self.end_date, subscription_start__lte=self.start_date
|
||||
)
|
||||
kwargs["subscriptions_types"] = settings.SITH_SUBSCRIPTIONS
|
||||
kwargs["payment_types"] = settings.SITH_COUNTER_PAYMENT_METHOD
|
||||
kwargs["locations"] = settings.SITH_SUBSCRIPTION_LOCATIONS
|
||||
return kwargs
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return reverse_lazy('subscriptions:stats')
|
||||
return reverse_lazy("subscriptions:stats")
|
||||
|
Reference in New Issue
Block a user