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