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
...@@ -62,7 +62,8 @@ class ScheduleAdmin(admin.ModelAdmin): ...@@ -62,7 +62,8 @@ class ScheduleAdmin(admin.ModelAdmin):
'fields': ('name', 'fields': ('name',
# Pair valid_start and valid_end together on the same # Pair valid_start and valid_end together on the same
# line # line
('valid_start', 'valid_end')) ('valid_start', 'valid_end'),
'twenty_four_hours')
}), }),
) )
......
...@@ -112,11 +112,8 @@ class Facility(TimeStampedModel): ...@@ -112,11 +112,8 @@ class Facility(TimeStampedModel):
special_schedules = models.ManyToManyField('Schedule', special_schedules = models.ManyToManyField('Schedule',
related_name='facility_special', related_name='facility_special',
blank=True, blank=True,
help_text="""This schedule will help_text="This schedule will come into effect only for its specified duration.")
come into effect
only for its
specified duration.
""")
# URL, if it exists, to the Tapingo page that is associated with this # URL, if it exists, to the Tapingo page that is associated with this
# facility # facility
tapingo_url = models.URLField(blank=True, validators=[RegexValidator(regex='^https:\/\/www.tapingo.com\/', tapingo_url = models.URLField(blank=True, validators=[RegexValidator(regex='^https:\/\/www.tapingo.com\/',
...@@ -191,27 +188,33 @@ class Schedule(TimeStampedModel): ...@@ -191,27 +188,33 @@ class Schedule(TimeStampedModel):
# The start date of the schedule # The start date of the schedule
# (inclusive) # (inclusive)
valid_start = models.DateField('Start Date', null=True, blank=True, valid_start = models.DateField('Start Date', null=True, blank=True,
help_text="""Date that this schedule goes help_text="Date that this schedule goes into effect")
into effect""")
# The end date of the schedule # The end date of the schedule
# (inclusive) # (inclusive)
valid_end = models.DateField('End Date', null=True, blank=True, valid_end = models.DateField('End Date', null=True, blank=True,
help_text="""Last day that this schedule is help_text="Last day that this schedule is in effect")
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): def is_open_now(self):
""" """
Return true if this schedule is open right now. Return true if this schedule is open right now.
""" """
# Loop through all the open times that correspond to this schedule # If the schedule is a 24 hour one, then it's open.
for open_time in OpenTime.objects.filter(schedule=self): if self.twenty_four_hours:
# If the current time we are looking at is open, then the schedule return True
# will say that the facility is open # Otherwise let's check if it's open.
if open_time.is_open_now(): else:
# Open # Loop through all the open times that correspond to this schedule
return True for open_time in OpenTime.objects.filter(schedule=self):
# Closed (all open times are not open) # If the current time we are looking at is open, then the schedule
return False # will say that the facility is open
if open_time.is_open_now():
# Open
return True
# Closed (all open times are not open)
return False
class Meta: class Meta:
# Sort by name in admin view # Sort by name in admin view
......
...@@ -65,7 +65,7 @@ class ScheduleSerializer(serializers.ModelSerializer): ...@@ -65,7 +65,7 @@ class ScheduleSerializer(serializers.ModelSerializer):
model = Schedule model = Schedule
# List the fields that we are serializing # List the fields that we are serializing
fields = ('id', 'open_times', 'modified', 'name', 'valid_start', fields = ('id', 'open_times', 'modified', 'name', 'valid_start',
'valid_end') 'valid_end', 'twenty_four_hours')
class FacilitySerializer(serializers.HyperlinkedModelSerializer): class FacilitySerializer(serializers.HyperlinkedModelSerializer):
""" """
......
...@@ -374,9 +374,11 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet): ...@@ -374,9 +374,11 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
'main_schedule__name', 'main_schedule__name',
'main_schedule__valid_start', 'main_schedule__valid_start',
'main_schedule__valid_end', 'main_schedule__valid_end',
'main_schedule__twenty_four_hours',
'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'
) )
# Associate a serializer with the ViewSet # Associate a serializer with the ViewSet
...@@ -481,6 +483,7 @@ class ScheduleViewSet(viewsets.ModelViewSet): ...@@ -481,6 +483,7 @@ class ScheduleViewSet(viewsets.ModelViewSet):
'name', 'name',
'valid_start', 'valid_start',
'valid_end', 'valid_end',
'twenty_four_hours'
) )
# 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