Merge remote-tracking branch 'origin/develop' into maigrate-carousel
This commit is contained in:
commit
4cdcc8988b
|
|
@ -87,3 +87,8 @@ class MenuAdmin(BaseModelAdminMixin, admin.ModelAdmin):
|
||||||
return obj.category_translated
|
return obj.category_translated
|
||||||
|
|
||||||
category_translated.short_description = _('category')
|
category_translated.short_description = _('category')
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(models.RatingStrategy)
|
||||||
|
class RatingStrategyAdmin(BaseModelAdminMixin, admin.ModelAdmin):
|
||||||
|
"""Admin conf for Rating Strategy model."""
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
"""Run recalculating toque number for establishments."""
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from establishment.models import Establishment
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
|
||||||
|
help = 'Recalculation toque number for all establishments.'
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
for establishment in Establishment.objects.select_related('address__city__country'):
|
||||||
|
print(f'Recalculate for {establishment.name} ({establishment.id})')
|
||||||
|
establishment.recalculate_toque_number()
|
||||||
33
apps/establishment/migrations/0048_ratingstrategy.py
Normal file
33
apps/establishment/migrations/0048_ratingstrategy.py
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-31 15:55
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('location', '0020_merge_20191030_1714'),
|
||||||
|
('establishment', '0047_merge_20191030_1714'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='RatingStrategy',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('created', models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='Date created')),
|
||||||
|
('modified', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
||||||
|
('toque_number', models.IntegerField(choices=[(1, 'One'), (2, 'Two'), (3, 'Three'), (4, 'Four'), (5, 'Five')])),
|
||||||
|
('public_mark_min_value', models.IntegerField()),
|
||||||
|
('public_mark_max_value', models.IntegerField()),
|
||||||
|
('country', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='location.Country', verbose_name='Country')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Rating strategy',
|
||||||
|
'verbose_name_plural': 'Rating strategy',
|
||||||
|
'unique_together': {('country', 'toque_number')},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
19
apps/establishment/migrations/0049_auto_20191031_1616.py
Normal file
19
apps/establishment/migrations/0049_auto_20191031_1616.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-31 16:16
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('establishment', '0048_ratingstrategy'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='ratingstrategy',
|
||||||
|
name='country',
|
||||||
|
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='location.Country', verbose_name='Country'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -14,7 +14,6 @@ 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 ptz
|
|
||||||
from timezone_field import TimeZoneField
|
from timezone_field import TimeZoneField
|
||||||
|
|
||||||
from collection.models import Collection
|
from collection.models import Collection
|
||||||
|
|
@ -384,7 +383,13 @@ class Establishment(ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin):
|
||||||
|
|
||||||
# todo: recalculate toque_number
|
# todo: recalculate toque_number
|
||||||
def recalculate_toque_number(self):
|
def recalculate_toque_number(self):
|
||||||
self.toque_number = 4
|
toque_number = None
|
||||||
|
if self.address and self.public_mark:
|
||||||
|
toque_number = RatingStrategy.objects. \
|
||||||
|
get_toque_number(country=self.address.city.country,
|
||||||
|
public_mark=self.public_mark)
|
||||||
|
self.toque_number = toque_number
|
||||||
|
self.save()
|
||||||
|
|
||||||
def recalculate_price_level(self, low_price=None, high_price=None):
|
def recalculate_price_level(self, low_price=None, high_price=None):
|
||||||
if low_price is None or high_price is None:
|
if low_price is None or high_price is None:
|
||||||
|
|
@ -669,3 +674,62 @@ class SocialNetwork(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
|
class RatingStrategyManager(models.Manager):
|
||||||
|
"""Extended manager for RatingStrategy."""
|
||||||
|
|
||||||
|
def get_toque_number(self, country, public_mark):
|
||||||
|
"""Get toque number for country and public_mark."""
|
||||||
|
qs = self.model.objects.by_country(country)
|
||||||
|
if not qs.exists():
|
||||||
|
qs = self.model.objects.by_country(None)
|
||||||
|
obj = qs.for_public_mark(public_mark).first()
|
||||||
|
if obj:
|
||||||
|
return obj.toque_number
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class RatingStrategyQuerySet(models.QuerySet):
|
||||||
|
"""Extended queryset for RatingStrategy."""
|
||||||
|
|
||||||
|
def by_country(self, country):
|
||||||
|
"""Filter by country."""
|
||||||
|
return self.filter(country=country)
|
||||||
|
|
||||||
|
def for_public_mark(self, public_mark):
|
||||||
|
"""Filter for value."""
|
||||||
|
return self.filter(public_mark_min_value__lte=public_mark,
|
||||||
|
public_mark_max_value__gte=public_mark)
|
||||||
|
|
||||||
|
|
||||||
|
class RatingStrategy(ProjectBaseMixin):
|
||||||
|
"""Rating Strategy model."""
|
||||||
|
|
||||||
|
TOQUE_NUMBER_CHOICES = (
|
||||||
|
(1, _('One')),
|
||||||
|
(2, _('Two')),
|
||||||
|
(3, _('Three')),
|
||||||
|
(4, _('Four')),
|
||||||
|
(5, _('Five')),
|
||||||
|
)
|
||||||
|
|
||||||
|
country = models.ForeignKey('location.Country', null=True, blank=True,
|
||||||
|
default=None, on_delete=models.CASCADE,
|
||||||
|
verbose_name=_('Country'))
|
||||||
|
toque_number = models.IntegerField(choices=TOQUE_NUMBER_CHOICES)
|
||||||
|
public_mark_min_value = models.IntegerField()
|
||||||
|
public_mark_max_value = models.IntegerField()
|
||||||
|
|
||||||
|
objects = RatingStrategyManager.from_queryset(RatingStrategyQuerySet)()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class."""
|
||||||
|
|
||||||
|
verbose_name = _('Rating strategy')
|
||||||
|
verbose_name_plural = _('Rating strategy')
|
||||||
|
unique_together = ('country', 'toque_number')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'{self.country.code if self.country else "Other country"}. ' \
|
||||||
|
f'"{self.toque_number}": {self.public_mark_min_value}-' \
|
||||||
|
f'{self.public_mark_max_value}'
|
||||||
|
|
@ -15,6 +15,7 @@ class TagBaseSerializer(serializers.ModelSerializer):
|
||||||
# todo: refactor this
|
# todo: refactor this
|
||||||
# label_translated = TranslatedField()
|
# label_translated = TranslatedField()
|
||||||
label_translated = serializers.CharField(source='value', read_only=True, allow_null=True)
|
label_translated = serializers.CharField(source='value', read_only=True, allow_null=True)
|
||||||
|
index_name = serializers.CharField(source='value', read_only=True, allow_null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
@ -23,6 +24,7 @@ class TagBaseSerializer(serializers.ModelSerializer):
|
||||||
fields = (
|
fields = (
|
||||||
'id',
|
'id',
|
||||||
'label_translated',
|
'label_translated',
|
||||||
|
'index_name',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user