Merge remote-tracking branch 'origin/feature/gm-148' into feature/gm-148

# Conflicts:
#	apps/news/models.py
#	apps/news/serializers.py
#	apps/news/views.py
#	project/settings/production.py
This commit is contained in:
Anatoly 2019-10-23 15:37:14 +03:00
commit fd2c1e0ca6
30 changed files with 214 additions and 47 deletions

View File

@ -0,0 +1,14 @@
# Generated by Django 2.2.4 on 2019-10-11 13:36
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('account', '0009_auto_20191002_0648'),
('account', '0010_user_password_confirmed'),
]
operations = [
]

View File

@ -0,0 +1,14 @@
# Generated by Django 2.2.4 on 2019-10-15 09:12
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('account', '0011_merge_20191014_1258'),
('account', '0011_merge_20191011_1336'),
]
operations = [
]

View File

@ -1,6 +1,8 @@
"""Establishment models."""
from datetime import datetime
from functools import reduce
import elasticsearch_dsl
from django.conf import settings
from django.contrib.contenttypes import fields as generic
from django.contrib.gis.db.models.functions import Distance
@ -12,6 +14,7 @@ from django.db.models import When, Case, F, ExpressionWrapper, Subquery, Q
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from phonenumber_field.modelfields import PhoneNumberField
from pytz import timezone as py_tz
from collection.models import Collection
from location.models import Address
@ -128,15 +131,15 @@ class EstablishmentQuerySet(models.QuerySet):
else:
return self.none()
# def es_search(self, value, locale=None):
# """Search text via ElasticSearch."""
# from search_indexes.documents import EstablishmentDocument
# search = EstablishmentDocument.search().filter(
# Elastic_Q('match', name=value) |
# Elastic_Q('match', **{f'description.{locale}': value})
# ).execute()
# ids = [result.meta.id for result in search]
# return self.filter(id__in=ids)
def es_search(self, value, locale=None):
"""Search text via ElasticSearch."""
from search_indexes.documents import EstablishmentDocument
search = EstablishmentDocument.search().filter(
elasticsearch_dsl.Q('match', name=value) |
elasticsearch_dsl.Q('match', **{f'description.{locale}': value})
).execute()
ids = [result.meta.id for result in search]
return self.filter(id__in=ids)
def by_country_code(self, code):
"""Return establishments by country code"""
@ -416,6 +419,32 @@ class Establishment(ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin):
def best_price_carte(self):
return 200
@property
def works_noon(self):
""" Used for indexing working by day """
return [ret.weekday for ret in self.schedule.all() if ret.works_at_noon]
@property
def works_evening(self):
""" Used for indexing working by day """
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
def tags_indexing(self):
return [{'id': tag.metadata.id,
'label': tag.metadata.label} for tag in self.tags.all()]
@property
def last_published_review(self):
"""Return last published review"""
@ -431,8 +460,8 @@ class Establishment(ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin):
@property
def the_most_recent_award(self):
return Award.objects.filter(Q(establishment=self) | Q(employees__establishments=self)).latest(
field_name='vintage_year')
return Award.objects.filter(Q(establishment=self) | Q(employees__establishments=self)) \
.latest(field_name='vintage_year')
@property
def country_id(self):

View File

@ -5,8 +5,10 @@ from django.db.models.signals import post_save
from django.db.transaction import on_commit
from django.dispatch import receiver
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 utils.models import ProjectBaseMixin, SVGImageMixin, TranslatedFieldsMixin, TJSONField
class Country(TranslatedFieldsMixin, SVGImageMixin, ProjectBaseMixin):
@ -112,6 +114,11 @@ class Address(models.Model):
def get_street_name(self):
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
def latitude(self):
return self.coordinates.y if self.coordinates else float(0)

View File

@ -1,21 +0,0 @@
# Generated by Django 2.2.4 on 2019-09-26 11:56
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('news', '0013_auto_20190924_0806'),
]
operations = [
migrations.RemoveField(
model_name='news',
name='image_url',
),
migrations.RemoveField(
model_name='news',
name='preview_image_url',
),
]

View File

@ -8,7 +8,6 @@ class Migration(migrations.Migration):
dependencies = [
('gallery', '0002_auto_20190930_0714'),
('news', '0014_auto_20190926_1156'),
]
operations = [

View File

@ -0,0 +1,14 @@
# Generated by Django 2.2.4 on 2019-10-15 09:12
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('news', '0021_auto_20191009_1408'),
('news', '0021_merge_20191002_1300'),
]
operations = [
]

View File

