Replace persisted event statuses with publication and cancellation flags, and compute public lifecycle labels from event timing and registration capacity. Keep filters, registration checks, and profile responses aligned with the derived status.
63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
from django.db import migrations, models
|
|
from django.db.models import F
|
|
|
|
|
|
def copy_legacy_event_state(apps, schema_editor):
|
|
Event = apps.get_model("events", "Event")
|
|
events = Event._base_manager.all()
|
|
events.update(legacy_status=F("status"))
|
|
events.filter(status__in=["published", "completed"]).update(
|
|
is_published=True,
|
|
is_cancelled=False,
|
|
)
|
|
events.filter(status="cancelled").update(
|
|
is_published=True,
|
|
is_cancelled=True,
|
|
)
|
|
|
|
|
|
def restore_legacy_event_state(apps, schema_editor):
|
|
Event = apps.get_model("events", "Event")
|
|
Event._base_manager.update(status=F("legacy_status"))
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
("events", "0018_registrationnotification_reg_notif_pending_idx"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AddField(
|
|
model_name="event",
|
|
name="is_published",
|
|
field=models.BooleanField(default=False),
|
|
),
|
|
migrations.AddField(
|
|
model_name="event",
|
|
name="is_cancelled",
|
|
field=models.BooleanField(default=False),
|
|
),
|
|
migrations.AddField(
|
|
model_name="event",
|
|
name="legacy_status",
|
|
field=models.CharField(max_length=10, null=True),
|
|
),
|
|
migrations.RunPython(copy_legacy_event_state, restore_legacy_event_state),
|
|
migrations.RemoveIndex(
|
|
model_name="event",
|
|
name="events_even_status_189ced_idx",
|
|
),
|
|
migrations.RemoveField(
|
|
model_name="event",
|
|
name="status",
|
|
),
|
|
migrations.RemoveField(
|
|
model_name="event",
|
|
name="legacy_status",
|
|
),
|
|
migrations.AddIndex(
|
|
model_name="event",
|
|
index=models.Index(fields=["is_published", "start_time"], name="event_pub_start_idx"),
|
|
),
|
|
]
|