Commit e4727e1f authored by David Haynes's avatar David Haynes 🙆

Remove promotion / deletion logic

Closes #91
Closes #92
parent 1672d971
Pipeline #3729 passed with stage
in 1 minute and 4 seconds
...@@ -185,8 +185,6 @@ class ScheduleAdmin(admin.ModelAdmin): ...@@ -185,8 +185,6 @@ class ScheduleAdmin(admin.ModelAdmin):
# Pair valid_start and valid_end together on the same line # Pair valid_start and valid_end together on the same line
("valid_start", "valid_end"), ("valid_start", "valid_end"),
"twenty_four_hours", "twenty_four_hours",
"schedule_for_removal",
"promote_to_main",
) )
}, },
), ),
......
# Generated by Django 2.0.10 on 2019-01-26 20:35
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('api', '0003_auto_20190126_1321'),
]
operations = [
migrations.RemoveField(
model_name='schedule',
name='promote_to_main',
),
migrations.RemoveField(
model_name='schedule',
name='schedule_for_removal',
),
]
...@@ -208,25 +208,6 @@ class Facility(TimeStampedModel): ...@@ -208,25 +208,6 @@ class Facility(TimeStampedModel):
# If no special schedule is in effect then check the main_schedule # If no special schedule is in effect then check the main_schedule
return self.main_schedule.is_open_now() return self.main_schedule.is_open_now()
def clean_schedules(self):
"""
Loop through every special_schedule and remove entries that have
expired as well as promote special schedules to main if necessary.
"""
for special_schedule in self.special_schedules.all():
if (
special_schedule.valid_end is not None
and special_schedule.valid_end < timezone.now()
and special_schedule.schedule_for_removal
):
self.special_schedules.remove(special_schedule)
elif special_schedule.promote_to_main:
if (
special_schedule.valid_start < timezone.now()
and special_schedule.valid_end >= timezone.now()
):
self.main_schedule = special_schedule
class Meta: class Meta:
verbose_name = "facility" verbose_name = "facility"
verbose_name_plural = "facilities" verbose_name_plural = "facilities"
...@@ -274,22 +255,6 @@ class Schedule(TimeStampedModel): ...@@ -274,22 +255,6 @@ class Schedule(TimeStampedModel):
help_text="Toggle to True if the Facility is open 24 hours. You do not need to specify any Open Times, it will always be displayed as open.", help_text="Toggle to True if the Facility is open 24 hours. You do not need to specify any Open Times, it will always be displayed as open.",
) )
# Boolean for if this schedule should never be removed.
schedule_for_removal = models.BooleanField(
"Schedule for removal?",
blank=False,
default=True,
help_text="Toggle to False if the schedule should never be removed in the backend. By default, all schedules are automatically deleted after they have expired.",
)
# Boolean for if this schedule should become the main schedule at the point
# it goes live
promote_to_main = models.BooleanField(
"Schedule for promotion?",
blank=False,
default=False,
help_text="Upon the start of the schedule, it will be promoted to become the main schedule of the Facility it is attached to rather than a special schedule.",
)
def is_open_now(self): def is_open_now(self):
""" """
Return true if this schedule is open right now. Return true if this schedule is open right now.
......
...@@ -87,8 +87,6 @@ class ScheduleSerializer(serializers.ModelSerializer): ...@@ -87,8 +87,6 @@ class ScheduleSerializer(serializers.ModelSerializer):
"valid_start", "valid_start",
"valid_end", "valid_end",
"twenty_four_hours", "twenty_four_hours",
"schedule_for_removal",
"promote_to_main",
) )
......
...@@ -397,12 +397,10 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet): ...@@ -397,12 +397,10 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
"main_schedule__valid_start", "main_schedule__valid_start",
"main_schedule__valid_end", "main_schedule__valid_end",
"main_schedule__twenty_four_hours", "main_schedule__twenty_four_hours",
"main_schedule__schedule_for_removal",
"special_schedules__name", "special_schedules__name",
"special_schedules__valid_start", "special_schedules__valid_start",
"special_schedules__valid_end", "special_schedules__valid_end",
"special_schedules__twenty_four_hours", "special_schedules__twenty_four_hours",
"special_schedules__schedule_for_removal",
) )
# Associate a serializer with the ViewSet # Associate a serializer with the ViewSet
...@@ -429,10 +427,6 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet): ...@@ -429,10 +427,6 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
# Define ?closed_now # Define ?closed_now
closed_now = self.request.query_params.get("closed_now", None) closed_now = self.request.query_params.get("closed_now", None)
# Clean the schedules in every Facility
# for facility in Facility.objects.all():
# facility.clean_schedules()
if open_now is not None: if open_now is not None:
open_now = [ open_now = [
facility.pk for facility in Facility.objects.all() if facility.is_open() facility.pk for facility in Facility.objects.all() if facility.is_open()
...@@ -512,8 +506,6 @@ class ScheduleViewSet(viewsets.ModelViewSet): ...@@ -512,8 +506,6 @@ class ScheduleViewSet(viewsets.ModelViewSet):
"valid_start", "valid_start",
"valid_end", "valid_end",
"twenty_four_hours", "twenty_four_hours",
"schedule_for_removal",
"promote_to_main",
) )
# Associate a serializer with the ViewSet # Associate a serializer with the ViewSet
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment