From daefd62f962fdf8db8e270a7d0fe1b99a43eff87 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Mon, 22 Jun 2020 10:54:09 +0200 Subject: [PATCH] add duration to eventsession constraints --- ...ssion_constraint_and_missing_migrations.py | 19 ++++++++++++++++++- src/program/models.py | 6 ++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/program/migrations/0095_add_eventsession_constraint_and_missing_migrations.py b/src/program/migrations/0095_add_eventsession_constraint_and_missing_migrations.py index 36112bae..41b9dafb 100644 --- a/src/program/migrations/0095_add_eventsession_constraint_and_missing_migrations.py +++ b/src/program/migrations/0095_add_eventsession_constraint_and_missing_migrations.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.3 on 2020-06-22 00:06 +# Generated by Django 3.0.3 on 2020-06-22 08:51 import django.contrib.postgres.constraints from django.db import migrations, models @@ -11,6 +11,10 @@ class Migration(migrations.Migration): ] operations = [ + migrations.RemoveConstraint( + model_name="eventsession", + name="prevent_event_session_event_type_event_location_overlaps", + ), migrations.AlterField( model_name="event", name="duration_minutes", @@ -32,8 +36,21 @@ class Migration(migrations.Migration): model_name="eventsession", constraint=django.contrib.postgres.constraints.ExclusionConstraint( expressions=[ + ("when", "&&"), ("event_location", "="), ("event_type", "="), + ("event_duration_minutes", "="), + ], + name="prevent_event_session_event_type_event_location_overlaps", + ), + ), + migrations.AddConstraint( + model_name="eventsession", + constraint=django.contrib.postgres.constraints.ExclusionConstraint( + expressions=[ + ("event_location", "="), + ("event_type", "="), + ("event_duration_minutes", "="), ("when", "-|-"), ], name="prevent_adjacent_eventsessions", diff --git a/src/program/models.py b/src/program/models.py index 30b64fa3..ace17289 100644 --- a/src/program/models.py +++ b/src/program/models.py @@ -833,21 +833,23 @@ class EventSession(CampRelatedModel): class Meta: ordering = ["when", "event_type", "event_location"] constraints = [ - # We do not want overlapping sessions for the same EventType/EventLocation combo. + # We do not want overlapping sessions for the same EventType/EventLocation/duration combo. ExclusionConstraint( name="prevent_event_session_event_type_event_location_overlaps", expressions=[ ("when", RangeOperators.OVERLAPS), ("event_location", RangeOperators.EQUAL), ("event_type", RangeOperators.EQUAL), + ("event_duration_minutes", RangeOperators.EQUAL), ], ), - # we do not want adjacent sessions for the same type and location + # we do not want adjacent sessions for the same type and location and duration ExclusionConstraint( name="prevent_adjacent_eventsessions", expressions=[ ("event_location", RangeOperators.EQUAL), ("event_type", RangeOperators.EQUAL), + ("event_duration_minutes", RangeOperators.EQUAL), ("when", RangeOperators.ADJACENT_TO), ], ),