Verified Commit 38d09c05 authored by David Haynes's avatar David Haynes 🙆
Browse files

Add support for non expiring schedules

- by default, remove all schedules
- but of you click this button then this behavior will not happen
parent 89e3f4f1
Pipeline #1716 passed with stage
in 2 minutes and 25 seconds
......@@ -63,7 +63,8 @@ class ScheduleAdmin(admin.ModelAdmin):
# Pair valid_start and valid_end together on the same
# line
('valid_start', 'valid_end'),
'twenty_four_hours')
'twenty_four_hours',
'schedule_for_removal')
}),
)
......
......@@ -162,7 +162,7 @@ class Facility(TimeStampedModel):
"""
for special_schedule in self.special_schedules.all():
# If it ends before today
if special_schedule.valid_end < datetime.date.today():
if special_schedule.valid_end < datetime.date.today() and special_schedule.schedule_for_removal:
self.special_schedules.remove(special_schedule)
class Meta:
......@@ -198,6 +198,10 @@ class Schedule(TimeStampedModel):
twenty_four_hours = models.BooleanField('24 hour schedule?', blank=True,
default=False, 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.")
def is_open_now(self):
"""
Return true if this schedule is open right now.
......
......@@ -66,7 +66,7 @@ class ScheduleSerializer(serializers.ModelSerializer):
model = Schedule
# List the fields that we are serializing
fields = ('id', 'open_times', 'modified', 'name', 'valid_start',
'valid_end', 'twenty_four_hours')
'valid_end', 'twenty_four_hours', 'schedule_for_removal')
class FacilitySerializer(serializers.HyperlinkedModelSerializer):
"""
......
......@@ -376,10 +376,12 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
'main_schedule__valid_start',
'main_schedule__valid_end',
'main_schedule__twenty_four_hours',
'main_schedule__schedule_for_removal',
'special_schedules__name',
'special_schedules__valid_start',
'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
......@@ -485,7 +487,8 @@ class ScheduleViewSet(viewsets.ModelViewSet):
'name',
'valid_start',
'valid_end',
'twenty_four_hours'
'twenty_four_hours',
'schedule_for_removal'
)
# Associate a serializer with the ViewSet
......@@ -509,7 +512,7 @@ class ScheduleViewSet(viewsets.ModelViewSet):
for schedule in Schedule.objects.all()
# If the schedule ended before today
if schedule.valid_end and schedule.valid_start
if schedule.valid_end < datetime.today()
if schedule.valid_end < datetime.datetime.now(schedule.valid_end.tzinfo)
]
# Return all Schedule objects that have not expired
return Schedule.objects.exclude(pk__in=filter_old_schedules)
......
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