@ -47,6 +47,7 @@ class NewsBannerSerializer(ProjectModelSerializer):
class CropImageSerializer(serializers.Serializer):
"""Serializer for crop images for News object."""
preview_url = serializers.SerializerMethodField()
promo_horizontal_web_url = serializers.SerializerMethodField()
promo_horizontal_mobile_url = serializers.SerializerMethodField()

View File

@ -32,6 +32,13 @@ class EstablishmentDocument(Document):
}),
},
multi=True)
works_evening = fields.ListField(fields.IntegerField(
attr='works_evening'
))
works_noon = fields.ListField(fields.IntegerField(
attr='works_noon'
))
works_now = fields.BooleanField(attr='works_now')
tags = fields.ObjectField(
properties={
'id': fields.IntegerField(attr='id'),
@ -39,6 +46,14 @@ class EstablishmentDocument(Document):
properties=OBJECT_FIELD_PROPERTIES),
},
multi=True)
schedule = fields.ListField(fields.ObjectField(
properties={
'id': fields.IntegerField(attr='id'),
'weekday': fields.IntegerField(attr='weekday'),
'weekday_display': fields.KeywordField(attr='get_weekday_display'),
'closed_at': fields.KeywordField(attr='closed_at_str'),
}
))
address = fields.ObjectField(
properties={
'id': fields.IntegerField(),

View File

@ -24,6 +24,7 @@ class NewsDocument(Document):
country = fields.ObjectField(properties={'id': fields.IntegerField(),
'code': fields.KeywordField()})
web_url = fields.KeywordField(attr='web_url')
preview_image_url = fields.TextField(attr='preview_image_url')
tags = fields.ObjectField(
properties={
'id': fields.IntegerField(attr='id'),

View File

@ -30,6 +30,15 @@ class AddressDocumentSerializer(serializers.Serializer):
geo_lat = serializers.FloatField(allow_null=True, source='coordinates.lat')
class ScheduleDocumentSerializer(serializers.Serializer):
"""Schedule serializer for ES Document"""
id = serializers.IntegerField()
weekday = serializers.IntegerField()
weekday_display = serializers.CharField()
closed_at = serializers.CharField()
class NewsDocumentSerializer(DocumentSerializer):
"""News document serializer."""
@ -68,6 +77,7 @@ class EstablishmentDocumentSerializer(DocumentSerializer):
address = AddressDocumentSerializer()
tags = TagsDocumentSerializer(many=True)
schedule = ScheduleDocumentSerializer(many=True, allow_null=True)
class Meta:
"""Meta class."""
@ -84,6 +94,10 @@ class EstablishmentDocumentSerializer(DocumentSerializer):
'preview_image',
'address',
'tags',
'schedule',
'works_noon',
'works_evening',
'works_now',
# 'collections',
# 'establishment_type',
# 'establishment_subtypes',

View File

@ -111,6 +111,9 @@ class EstablishmentDocumentViewSet(BaseDocumentViewSet):
},
'tags_category_id': {
'field': 'tags.category.id',
'lookups': [
constants.LOOKUP_QUERY_IN,
],
},
'collection_type': {
'field': 'collections.collection_type'
@ -121,6 +124,25 @@ class EstablishmentDocumentViewSet(BaseDocumentViewSet):
'establishment_subtypes': {
'field': 'establishment_subtypes.id'
},
'works_noon': {
'field': 'works_noon',
'lookups': [
constants.LOOKUP_QUERY_IN,
],
},
'works_evening': {
'field': 'works_evening',
'lookups': [
constants.LOOKUP_FILTER_TERM,
],
},
'works_now': {
'field': 'works_now',
'lookups': [
constants.LOOKUP_FILTER_EXISTS,
constants.LOOKUP_QUERY_IN,
]
},
}
geo_spatial_filter_fields = {

View File

@ -56,7 +56,7 @@ class TagCategoryQuerySet(models.QuerySet):
def with_tags(self, switcher=True):
"""Filter by existing tags."""
return self.filter(tags__isnull=not switcher)
return self.exclude(tags__isnull=switcher)
class TagCategory(TranslatedFieldsMixin, models.Model):

7
apps/tag/urls/mobile.py Normal file
View File

@ -0,0 +1,7 @@
from tag.urls.web import urlpatterns as common_urlpatterns
urlpatterns = [
]
urlpatterns.extend(common_urlpatterns)

View File

@ -1,5 +1,6 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from datetime import time
from utils.models import ProjectBaseMixin
@ -14,6 +15,8 @@ class Timetable(ProjectBaseMixin):
SATURDAY = 5
SUNDAY = 6
NOON = time(17, 0)
WEEKDAYS_CHOICES = (
(MONDAY, _('Monday')),
(TUESDAY, _('Tuesday')),
@ -32,6 +35,18 @@ class Timetable(ProjectBaseMixin):
opening_at = models.TimeField(verbose_name=_('Opening time'), null=True)
closed_at = models.TimeField(verbose_name=_('Closed time'), null=True)
@property
def closed_at_str(self):
return str(self.closed_at) if self.closed_at else None
@property
def works_at_noon(self):
return bool(self.closed_at and self.closed_at <= self.NOON)
@property
def works_at_afternoon(self):
return bool(self.closed_at and self.closed_at > self.NOON)
class Meta:
"""Meta class."""
verbose_name = _('Timetable')

View File

@ -77,3 +77,16 @@ class ScheduleCreateSerializer(ScheduleRUDSerializer):
schedule_qs.delete()
establishment.schedule.add(instance)
return instance
class TimetableSerializer(serializers.ModelSerializer):
"""Serailzier for Timetable model."""
weekday_display = serializers.CharField(source='get_weekday_display',
read_only=True)
class Meta:
model = Timetable
fields = (
'id',
'weekday_display',
'works_at_noon',
)

View File

View File

@ -6,5 +6,5 @@ from timetable import views
app_name = 'timetable'
urlpatterns = [
path('', views.TimetableListView.as_view(), name='list')
# path('', views.TimetableListView.as_view(), name='list')
]

View File

@ -0,0 +1,6 @@
from timetable.urls.common import urlpatterns as common_urlpatterns
urlpatterns = []
urlpatterns.extend(common_urlpatterns)

View File

@ -0,0 +1,6 @@
from timetable.urls.common import urlpatterns as common_urlpatterns
urlpatterns = []
urlpatterns.extend(common_urlpatterns)

View File

@ -1,4 +1,4 @@
from rest_framework import generics
from rest_framework import generics, permissions
from timetable import serialziers, models
@ -6,3 +6,5 @@ class TimetableListView(generics.ListAPIView):
"""Method to get timetables"""
serializer_class = serialziers.TimetableSerializer
queryset = models.Timetable.objects.all()
pagination_class = None
permission_classes = (permissions.AllowAny, )

Binary file not shown.

View File

@ -1,13 +1,16 @@
"""Settings for Amazon S3"""
import os
from .base import MEDIA_LOCATION
# AMAZON S3
AWS_S3_REGION_NAME = 'eu-central-1'
AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_STORAGE_BUCKET_NAME')
AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'
AWS_S3_CUSTOM_DOMAIN = f's3.{AWS_S3_REGION_NAME}.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}'
AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}
AWS_S3_ADDRESSING_STYLE = 'path'
# Static settings
# PUBLIC_STATIC_LOCATION = 'static'

View File

@ -96,6 +96,7 @@ EXTERNAL_APPS = [
'phonenumber_field',
'storages',
'sorl.thumbnail',
'timezonefinder'
]

View File

@ -7,4 +7,4 @@ GUESTONLINE_SERVICE = 'https://api.guestonline.fr/'
GUESTONLINE_TOKEN = ''
LASTABLE_SERVICE = ''
LASTABLE_TOKEN = ''
LASTABLE_PROXY = ''
LASTABLE_PROXY = ''

View File

@ -6,7 +6,7 @@ ALLOWED_HOSTS = ['gm-stage.id-east.ru', '95.213.204.126']
SEND_SMS = False
SMS_CODE_SHOW = True
USE_CELERY = False
USE_CELERY = True
SCHEMA_URI = 'https'
DEFAULT_SUBDOMAIN = 'www'

File diff suppressed because one or more lines are too long

View File

@ -4,8 +4,10 @@ app_name = 'mobile'
urlpatterns = [
path('establishments/', include('establishment.urls.mobile')),
path('location/', include('location.urls.mobile')),
path('main/', include('main.urls.mobile')),
path('location/', include('location.urls.mobile'))
path('tags/', include('tag.urls.mobile')),
path('timetables/', include('timetable.urls.mobile')),
# path('account/', include('account.urls.web')),
# path('advertisement/', include('advertisement.urls.web')),
# path('collection/', include('collection.urls.web')),

View File

@ -34,4 +34,5 @@ urlpatterns = [
path('translation/', include('translation.urls')),
path('comments/', include('comment.urls.web')),
path('favorites/', include('favorites.urls')),
path('timetables/', include('timetable.urls.web')),
]

View File

@ -9,6 +9,7 @@ fcm-django
django-easy-select2
bootstrap-admin
drf-yasg==1.16.0
timezonefinder
PySocks!=1.5.7,>=1.5.6;
djangorestframework==3.9.4