Merge branch 'develop' into features/migrate-wine
This commit is contained in:
commit
6f8361cb83
|
|
@ -0,0 +1,31 @@
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from establishment.models import Establishment
|
||||||
|
from transfer.models import Descriptions
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Add description values from old db to new db'
|
||||||
|
|
||||||
|
def handle(self, *args, **kwargs):
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
queryset = Descriptions.objects.all()
|
||||||
|
for obj in queryset:
|
||||||
|
try:
|
||||||
|
establishment = Establishment.objects.get(old_id=obj.establishment.id)
|
||||||
|
except Establishment.DoesNotExist:
|
||||||
|
continue
|
||||||
|
except Establishment.MultipleObjectsReturned:
|
||||||
|
establishment = Establishment.objects.filter(old_id=obj.establishment.id).first()
|
||||||
|
else:
|
||||||
|
description = establishment.description
|
||||||
|
description.update({
|
||||||
|
obj.locale: obj.text
|
||||||
|
})
|
||||||
|
establishment.description = description
|
||||||
|
establishment.save()
|
||||||
|
count += 1
|
||||||
|
break
|
||||||
|
|
||||||
|
self.stdout.write(self.style.WARNING(f'Updated {count} objects.'))
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
|
from establishment.models import Establishment
|
||||||
|
from transfer.models import Reviews
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Add description values from old db to new db'
|
||||||
|
|
||||||
|
def handle(self, *args, **kwargs):
|
||||||
|
count = 0
|
||||||
|
valid_data = {}
|
||||||
|
|
||||||
|
queryset = Reviews.objects.exclude(
|
||||||
|
Q(establishment_id__isnull=True) |
|
||||||
|
Q(mark__isnull=True)
|
||||||
|
).filter(aasm_state='published').values_list('establishment_id', 'mark', 'updated_at')
|
||||||
|
|
||||||
|
for es_id, new_mark, new_date in queryset:
|
||||||
|
try:
|
||||||
|
mark, date = valid_data[es_id]
|
||||||
|
except KeyError:
|
||||||
|
valid_data[es_id] = (new_mark, new_date)
|
||||||
|
else:
|
||||||
|
if new_date > date:
|
||||||
|
valid_data[es_id] = (new_mark, new_date)
|
||||||
|
|
||||||
|
for key, value in valid_data.items():
|
||||||
|
try:
|
||||||
|
establishment = Establishment.objects.get(old_id=key)
|
||||||
|
except Establishment.DoesNotExist:
|
||||||
|
continue
|
||||||
|
except Establishment.MultipleObjectsReturned:
|
||||||
|
establishment = Establishment.objects.filter(old_id=key).first()
|
||||||
|
else:
|
||||||
|
establishment.public_mark = int(value[0])
|
||||||
|
establishment.save()
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
self.stdout.write(self.style.WARNING(f'Updated {count} objects.'))
|
||||||
|
|
@ -149,6 +149,18 @@ class EstablishmentSubTypeBaseSerializer(serializers.ModelSerializer):
|
||||||
'establishment_type': {'write_only': True}
|
'establishment_type': {'write_only': True}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class EstablishmentSubTypeGeoSerializer(EstablishmentSubTypeBaseSerializer):
|
||||||
|
"""Serializer for EstablishmentSuType model w/ index_name."""
|
||||||
|
|
||||||
|
class Meta(EstablishmentSubTypeBaseSerializer.Meta):
|
||||||
|
fields = EstablishmentSubTypeBaseSerializer.Meta.fields + [
|
||||||
|
'index_name'
|
||||||
|
]
|
||||||
|
extra_kwargs = {
|
||||||
|
**EstablishmentSubTypeBaseSerializer.Meta.extra_kwargs,
|
||||||
|
'index_name': {'read_only': True},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentEmployeeSerializer(serializers.ModelSerializer):
|
class EstablishmentEmployeeSerializer(serializers.ModelSerializer):
|
||||||
"""Serializer for actual employees."""
|
"""Serializer for actual employees."""
|
||||||
|
|
@ -200,12 +212,14 @@ class EstablishmentGeoSerializer(EstablishmentBaseSerializer):
|
||||||
"""Serializer for Geo view."""
|
"""Serializer for Geo view."""
|
||||||
|
|
||||||
type = EstablishmentTypeGeoSerializer(source='establishment_type', read_only=True)
|
type = EstablishmentTypeGeoSerializer(source='establishment_type', read_only=True)
|
||||||
|
subtypes = EstablishmentSubTypeGeoSerializer(many=True, source='establishment_subtypes')
|
||||||
|
|
||||||
class Meta(EstablishmentBaseSerializer.Meta):
|
class Meta(EstablishmentBaseSerializer.Meta):
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
||||||
fields = EstablishmentBaseSerializer.Meta.fields + [
|
fields = EstablishmentBaseSerializer.Meta.fields + [
|
||||||
'type'
|
'type',
|
||||||
|
'subtypes',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -172,8 +172,9 @@ class SiteSettings(ProjectBaseMixin):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def published_sitefeatures(self):
|
def published_sitefeatures(self):
|
||||||
return self.sitefeature_set\
|
return self.sitefeature_set. \
|
||||||
.filter(Q(published=True) and Q(feature__source__in=[PlatformMixin.WEB, PlatformMixin.ALL]))
|
filter(Q(published=True) &
|
||||||
|
Q(feature__source__in=[PlatformMixin.WEB, PlatformMixin.ALL]))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def site_url(self):
|
def site_url(self):
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,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(attr='works_now')
|
works_now = fields.BooleanField(attr='works_now')
|
||||||
tags = fields.ObjectField(
|
tags = fields.ObjectField(
|
||||||
properties={
|
properties={
|
||||||
'id': fields.IntegerField(attr='id'),
|
'id': fields.IntegerField(attr='id'),
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
"""Search indexes filters."""
|
"""Search indexes filters."""
|
||||||
from elasticsearch_dsl.query import Q
|
from elasticsearch_dsl.query import Q
|
||||||
from django_elasticsearch_dsl_drf.filter_backends import SearchFilterBackend
|
from django_elasticsearch_dsl_drf.filter_backends import SearchFilterBackend
|
||||||
from utils.models import get_current_language
|
from utils.models import get_current_locale
|
||||||
|
|
||||||
|
|
||||||
class CustomSearchFilterBackend(SearchFilterBackend):
|
class CustomSearchFilterBackend(SearchFilterBackend):
|
||||||
|
|
@ -12,7 +12,7 @@ class CustomSearchFilterBackend(SearchFilterBackend):
|
||||||
field_name = field
|
field_name = field
|
||||||
if hasattr(view, 'search_fields') and hasattr(view, 'translated_search_fields'):
|
if hasattr(view, 'search_fields') and hasattr(view, 'translated_search_fields'):
|
||||||
if field in view.translated_search_fields:
|
if field in view.translated_search_fields:
|
||||||
field_name = f'{field}.{get_current_language()}'
|
field_name = f'{field}.{get_current_locale()}'
|
||||||
return field_name
|
return field_name
|
||||||
|
|
||||||
def construct_search(self, request, view):
|
def construct_search(self, request, view):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""Search indexes utils."""
|
"""Search indexes utils."""
|
||||||
from django_elasticsearch_dsl import fields
|
from django_elasticsearch_dsl import fields
|
||||||
from utils.models import get_current_language
|
from utils.models import get_current_locale, get_default_locale
|
||||||
|
|
||||||
|
|
||||||
# object field properties
|
# object field properties
|
||||||
|
|
@ -19,4 +19,8 @@ def get_translated_value(value):
|
||||||
field_dict = value.to_dict()
|
field_dict = value.to_dict()
|
||||||
elif isinstance(value, dict):
|
elif isinstance(value, dict):
|
||||||
field_dict = value
|
field_dict = value
|
||||||
return field_dict.get(get_current_language())
|
value = field_dict.get(get_current_locale())
|
||||||
|
# fallback
|
||||||
|
if value is None:
|
||||||
|
value = field_dict.get(get_default_locale())
|
||||||
|
return value
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ class EstablishmentDocumentViewSet(BaseDocumentViewSet):
|
||||||
'lookups': [
|
'lookups': [
|
||||||
constants.LOOKUP_QUERY_IN,
|
constants.LOOKUP_QUERY_IN,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
'works_noon': {
|
'works_noon': {
|
||||||
'field': 'works_noon',
|
'field': 'works_noon',
|
||||||
'lookups': [
|
'lookups': [
|
||||||
|
|
@ -152,12 +152,12 @@ class EstablishmentDocumentViewSet(BaseDocumentViewSet):
|
||||||
constants.LOOKUP_QUERY_IN,
|
constants.LOOKUP_QUERY_IN,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
# 'works_now': {
|
'works_now': {
|
||||||
# 'field': 'works_now',
|
'field': 'works_now',
|
||||||
# 'lookups': [
|
'lookups': [
|
||||||
# constants.LOOKUP_FILTER_TERM,
|
constants.LOOKUP_FILTER_TERM,
|
||||||
# ]
|
]
|
||||||
# },
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
geo_spatial_filter_fields = {
|
geo_spatial_filter_fields = {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class TagBaseSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
# todo: refactor this
|
# todo: refactor this
|
||||||
# label_translated = TranslatedField()
|
# label_translated = TranslatedField()
|
||||||
label_translated = serializers.CharField(source='value')
|
label_translated = serializers.CharField(source='value', read_only=True, allow_null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
@ -43,7 +43,7 @@ class TagCategoryBaseSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
# todo: refactor this
|
# todo: refactor this
|
||||||
# label_translated = TranslatedField()
|
# label_translated = TranslatedField()
|
||||||
label_translated = serializers.CharField(source='index_name')
|
label_translated = serializers.CharField(source='index_name', read_only=True, allow_null=True)
|
||||||
tags = TagBaseSerializer(many=True, read_only=True)
|
tags = TagBaseSerializer(many=True, read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ from establishment.models import Establishment, ContactEmail, ContactPhone, Esta
|
||||||
from location.models import Address
|
from location.models import Address
|
||||||
from timetable.models import Timetable
|
from timetable.models import Timetable
|
||||||
from utils.legacy_parser import parse_legacy_schedule_content
|
from utils.legacy_parser import parse_legacy_schedule_content
|
||||||
|
from utils.serializers import TimeZoneChoiceField
|
||||||
from utils.slug_generator import generate_unique_slug
|
from utils.slug_generator import generate_unique_slug
|
||||||
from pytz import timezone as ptz
|
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentSerializer(serializers.ModelSerializer):
|
class EstablishmentSerializer(serializers.ModelSerializer):
|
||||||
|
|
@ -26,7 +26,7 @@ class EstablishmentSerializer(serializers.ModelSerializer):
|
||||||
twitter = serializers.CharField(allow_null=True, allow_blank=True)
|
twitter = serializers.CharField(allow_null=True, allow_blank=True)
|
||||||
booking = serializers.CharField(allow_null=True, allow_blank=True)
|
booking = serializers.CharField(allow_null=True, allow_blank=True)
|
||||||
state = serializers.CharField(allow_null=True)
|
state = serializers.CharField(allow_null=True)
|
||||||
tz = serializers.CharField()
|
tz = TimeZoneChoiceField()
|
||||||
created = serializers.DateTimeField(format='%m-%d-%Y %H:%M:%S')
|
created = serializers.DateTimeField(format='%m-%d-%Y %H:%M:%S')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
@ -59,7 +59,6 @@ class EstablishmentSerializer(serializers.ModelSerializer):
|
||||||
'establishment_type_id': self.get_type(data),
|
'establishment_type_id': self.get_type(data),
|
||||||
'is_publish': data.get('state') == 'published',
|
'is_publish': data.get('state') == 'published',
|
||||||
})
|
})
|
||||||
data['tz'] = ptz(data['tz'])
|
|
||||||
data.pop('location')
|
data.pop('location')
|
||||||
data.pop('type')
|
data.pop('type')
|
||||||
data.pop('state')
|
data.pop('state')
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ from django.contrib.postgres.fields.jsonb import KeyTextTransform
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.html import mark_safe
|
from django.utils.html import mark_safe
|
||||||
from django.utils.translation import ugettext_lazy as _, get_language
|
from django.utils.translation import ugettext_lazy as _, get_language
|
||||||
|
from configuration.models import TranslationSettings
|
||||||
from easy_thumbnails.fields import ThumbnailerImageField
|
from easy_thumbnails.fields import ThumbnailerImageField
|
||||||
from sorl.thumbnail import get_thumbnail
|
from sorl.thumbnail import get_thumbnail
|
||||||
from sorl.thumbnail.fields import ImageField as SORLImageField
|
from sorl.thumbnail.fields import ImageField as SORLImageField
|
||||||
|
|
@ -59,13 +60,26 @@ def to_locale(language):
|
||||||
return language + '-' + country
|
return language + '-' + country
|
||||||
|
|
||||||
|
|
||||||
|
def get_current_locale():
|
||||||
|
"""Get current language."""
|
||||||
|
return to_locale(get_language())
|
||||||
|
|
||||||
|
|
||||||
|
def get_default_locale():
|
||||||
|
return TranslationSettings.get_solo().default_language or \
|
||||||
|
settings.FALLBACK_LOCALE
|
||||||
|
|
||||||
|
|
||||||
def translate_field(self, field_name):
|
def translate_field(self, field_name):
|
||||||
def translate(self):
|
def translate(self):
|
||||||
field = getattr(self, field_name)
|
field = getattr(self, field_name)
|
||||||
if isinstance(field, dict):
|
if isinstance(field, dict):
|
||||||
return field.get(to_locale(get_language()))
|
value = field.get(to_locale(get_language()))
|
||||||
|
# fallback
|
||||||
|
if value is None:
|
||||||
|
value = field.get(get_default_locale())
|
||||||
|
return value
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return translate
|
return translate
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -111,15 +125,10 @@ class TranslatedFieldsMixin:
|
||||||
if self.STR_FIELD_NAME:
|
if self.STR_FIELD_NAME:
|
||||||
field = getattr(self, getattr(self, 'STR_FIELD_NAME'))
|
field = getattr(self, getattr(self, 'STR_FIELD_NAME'))
|
||||||
if isinstance(field, dict):
|
if isinstance(field, dict):
|
||||||
value = field.get(get_current_language())
|
value = field.get(get_current_locale())
|
||||||
return value if value else super(TranslatedFieldsMixin, self).__str__()
|
return value if value else super(TranslatedFieldsMixin, self).__str__()
|
||||||
|
|
||||||
|
|
||||||
def get_current_language():
|
|
||||||
"""Get current language."""
|
|
||||||
return to_locale(get_language())
|
|
||||||
|
|
||||||
|
|
||||||
class OAuthProjectMixin:
|
class OAuthProjectMixin:
|
||||||
"""OAuth2 mixin for project GM"""
|
"""OAuth2 mixin for project GM"""
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -488,3 +488,5 @@ MEDIA_LOCATION = 'media'
|
||||||
|
|
||||||
PHONENUMBER_DB_FORMAT = 'NATIONAL'
|
PHONENUMBER_DB_FORMAT = 'NATIONAL'
|
||||||
PHONENUMBER_DEFAULT_REGION = "FR"
|
PHONENUMBER_DEFAULT_REGION = "FR"
|
||||||
|
|
||||||
|
FALLBACK_LOCALE = 'en-GB'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user