Open now filter
This commit is contained in:
parent
4b5b34de20
commit
b77c654c6c
|
|
@ -1,4 +1,5 @@
|
||||||
"""Establishment models."""
|
"""Establishment models."""
|
||||||
|
from datetime import datetime
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
|
||||||
import elasticsearch_dsl
|
import elasticsearch_dsl
|
||||||
|
|
@ -13,6 +14,7 @@ from django.db.models import When, Case, F, ExpressionWrapper, Subquery, Q
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from phonenumber_field.modelfields import PhoneNumberField
|
from phonenumber_field.modelfields import PhoneNumberField
|
||||||
|
from pytz import timezone as py_tz
|
||||||
|
|
||||||
from collection.models import Collection
|
from collection.models import Collection
|
||||||
from location.models import Address
|
from location.models import Address
|
||||||
|
|
@ -378,6 +380,17 @@ class Establishment(ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin):
|
||||||
""" Used for indexing working by day """
|
""" Used for indexing working by day """
|
||||||
return [ret.weekday for ret in self.schedule.all() if ret.works_at_afternoon]
|
return [ret.weekday for ret in self.schedule.all() if ret.works_at_afternoon]
|
||||||
|
|
||||||
|
# @property
|
||||||
|
def works_now(self):
|
||||||
|
""" Is establishment working now """
|
||||||
|
now_at_est_tz = datetime.now(tz=py_tz(self.address.tz_name))
|
||||||
|
current_week = now_at_est_tz.weekday()
|
||||||
|
schedule_for_today = self.schedule.filter(weekday=current_week).first()
|
||||||
|
if schedule_for_today is None:
|
||||||
|
return False
|
||||||
|
time_at_est_tz = now_at_est_tz.time()
|
||||||
|
return schedule_for_today.closed_at > time_at_est_tz > schedule_for_today.opening_at
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tags_indexing(self):
|
def tags_indexing(self):
|
||||||
return [{'id': tag.metadata.id,
|
return [{'id': tag.metadata.id,
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,10 @@ from django.db.models.signals import post_save
|
||||||
from django.db.transaction import on_commit
|
from django.db.transaction import on_commit
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from utils.models import ProjectBaseMixin, SVGImageMixin, TranslatedFieldsMixin, TJSONField
|
|
||||||
|
from timezonefinder import TimezoneFinder
|
||||||
from translation.models import Language
|
from translation.models import Language
|
||||||
|
from utils.models import ProjectBaseMixin, SVGImageMixin, TranslatedFieldsMixin, TJSONField
|
||||||
|
|
||||||
|
|
||||||
class Country(TranslatedFieldsMixin, SVGImageMixin, ProjectBaseMixin):
|
class Country(TranslatedFieldsMixin, SVGImageMixin, ProjectBaseMixin):
|
||||||
|
|
@ -99,6 +101,11 @@ class Address(models.Model):
|
||||||
def get_street_name(self):
|
def get_street_name(self):
|
||||||
return self.street_name_1 or self.street_name_2
|
return self.street_name_1 or self.street_name_2
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tz_name(self):
|
||||||
|
tf = TimezoneFinder(in_memory=True)
|
||||||
|
return tf.certain_timezone_at(lng=self.latitude, lat=self.longitude)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def latitude(self):
|
def latitude(self):
|
||||||
return self.coordinates.y if self.coordinates else float(0)
|
return self.coordinates.y if self.coordinates else float(0)
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ class EstablishmentDocument(Document):
|
||||||
works_noon = fields.ListField(fields.IntegerField(
|
works_noon = fields.ListField(fields.IntegerField(
|
||||||
attr='works_noon'
|
attr='works_noon'
|
||||||
))
|
))
|
||||||
|
works_now = fields.BooleanField()
|
||||||
tags = fields.ObjectField(
|
tags = fields.ObjectField(
|
||||||
properties={
|
properties={
|
||||||
'id': fields.IntegerField(attr='id'),
|
'id': fields.IntegerField(attr='id'),
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@ class EstablishmentDocumentSerializer(DocumentSerializer):
|
||||||
'schedule',
|
'schedule',
|
||||||
'works_noon',
|
'works_noon',
|
||||||
'works_evening',
|
'works_evening',
|
||||||
|
'works_now',
|
||||||
# 'collections',
|
# 'collections',
|
||||||
# 'establishment_type',
|
# 'establishment_type',
|
||||||
# 'establishment_subtypes',
|
# 'establishment_subtypes',
|
||||||
|
|
|
||||||
|
|
@ -133,9 +133,16 @@ class EstablishmentDocumentViewSet(BaseDocumentViewSet):
|
||||||
'works_evening': {
|
'works_evening': {
|
||||||
'field': 'works_evening',
|
'field': 'works_evening',
|
||||||
'lookups': [
|
'lookups': [
|
||||||
constants.LOOKUP_QUERY_IN,
|
constants.LOOKUP_FILTER_TERM,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
'works_now': {
|
||||||
|
'field': 'works_now',
|
||||||
|
'lookups': [
|
||||||
|
constants.LOOKUP_FILTER_EXISTS,
|
||||||
|
constants.LOOKUP_QUERY_IN,
|
||||||
|
]
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
geo_spatial_filter_fields = {
|
geo_spatial_filter_fields = {
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ EXTERNAL_APPS = [
|
||||||
'phonenumber_field',
|
'phonenumber_field',
|
||||||
'storages',
|
'storages',
|
||||||
'sorl.thumbnail',
|
'sorl.thumbnail',
|
||||||
|
'timezonefinder'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ fcm-django
|
||||||
django-easy-select2
|
django-easy-select2
|
||||||
bootstrap-admin
|
bootstrap-admin
|
||||||
drf-yasg==1.16.0
|
drf-yasg==1.16.0
|
||||||
|
timezonefinder
|
||||||
PySocks!=1.5.7,>=1.5.6;
|
PySocks!=1.5.7,>=1.5.6;
|
||||||
|
|
||||||
djangorestframework==3.9.4
|
djangorestframework==3.9.4
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user