Verified Commit 663a2875 authored by David Haynes's avatar David Haynes 🙆
Browse files

Support 24 hour schedules

- It's a boolean that if set True, will always return that the Facility is open.
parent 0bd32ef1
Pipeline #1447 passed with stage
in 1 minute and 30 seconds
......@@ -62,7 +62,8 @@ class ScheduleAdmin(admin.ModelAdmin):
'fields': ('name',
# Pair valid_start and valid_end together on the same
# line
('valid_start', 'valid_end'))
('valid_start', 'valid_end'),
......@@ -112,11 +112,8 @@ class Facility(TimeStampedModel):
special_schedules = models.ManyToManyField('Schedule',
help_text="""This schedule will
come into effect
only for its
specified duration.
help_text="This schedule will come into effect only for its specified duration.")
# URL, if it exists, to the Tapingo page that is associated with this
# facility
tapingo_url = models.URLField(blank=True, validators=[RegexValidator(regex='^https:\/\/\/',
......@@ -191,18 +188,24 @@ class Schedule(TimeStampedModel):
# The start date of the schedule
# (inclusive)
valid_start = models.DateField('Start Date', null=True, blank=True,
help_text="""Date that this schedule goes
into effect""")
help_text="Date that this schedule goes into effect")
# The end date of the schedule
# (inclusive)
valid_end = models.DateField('End Date', null=True, blank=True,
help_text="""Last day that this schedule is
in effect""")
help_text="Last day that this schedule is in effect")
# Boolean for if this schedule is 24 hours
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.")
def is_open_now(self):
Return true if this schedule is open right now.
# If the schedule is a 24 hour one, then it's open.
if self.twenty_four_hours:
return True
# Otherwise let's check if it's open.
# Loop through all the open times that correspond to this schedule
for open_time in OpenTime.objects.filter(schedule=self):
# If the current time we are looking at is open, then the schedule
......@@ -65,7 +65,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')
class FacilitySerializer(serializers.HyperlinkedModelSerializer):
......@@ -374,9 +374,11 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
# Associate a serializer with the ViewSet
......@@ -481,6 +483,7 @@ class ScheduleViewSet(viewsets.ModelViewSet):
# 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