2016-10-10 16:56:40 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2016-12-21 04:05:04 +01:00
|
|
|
from datetime import timedelta
|
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
from django.db import migrations, models
|
|
|
|
from django.utils import timezone
|
|
|
|
|
2016-12-21 04:05:04 +01:00
|
|
|
|
|
|
|
def forwards_func(apps, schema_editor):
|
|
|
|
SpectacleRevente = apps.get_model("bda", "SpectacleRevente")
|
|
|
|
|
|
|
|
for revente in SpectacleRevente.objects.all():
|
|
|
|
is_expired = timezone.now() > revente.date_tirage()
|
2020-08-28 18:00:54 +02:00
|
|
|
is_direct = (
|
|
|
|
revente.attribution.spectacle.date >= revente.date
|
|
|
|
and timezone.now() > revente.date + timedelta(minutes=15)
|
2018-10-06 12:35:49 +02:00
|
|
|
)
|
2016-12-21 04:05:04 +01:00
|
|
|
revente.shotgun = is_expired or is_direct
|
|
|
|
revente.save()
|
2016-10-10 16:56:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
dependencies = [("bda", "0009_revente")]
|
2016-10-10 16:56:40 +02:00
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.AddField(
|
2018-10-06 12:35:49 +02:00
|
|
|
model_name="spectaclerevente",
|
|
|
|
name="shotgun",
|
|
|
|
field=models.BooleanField(
|
|
|
|
default=False, verbose_name="Disponible imm\xe9diatement"
|
|
|
|
),
|
2016-10-10 16:56:40 +02:00
|
|
|
),
|
2016-12-21 04:05:04 +01:00
|
|
|
migrations.RunPython(forwards_func, migrations.RunPython.noop),
|
2016-10-10 16:56:40 +02:00
|
|
|
]
|