Merge branch 'develop' into feature/site-feature-api
This commit is contained in:
commit
4becc39b3e
|
|
@ -92,7 +92,11 @@ class UserBaseSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
model = models.User
|
model = models.User
|
||||||
fields = (
|
fields = (
|
||||||
|
'id',
|
||||||
'fullname',
|
'fullname',
|
||||||
|
'first_name',
|
||||||
|
'last_name',
|
||||||
|
'email',
|
||||||
'cropped_image_url',
|
'cropped_image_url',
|
||||||
'image_url',
|
'image_url',
|
||||||
)
|
)
|
||||||
|
|
|
||||||
36
apps/establishment/management/commands/fix_scheduler.py
Normal file
36
apps/establishment/management/commands/fix_scheduler.py
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
from establishment.models import Establishment
|
||||||
|
from transfer.models import Establishments
|
||||||
|
from transfer.serializers.establishment import EstablishmentSerializer
|
||||||
|
from timetable.models import Timetable
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Fix scheduler'
|
||||||
|
|
||||||
|
@transaction.atomic
|
||||||
|
def handle(self, *args, **kwargs):
|
||||||
|
count = 0
|
||||||
|
establishments = Establishment.objects.all()
|
||||||
|
old_est_list = Establishments.objects.prefetch_related(
|
||||||
|
'schedules_set',
|
||||||
|
)
|
||||||
|
# remove old records of Timetable
|
||||||
|
Timetable.objects.all().delete()
|
||||||
|
|
||||||
|
for est in tqdm(establishments, desc="Fix scheduler"):
|
||||||
|
old_est = old_est_list.filter(id=est.old_id).first()
|
||||||
|
|
||||||
|
if old_est and old_est.schedules_set.exists():
|
||||||
|
old_schedule = old_est.schedules_set.first()
|
||||||
|
timetable = old_schedule.timetable
|
||||||
|
if timetable:
|
||||||
|
new_schedules = EstablishmentSerializer.get_schedules(timetable)
|
||||||
|
est.schedule.add(*new_schedules)
|
||||||
|
est.save()
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
self.stdout.write(self.style.WARNING(f'Update {count} objects.'))
|
||||||
|
|
@ -38,7 +38,7 @@ class EstablishmentListView(EstablishmentMixinView, generics.ListAPIView):
|
||||||
.with_extended_address_related().with_currency_related() \
|
.with_extended_address_related().with_currency_related() \
|
||||||
.with_certain_tag_category_related('category', 'restaurant_category') \
|
.with_certain_tag_category_related('category', 'restaurant_category') \
|
||||||
.with_certain_tag_category_related('cuisine', 'restaurant_cuisine') \
|
.with_certain_tag_category_related('cuisine', 'restaurant_cuisine') \
|
||||||
.with_ceratin_tag_category_related('shop_category', 'artisan_category')
|
.with_certain_tag_category_related('shop_category', 'artisan_category')
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentRetrieveView(EstablishmentMixinView, generics.RetrieveAPIView):
|
class EstablishmentRetrieveView(EstablishmentMixinView, generics.RetrieveAPIView):
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ class CustomGeoSpatialFilteringFilterBackend(GeoSpatialFilteringFilterBackend):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def calculate_center(first, second):
|
def calculate_center(first, second):
|
||||||
if second[1] < 0 <= first[1]:
|
if second[1] < 0 < first[1]:
|
||||||
reverse_first, reverse_second = 180 - abs(first[1]), 180 - abs(second[1])
|
reverse_first, reverse_second = 180 - abs(first[1]), 180 - abs(second[1])
|
||||||
diff = (reverse_first + reverse_second) / 2
|
diff = (reverse_first + reverse_second) / 2
|
||||||
|
|
||||||
|
|
@ -21,6 +21,16 @@ class CustomGeoSpatialFilteringFilterBackend(GeoSpatialFilteringFilterBackend):
|
||||||
else:
|
else:
|
||||||
result_part = 180 - (180 - first[1] - diff)
|
result_part = 180 - (180 - first[1] - diff)
|
||||||
|
|
||||||
|
elif second[1] < 0 > first[1]:
|
||||||
|
diff = abs(abs(second[1]) - abs(first[1]))
|
||||||
|
|
||||||
|
if diff > 90:
|
||||||
|
reverse_first, reverse_second = 180 - abs(first[1]), 180 - abs(second[1])
|
||||||
|
result_part = (reverse_first + reverse_second) / 2
|
||||||
|
|
||||||
|
else:
|
||||||
|
result_part = (first[1] + second[1]) / 2
|
||||||
|
|
||||||
else:
|
else:
|
||||||
result_part = (first[1] + second[1]) / 2
|
result_part = (first[1] + second[1]) / 2
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,10 @@ class TagsFilterSet(TagsBaseFilterSet):
|
||||||
|
|
||||||
def by_establishment_type(self, queryset, name, value):
|
def by_establishment_type(self, queryset, name, value):
|
||||||
if value == EstablishmentType.ARTISAN:
|
if value == EstablishmentType.ARTISAN:
|
||||||
return models.Tag.objects.by_category_index_name('shop_category')[0:8]
|
qs = models.Tag.objects.by_category_index_name('shop_category')
|
||||||
|
if self.request.country_code and self.request.country_code not in settings.INTERNATIONAL_COUNTRY_CODES:
|
||||||
|
qs = qs.filter(establishments__address__city__country__code=self.request.country_code).distinct('id')
|
||||||
|
return qs.exclude(establishments__isnull=True)[0:8]
|
||||||
return queryset.by_establishment_type(value)
|
return queryset.by_establishment_type(value)
|
||||||
|
|
||||||
# TMP TODO remove it later
|
# TMP TODO remove it later
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ class EstablishmentSerializer(serializers.ModelSerializer):
|
||||||
weekdays = {
|
weekdays = {
|
||||||
'su': Timetable.SUNDAY,
|
'su': Timetable.SUNDAY,
|
||||||
'mo': Timetable.MONDAY,
|
'mo': Timetable.MONDAY,
|
||||||
'tu': Timetable.THURSDAY,
|
'tu': Timetable.TUESDAY,
|
||||||
'we': Timetable.WEDNESDAY,
|
'we': Timetable.WEDNESDAY,
|
||||||
'th': Timetable.THURSDAY,
|
'th': Timetable.THURSDAY,
|
||||||
'fr': Timetable.FRIDAY,
|
'fr': Timetable.FRIDAY,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user