Merge branch 'develop' into feature/permission_winery
This commit is contained in:
commit
cbf998569a
|
|
@ -35,6 +35,7 @@ class ContactPhoneInline(admin.TabularInline):
|
|||
class GalleryImageInline(admin.TabularInline):
|
||||
"""Gallery image inline admin."""
|
||||
model = models.EstablishmentGallery
|
||||
raw_id_fields = ['image', ]
|
||||
extra = 0
|
||||
|
||||
|
||||
|
|
@ -61,17 +62,20 @@ class ProductInline(admin.TabularInline):
|
|||
|
||||
class CompanyInline(admin.TabularInline):
|
||||
model = models.Company
|
||||
raw_id_fields = ['establishment', 'address']
|
||||
extra = 0
|
||||
|
||||
|
||||
class EstablishmentNote(admin.TabularInline):
|
||||
model = models.EstablishmentNote
|
||||
extra = 0
|
||||
raw_id_fields = ['user', ]
|
||||
|
||||
|
||||
class PurchasedProduct(admin.TabularInline):
|
||||
class PurchasedProductInline(admin.TabularInline):
|
||||
model = PurchasedProduct
|
||||
extra = 0
|
||||
raw_id_fields = ['product', ]
|
||||
|
||||
|
||||
@admin.register(models.Establishment)
|
||||
|
|
@ -80,13 +84,12 @@ class EstablishmentAdmin(BaseModelAdminMixin, admin.ModelAdmin):
|
|||
list_display = ['id', '__str__', 'image_tag', ]
|
||||
search_fields = ['id', 'name', 'index_name', 'slug']
|
||||
list_filter = ['public_mark', 'toque_number']
|
||||
inlines = [GalleryImageInline, CompanyInline, EstablishmentNote,
|
||||
PurchasedProduct]
|
||||
|
||||
inlines = [CompanyInline, EstablishmentNote, GalleryImageInline,
|
||||
PurchasedProductInline, ]
|
||||
# inlines = [
|
||||
# AwardInline, ContactPhoneInline, ContactEmailInline,
|
||||
# ReviewInline, CommentInline, ProductInline]
|
||||
raw_id_fields = ('address',)
|
||||
raw_id_fields = ('address', 'collections', 'tags', 'schedule')
|
||||
|
||||
|
||||
@admin.register(models.Position)
|
||||
|
|
|
|||
|
|
@ -457,9 +457,7 @@ class Establishment(GalleryModelMixin, ProjectBaseMixin, URLImageMixin,
|
|||
def visible_tags(self):
|
||||
return super().visible_tags \
|
||||
.exclude(category__index_name__in=['guide', 'collection', 'purchased_item',
|
||||
'business_tag', 'business_tags_de']) \
|
||||
.exclude(value__in=['rss', 'rss_selection']) \
|
||||
\
|
||||
'business_tag', 'business_tags_de', 'tag'])
|
||||
# todo: recalculate toque_number
|
||||
|
||||
def recalculate_toque_number(self):
|
||||
|
|
|
|||
|
|
@ -427,11 +427,13 @@ class EstablishmentSimilarSerializer(EstablishmentBaseSerializer):
|
|||
address = AddressDetailSerializer(read_only=True)
|
||||
schedule = ScheduleRUDSerializer(many=True, allow_null=True)
|
||||
establishment_type = EstablishmentTypeGeoSerializer()
|
||||
artisan_category = TagBaseSerializer(many=True, allow_null=True)
|
||||
|
||||
class Meta(EstablishmentBaseSerializer.Meta):
|
||||
fields = EstablishmentBaseSerializer.Meta.fields + [
|
||||
'schedule',
|
||||
'establishment_type',
|
||||
'artisan_category',
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ class FavoritesEstablishmentListView(generics.ListAPIView):
|
|||
def get_queryset(self):
|
||||
"""Override get_queryset method"""
|
||||
return Establishment.objects.filter(favorites__user=self.request.user) \
|
||||
.order_by('-favorites').with_base_related()
|
||||
.order_by('-favorites').with_base_related() \
|
||||
.with_certain_tag_category_related('shop_category', 'artisan_category')
|
||||
|
||||
|
||||
class FavoritesProductListView(generics.ListAPIView):
|
||||
|
|
|
|||
29
apps/location/management/commands/fix_address.py
Normal file
29
apps/location/management/commands/fix_address.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from tqdm import tqdm
|
||||
|
||||
from location.models import Address
|
||||
from transfer.models import Locations
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = """Fix address, clear number field and fill street_name_1 like in old db"""
|
||||
|
||||
def handle(self, *args, **kwarg):
|
||||
addresses = Address.objects.filter(
|
||||
old_id__isnull=False
|
||||
).values_list('old_id', flat=True)
|
||||
|
||||
old_addresses = Locations.objects.filter(
|
||||
id__in=list(addresses)
|
||||
).values_list('id', 'address')
|
||||
|
||||
update_address = []
|
||||
for idx, address in tqdm(old_addresses):
|
||||
new_address = Address.objects.filter(old_id=idx).first()
|
||||
if new_address:
|
||||
new_address.number = 0
|
||||
new_address.street_name_1 = address
|
||||
update_address.append(new_address)
|
||||
|
||||
Address.objects.bulk_update(update_address, ['number', 'street_name_1'])
|
||||
self.stdout.write(self.style.WARNING(f'Updated addresses: {len(update_address)}'))
|
||||
25
apps/product/management/commands/add_public_mark.py
Normal file
25
apps/product/management/commands/add_public_mark.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from tqdm import tqdm
|
||||
|
||||
from product.models import Product
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = """Add public_mark to product from reviews."""
|
||||
|
||||
def handle(self, *args, **kwarg):
|
||||
update_products = []
|
||||
products = Product.objects.filter(
|
||||
public_mark__isnull=True,
|
||||
reviews__isnull=False).distinct()
|
||||
|
||||
for product in tqdm(products):
|
||||
review = product.reviews.published().filter(
|
||||
mark__isnull=False).order_by('-published_at').first()
|
||||
if review:
|
||||
product.public_mark = review.mark
|
||||
update_products.append(product)
|
||||
|
||||
Product.objects.bulk_update(update_products, ['public_mark', ])
|
||||
self.stdout.write(
|
||||
self.style.WARNING(f'Updated products: {len(update_products)}'))
|
||||
|
|
@ -115,12 +115,8 @@ def transfer_product_reviews():
|
|||
products = Product.objects.filter(
|
||||
old_id__isnull=False).values_list('old_id', flat=True)
|
||||
|
||||
users = User.objects.filter(
|
||||
old_id__isnull=False).values_list('old_id', flat=True)
|
||||
|
||||
queryset = Reviews.objects.filter(
|
||||
product_id__in=list(products),
|
||||
reviewer_id__in=list(users),
|
||||
).values('id', 'reviewer_id', 'aasm_state', 'created_at', 'product_id', 'mark', 'vintage')
|
||||
|
||||
serialized_data = ProductReviewSerializer(data=list(queryset.values()), many=True)
|
||||
|
|
|
|||
|
|
@ -13,24 +13,13 @@ class CustomGeoSpatialFilteringFilterBackend(GeoSpatialFilteringFilterBackend):
|
|||
|
||||
@staticmethod
|
||||
def calculate_center(first, second):
|
||||
if second[1] < 0 < first[1]:
|
||||
reverse_first, reverse_second = 180 - abs(first[1]), 180 - abs(second[1])
|
||||
diff = (reverse_first + reverse_second) / 2
|
||||
|
||||
if reverse_first < reverse_second:
|
||||
result_part = -180 + (180 + second[1] - diff)
|
||||
|
||||
else:
|
||||
result_part = 180 - (180 - first[1] - diff)
|
||||
|
||||
elif second[1] < 0 > first[1] or second[1] > 0 < first[1]:
|
||||
reverse_first, reverse_second = 180 - abs(first[1]), 180 - abs(second[1])
|
||||
result_part = ((reverse_first + reverse_second) / 2) * (-1 + (second[1] < 0) * 2)
|
||||
|
||||
if second[1] < first[1]:
|
||||
res_longtitude = first[1] + (360 + abs(first[1]) - abs(second[1])) / 2
|
||||
else:
|
||||
result_part = (first[1] + second[1]) / 2
|
||||
res_longtitude = first[1] + (second[1] - first[1]) / 2
|
||||
|
||||
return (first[0] + second[0]) / 2, result_part
|
||||
# return (first[0] + second[0]) / 2, result_part
|
||||
return (first[0] + second[0]) / 2, res_longtitude
|
||||
|
||||
def filter_queryset(self, request, queryset, view):
|
||||
ret = super().filter_queryset(request, queryset, view)
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class ProductReviewSerializer(ReviewSerializer):
|
|||
product_id = serializers.IntegerField()
|
||||
created_at = serializers.DateTimeField(format='%m-%d-%Y %H:%M:%S')
|
||||
aasm_state = serializers.CharField(allow_null=True)
|
||||
reviewer_id = serializers.IntegerField()
|
||||
reviewer_id = serializers.IntegerField(allow_null=True)
|
||||
id = serializers.IntegerField()
|
||||
|
||||
def validate(self, data):
|
||||
|
|
@ -82,9 +82,8 @@ class ProductReviewSerializer(ReviewSerializer):
|
|||
@staticmethod
|
||||
def get_reviewer(data):
|
||||
user = User.objects.filter(old_id=data['reviewer_id']).first()
|
||||
if not user:
|
||||
raise ValueError(f"User account not found with old_id {data['reviewer_id']}")
|
||||
return user
|
||||
if user:
|
||||
return user
|
||||
|
||||
@staticmethod
|
||||
def get_product(data):
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
./manage.py transfer -a
|
||||
./manage.py transfer -d
|
||||
./manage.py transfer -e
|
||||
./manage.py upd_transportation
|
||||
./manage.py transfer --fill_city_gallery
|
||||
./manage.py transfer -l
|
||||
./manage.py transfer --product
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user