Commit 230e2ec1 authored by Silvestre Perret's avatar Silvestre Perret

add is_open function

parent b0d9763d
......@@ -98,6 +98,14 @@ class Location(models.Model):
dt = timezone.now()
return self.schedules.filter(day_of_the_week=dt.weekday())
def is_open(self):
dt = timezone.now()
schedule = self.schedules.filter(day_of_the_week=dt.weekday())
if not schedule:
return False
schedule = schedule[0]
return schedule.opening_time <= dt.time() <= schedule.closing_time
def get_incident(self):
qs = self.incident_set.filter(status=True).order_by('-id')
return qs[0] if bool(qs) else None
......
......@@ -50,6 +50,7 @@ class ListLocationSerializer(serializers.ModelSerializer):
estimated_waiting_time = serializers.DurationField(source='get_waiting_time_now', read_only=True)
waiting_time_level = serializers.IntegerField(source='get_wt_now_level', read_only=True)
incident = IncidentSerializer(source='get_incident', read_only=True, allow_null=True)
is_open = serializers.BooleanField(read_only=True)
class Meta:
model = Location
......@@ -59,8 +60,9 @@ class ListLocationSerializer(serializers.ModelSerializer):
'category_id',
'category',
'latitude', 'longitude',
'estimated_waiting_time','waiting_time_level',
'incident'
'estimated_waiting_time', 'waiting_time_level',
'incident',
'is_open'
)
......@@ -68,6 +70,7 @@ class LocationSerializer(serializers.ModelSerializer):
category_id = serializers.PrimaryKeyRelatedField(read_only=True)
category = serializers.StringRelatedField(read_only=True)
schedule = ScheduleSerializer(source='get_schedule', many=True, read_only=True, allow_null=True)
is_open = serializers.BooleanField(read_only=True)
estimated_waiting_time = serializers.DurationField(source='get_waiting_time_now', read_only=True)
waiting_time_level = serializers.IntegerField(source='get_wt_now_level', read_only=True)
incident = IncidentSerializer(source='get_incident', read_only=True, allow_null=True)
......@@ -81,7 +84,8 @@ class LocationSerializer(serializers.ModelSerializer):
'category',
'description',
'latitude', 'longitude',
'estimated_waiting_time','waiting_time_level',
'estimated_waiting_time', 'waiting_time_level',
'incident',
'schedule'
'schedule',
'is_open'
)
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