Merge remote-tracking branch 'origin/develop' into feature/authorization
This commit is contained in:
commit
892159ccb6
|
|
@ -43,7 +43,7 @@ class Migration(migrations.Migration):
|
||||||
'verbose_name': 'Position',
|
'verbose_name': 'Position',
|
||||||
'verbose_name_plural': 'Positions',
|
'verbose_name_plural': 'Positions',
|
||||||
},
|
},
|
||||||
bases=(models.Model, utils.models.TraslatedFieldsMixin),
|
bases=(models.Model, utils.models.TranslatedFieldsMixin),
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='EstablishmentEmployee',
|
name='EstablishmentEmployee',
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class Migration(migrations.Migration):
|
||||||
'verbose_name': 'menu',
|
'verbose_name': 'menu',
|
||||||
'verbose_name_plural': 'menu',
|
'verbose_name_plural': 'menu',
|
||||||
},
|
},
|
||||||
bases=(utils.models.TraslatedFieldsMixin, models.Model),
|
bases=(utils.models.TranslatedFieldsMixin, models.Model),
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Plate',
|
name='Plate',
|
||||||
|
|
@ -48,6 +48,6 @@ class Migration(migrations.Migration):
|
||||||
'verbose_name': 'plate',
|
'verbose_name': 'plate',
|
||||||
'verbose_name_plural': 'plates',
|
'verbose_name_plural': 'plates',
|
||||||
},
|
},
|
||||||
bases=(utils.models.TraslatedFieldsMixin, models.Model),
|
bases=(utils.models.TranslatedFieldsMixin, models.Model),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,22 @@
|
||||||
"""Establishment models."""
|
"""Establishment models."""
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
|
||||||
from django.contrib.contenttypes import fields as generic
|
from django.contrib.contenttypes import fields as generic
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
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 location.models import Address
|
from location.models import Address
|
||||||
from utils.models import (ProjectBaseMixin, ImageMixin, TJSONField,
|
from utils.models import (ProjectBaseMixin, ImageMixin, TJSONField,
|
||||||
TraslatedFieldsMixin, BaseAttributes)
|
TranslatedFieldsMixin, BaseAttributes)
|
||||||
|
|
||||||
|
|
||||||
# todo: establishment type&subtypes check
|
# todo: establishment type&subtypes check
|
||||||
class EstablishmentType(ProjectBaseMixin, TraslatedFieldsMixin):
|
class EstablishmentType(TranslatedFieldsMixin, ProjectBaseMixin):
|
||||||
"""Establishment type model."""
|
"""Establishment type model."""
|
||||||
|
|
||||||
|
STR_FIELD_NAME = 'name'
|
||||||
|
|
||||||
name = TJSONField(blank=True, null=True, default=None, verbose_name=_('Description'),
|
name = TJSONField(blank=True, null=True, default=None, verbose_name=_('Description'),
|
||||||
help_text='{"en-GB":"some text"}')
|
help_text='{"en-GB":"some text"}')
|
||||||
use_subtypes = models.BooleanField(_('Use subtypes'), default=True)
|
use_subtypes = models.BooleanField(_('Use subtypes'), default=True)
|
||||||
|
|
@ -38,7 +38,7 @@ class EstablishmentSubTypeManager(models.Manager):
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentSubType(ProjectBaseMixin, TraslatedFieldsMixin):
|
class EstablishmentSubType(ProjectBaseMixin, TranslatedFieldsMixin):
|
||||||
"""Establishment type model."""
|
"""Establishment type model."""
|
||||||
|
|
||||||
name = TJSONField(blank=True, null=True, default=None, verbose_name=_('Description'),
|
name = TJSONField(blank=True, null=True, default=None, verbose_name=_('Description'),
|
||||||
|
|
@ -87,9 +87,11 @@ class EstablishmentQuerySet(models.QuerySet):
|
||||||
to_attr='actual_establishment_employees'))
|
to_attr='actual_establishment_employees'))
|
||||||
|
|
||||||
|
|
||||||
class Establishment(ProjectBaseMixin, ImageMixin, TraslatedFieldsMixin):
|
class Establishment(ProjectBaseMixin, ImageMixin, TranslatedFieldsMixin):
|
||||||
"""Establishment model."""
|
"""Establishment model."""
|
||||||
|
|
||||||
|
STR_FIELD_NAME = 'name'
|
||||||
|
|
||||||
name = TJSONField(blank=True, null=True, default=None,
|
name = TJSONField(blank=True, null=True, default=None,
|
||||||
verbose_name=_('Name'), help_text='{"en-GB":"some text"}')
|
verbose_name=_('Name'), help_text='{"en-GB":"some text"}')
|
||||||
description = TJSONField(blank=True, null=True, default=None,
|
description = TJSONField(blank=True, null=True, default=None,
|
||||||
|
|
@ -177,9 +179,11 @@ class Establishment(ProjectBaseMixin, ImageMixin, TraslatedFieldsMixin):
|
||||||
return 200
|
return 200
|
||||||
|
|
||||||
|
|
||||||
class Position(BaseAttributes, TraslatedFieldsMixin):
|
class Position(BaseAttributes, TranslatedFieldsMixin):
|
||||||
"""Position model."""
|
"""Position model."""
|
||||||
|
|
||||||
|
STR_FIELD_NAME = 'name'
|
||||||
|
|
||||||
name = TJSONField(blank=True, null=True, default=None, verbose_name=_('Description'),
|
name = TJSONField(blank=True, null=True, default=None, verbose_name=_('Description'),
|
||||||
help_text='{"en":"some text"}')
|
help_text='{"en":"some text"}')
|
||||||
|
|
||||||
|
|
@ -285,7 +289,7 @@ class ContactEmail(models.Model):
|
||||||
return f'{self.email}'
|
return f'{self.email}'
|
||||||
|
|
||||||
#
|
#
|
||||||
# class Wine(TraslatedFieldsMixin, models.Model):
|
# class Wine(TranslatedFieldsMixin, models.Model):
|
||||||
# """Wine model."""
|
# """Wine model."""
|
||||||
# establishment = models.ForeignKey(
|
# establishment = models.ForeignKey(
|
||||||
# 'establishment.Establishment', verbose_name=_('establishment'),
|
# 'establishment.Establishment', verbose_name=_('establishment'),
|
||||||
|
|
@ -303,7 +307,7 @@ class ContactEmail(models.Model):
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
class Plate(TraslatedFieldsMixin, models.Model):
|
class Plate(TranslatedFieldsMixin, models.Model):
|
||||||
"""Plate model."""
|
"""Plate model."""
|
||||||
|
|
||||||
name = TJSONField(
|
name = TJSONField(
|
||||||
|
|
@ -329,7 +333,7 @@ class Plate(TraslatedFieldsMixin, models.Model):
|
||||||
return f'plate_id:{self.id}'
|
return f'plate_id:{self.id}'
|
||||||
|
|
||||||
|
|
||||||
class Menu(TraslatedFieldsMixin, BaseAttributes):
|
class Menu(TranslatedFieldsMixin, BaseAttributes):
|
||||||
"""Menu model."""
|
"""Menu model."""
|
||||||
category = TJSONField(
|
category = TJSONField(
|
||||||
blank=True, null=True, default=None, verbose_name=_('category'),
|
blank=True, null=True, default=None, verbose_name=_('category'),
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ class EstablishmentMixin:
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
"""Overrided method 'get_queryset'."""
|
"""Overrided method 'get_queryset'."""
|
||||||
|
# todo: update ordering (last review)
|
||||||
return models.Establishment.objects.all().prefetch_actual_employees()
|
return models.Establishment.objects.all().prefetch_actual_employees()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -23,9 +24,8 @@ class EstablishmentListView(EstablishmentMixin, JWTGenericViewMixin, generics.Li
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
"""Overrided method 'get_queryset'."""
|
"""Overrided method 'get_queryset'."""
|
||||||
return models.Establishment.objects.all()\
|
qs = super(EstablishmentListView, self).get_queryset()
|
||||||
.prefetch_actual_employees()\
|
return qs.by_country_code(code=self.request.country_code)
|
||||||
.by_country_code(code=self.request.country_code)
|
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentRetrieveView(EstablishmentMixin, JWTGenericViewMixin, generics.RetrieveAPIView):
|
class EstablishmentRetrieveView(EstablishmentMixin, JWTGenericViewMixin, generics.RetrieveAPIView):
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class Migration(migrations.Migration):
|
||||||
'verbose_name': 'metadata',
|
'verbose_name': 'metadata',
|
||||||
'verbose_name_plural': 'metadata',
|
'verbose_name_plural': 'metadata',
|
||||||
},
|
},
|
||||||
bases=(utils.models.TraslatedFieldsMixin, models.Model),
|
bases=(utils.models.TranslatedFieldsMixin, models.Model),
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='MetaDataContent',
|
name='MetaDataContent',
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from django.utils.translation import gettext_lazy as _
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from location.models import Country
|
from location.models import Country
|
||||||
from main import methods
|
from main import methods
|
||||||
from utils.models import ProjectBaseMixin, TJSONField, TraslatedFieldsMixin
|
from utils.models import ProjectBaseMixin, TJSONField, TranslatedFieldsMixin
|
||||||
from configuration.models import TranslationSettings
|
from configuration.models import TranslationSettings
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
@ -185,7 +185,7 @@ class SiteFeature(ProjectBaseMixin):
|
||||||
unique_together = ('site_settings', 'feature')
|
unique_together = ('site_settings', 'feature')
|
||||||
|
|
||||||
|
|
||||||
class Award(TraslatedFieldsMixin, models.Model):
|
class Award(TranslatedFieldsMixin, models.Model):
|
||||||
"""Award model."""
|
"""Award model."""
|
||||||
award_type = models.ForeignKey('main.AwardType', on_delete=models.CASCADE)
|
award_type = models.ForeignKey('main.AwardType', on_delete=models.CASCADE)
|
||||||
title = TJSONField(
|
title = TJSONField(
|
||||||
|
|
@ -224,7 +224,7 @@ class MetaDataCategory(models.Model):
|
||||||
public = models.BooleanField()
|
public = models.BooleanField()
|
||||||
|
|
||||||
|
|
||||||
class MetaData(TraslatedFieldsMixin, models.Model):
|
class MetaData(TranslatedFieldsMixin, models.Model):
|
||||||
"""MetaData model."""
|
"""MetaData model."""
|
||||||
label = TJSONField(
|
label = TJSONField(
|
||||||
_('label'), null=True, blank=True,
|
_('label'), null=True, blank=True,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from utils.models import BaseAttributes, TJSONField, TraslatedFieldsMixin
|
from utils.models import BaseAttributes, TJSONField, TranslatedFieldsMixin
|
||||||
|
|
||||||
|
|
||||||
class NewsType(models.Model):
|
class NewsType(models.Model):
|
||||||
|
|
@ -32,7 +32,7 @@ class NewsQuerySet(models.QuerySet):
|
||||||
return self.filter(is_publish=True)
|
return self.filter(is_publish=True)
|
||||||
|
|
||||||
|
|
||||||
class News(BaseAttributes, TraslatedFieldsMixin):
|
class News(BaseAttributes, TranslatedFieldsMixin):
|
||||||
"""News model."""
|
"""News model."""
|
||||||
|
|
||||||
image = models.ForeignKey(
|
image = models.ForeignKey(
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
|
"""Review app models."""
|
||||||
from django.contrib.contenttypes import fields as generic
|
from django.contrib.contenttypes import fields as generic
|
||||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from utils.models import BaseAttributes, TraslatedFieldsMixin
|
from utils.models import BaseAttributes, TranslatedFieldsMixin
|
||||||
from utils.models import TJSONField
|
from utils.models import TJSONField
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -19,7 +20,7 @@ class ReviewQuerySet(models.QuerySet):
|
||||||
return self.filter(vintage=year)
|
return self.filter(vintage=year)
|
||||||
|
|
||||||
|
|
||||||
class Review(BaseAttributes, TraslatedFieldsMixin):
|
class Review(BaseAttributes, TranslatedFieldsMixin):
|
||||||
"""Review model"""
|
"""Review model"""
|
||||||
TO_INVESTIGATE = 0
|
TO_INVESTIGATE = 0
|
||||||
TO_REVIEW = 1
|
TO_REVIEW = 1
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,14 @@ def translate_field(self, field_name):
|
||||||
return translate
|
return translate
|
||||||
|
|
||||||
|
|
||||||
class TraslatedFieldsMixin:
|
class TranslatedFieldsMixin:
|
||||||
|
"""Translated Fields mixin"""
|
||||||
|
|
||||||
|
STR_FIELD_NAME = ''
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(TraslatedFieldsMixin, self).__init__(*args, **kwargs)
|
"""Overrided __init__ method."""
|
||||||
|
super(TranslatedFieldsMixin, self).__init__(*args, **kwargs)
|
||||||
cls = self.__class__
|
cls = self.__class__
|
||||||
for field in cls._meta.fields:
|
for field in cls._meta.fields:
|
||||||
field_name = field.name
|
field_name = field.name
|
||||||
|
|
@ -65,6 +70,20 @@ class TraslatedFieldsMixin:
|
||||||
setattr(cls, f'{field.name}_translated',
|
setattr(cls, f'{field.name}_translated',
|
||||||
property(translate_field(self, field_name)))
|
property(translate_field(self, field_name)))
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
"""Overrided __str__ method."""
|
||||||
|
value = None
|
||||||
|
if self.STR_FIELD_NAME:
|
||||||
|
field = getattr(self, getattr(self, 'STR_FIELD_NAME'))
|
||||||
|
if isinstance(field, dict):
|
||||||
|
value = field.get(get_current_language())
|
||||||
|
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"""
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ LOGOUT_URL = 'admin:logout'
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'ru'
|
LANGUAGE_CODE = 'ru-RU'
|
||||||
|
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = 'UTC'
|
||||||
|
|
||||||
|
|
@ -388,7 +388,10 @@ DATA_UPLOAD_MAX_MEMORY_SIZE = 5242880 # 5MB
|
||||||
FILE_UPLOAD_MAX_MEMORY_SIZE = 5242880 # 5MB
|
FILE_UPLOAD_MAX_MEMORY_SIZE = 5242880 # 5MB
|
||||||
FILE_UPLOAD_PERMISSIONS = 0o644
|
FILE_UPLOAD_PERMISSIONS = 0o644
|
||||||
|
|
||||||
|
# SOLO SETTINGS
|
||||||
|
# todo: make a separate service (redis?) and update solo_cache
|
||||||
|
SOLO_CACHE = 'default'
|
||||||
|
SOLO_CACHE_PREFIX = 'solo'
|
||||||
SOLO_CACHE_TIMEOUT = 300
|
SOLO_CACHE_TIMEOUT = 300
|
||||||
|
|
||||||
# REDIRECT URL
|
# REDIRECT URL
|
||||||
|
|
|
||||||
|
|
@ -16,3 +16,41 @@ DOMAIN_URI = '0.0.0.0:8000'
|
||||||
BROKER_URL = 'amqp://rabbitmq:5672'
|
BROKER_URL = 'amqp://rabbitmq:5672'
|
||||||
CELERY_RESULT_BACKEND = BROKER_URL
|
CELERY_RESULT_BACKEND = BROKER_URL
|
||||||
CELERY_BROKER_URL = BROKER_URL
|
CELERY_BROKER_URL = BROKER_URL
|
||||||
|
|
||||||
|
|
||||||
|
# LOGGING
|
||||||
|
LOGGING = {
|
||||||
|
'version': 1,
|
||||||
|
'disable_existing_loggers': False,
|
||||||
|
'filters': {
|
||||||
|
'require_debug_false': {
|
||||||
|
'()': 'django.utils.log.RequireDebugFalse',
|
||||||
|
},
|
||||||
|
'require_debug_true': {
|
||||||
|
'()': 'django.utils.log.RequireDebugTrue',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'handlers': {
|
||||||
|
'console': {
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'filters': ['require_debug_true'],
|
||||||
|
'class': 'logging.StreamHandler',
|
||||||
|
},
|
||||||
|
'null': {
|
||||||
|
'class': 'logging.NullHandler',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'loggers': {
|
||||||
|
'django': {
|
||||||
|
'handlers': ['console'],
|
||||||
|
},
|
||||||
|
'py.warnings': {
|
||||||
|
'handlers': ['console'],
|
||||||
|
},
|
||||||
|
'django.db.backends': {
|
||||||
|
'handlers': ['console', ],
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'propagate': False,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user