Merge branch 'develop' into feature/bo-endpoints
# Conflicts: # apps/product/serializers/common.py
This commit is contained in:
commit
23a1af1870
|
|
@ -1,9 +1,8 @@
|
||||||
from transfer.serializers.notification import SubscriberSerializer
|
|
||||||
from notification.models import Subscriber
|
|
||||||
from transfer.models import EmailAddresses
|
|
||||||
from django.db.models import Value, IntegerField, F
|
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
|
from transfer.models import EmailAddresses
|
||||||
|
from transfer.serializers.notification import SubscriberSerializer
|
||||||
|
|
||||||
|
|
||||||
def transfer_subscriber():
|
def transfer_subscriber():
|
||||||
queryset = EmailAddresses.objects.filter(state="usable")
|
queryset = EmailAddresses.objects.filter(state="usable")
|
||||||
|
|
@ -16,6 +15,10 @@ def transfer_subscriber():
|
||||||
pprint(f"News serializer errors: {serialized_data.errors}")
|
pprint(f"News serializer errors: {serialized_data.errors}")
|
||||||
|
|
||||||
|
|
||||||
|
def transfer_newsletter_subscriber():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
data_types = {
|
data_types = {
|
||||||
"subscriber": [transfer_subscriber]
|
"subscriber": [transfer_subscriber]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,7 @@ class Command(BaseCommand):
|
||||||
def add_category_tag(self):
|
def add_category_tag(self):
|
||||||
objects = []
|
objects = []
|
||||||
for c in tqdm(self.category_sql(), desc='Add category tags'):
|
for c in tqdm(self.category_sql(), desc='Add category tags'):
|
||||||
categories = TagCategory.objects.filter(index_name=c.category,
|
categories = TagCategory.objects.filter(index_name=c.category
|
||||||
value_type=c.value_type
|
|
||||||
)
|
)
|
||||||
if not categories.exists():
|
if not categories.exists():
|
||||||
objects.append(
|
objects.append(
|
||||||
|
|
@ -91,8 +90,9 @@ class Command(BaseCommand):
|
||||||
tag.filter(lower_value=t.tag_value, category=category)
|
tag.filter(lower_value=t.tag_value, category=category)
|
||||||
products = Product.objects.filter(old_id=t.product_id)
|
products = Product.objects.filter(old_id=t.product_id)
|
||||||
if products.exists():
|
if products.exists():
|
||||||
products.tags.add(tag)
|
for p in products:
|
||||||
products.save()
|
p.tags.add(*list(tag))
|
||||||
|
p.save()
|
||||||
|
|
||||||
self.stdout.write(self.style.WARNING(f'Add or get tag objects.'))
|
self.stdout.write(self.style.WARNING(f'Add or get tag objects.'))
|
||||||
|
|
||||||
|
|
@ -112,5 +112,5 @@ class Command(BaseCommand):
|
||||||
def handle(self, *args, **kwargs):
|
def handle(self, *args, **kwargs):
|
||||||
self.add_category_tag()
|
self.add_category_tag()
|
||||||
self.add_tag()
|
self.add_tag()
|
||||||
|
self.check_tag()
|
||||||
self.add_product_tag()
|
self.add_product_tag()
|
||||||
self.check_tag()
|
|
||||||
|
|
@ -89,6 +89,8 @@ class ProductBaseSerializer(serializers.ModelSerializer):
|
||||||
subtypes = ProductSubTypeBaseSerializer(many=True, read_only=True)
|
subtypes = ProductSubTypeBaseSerializer(many=True, read_only=True)
|
||||||
establishment_detail = EstablishmentShortSerializer(source='establishment', read_only=True)
|
establishment_detail = EstablishmentShortSerializer(source='establishment', read_only=True)
|
||||||
tags = ProductTagSerializer(source='related_tags', many=True, read_only=True)
|
tags = ProductTagSerializer(source='related_tags', many=True, read_only=True)
|
||||||
|
wine_region = WineRegionBaseSerializer(read_only=True)
|
||||||
|
wine_colors = TagBaseSerializer(many=True, read_only=True)
|
||||||
preview_image_url = serializers.URLField(source='preview_main_image_url',
|
preview_image_url = serializers.URLField(source='preview_main_image_url',
|
||||||
allow_null=True,
|
allow_null=True,
|
||||||
read_only=True)
|
read_only=True)
|
||||||
|
|
@ -107,6 +109,8 @@ class ProductBaseSerializer(serializers.ModelSerializer):
|
||||||
'vintage',
|
'vintage',
|
||||||
'tags',
|
'tags',
|
||||||
'preview_image_url',
|
'preview_image_url',
|
||||||
|
'wine_region',
|
||||||
|
'wine_colors',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -117,9 +121,7 @@ class ProductDetailSerializer(ProductBaseSerializer):
|
||||||
awards = AwardSerializer(many=True, read_only=True)
|
awards = AwardSerializer(many=True, read_only=True)
|
||||||
classifications = ProductClassificationBaseSerializer(many=True, read_only=True)
|
classifications = ProductClassificationBaseSerializer(many=True, read_only=True)
|
||||||
standards = ProductStandardBaseSerializer(many=True, read_only=True)
|
standards = ProductStandardBaseSerializer(many=True, read_only=True)
|
||||||
wine_region = WineRegionBaseSerializer(read_only=True)
|
|
||||||
wine_sub_region = WineSubRegionBaseSerializer(read_only=True)
|
wine_sub_region = WineSubRegionBaseSerializer(read_only=True)
|
||||||
wine_colors = TagBaseSerializer(many=True, read_only=True)
|
|
||||||
bottles_produced = TagBaseSerializer(many=True, read_only=True)
|
bottles_produced = TagBaseSerializer(many=True, read_only=True)
|
||||||
sugar_contents = TagBaseSerializer(many=True, read_only=True)
|
sugar_contents = TagBaseSerializer(many=True, read_only=True)
|
||||||
image_url = serializers.ImageField(source='main_image_url',
|
image_url = serializers.ImageField(source='main_image_url',
|
||||||
|
|
@ -133,9 +135,7 @@ class ProductDetailSerializer(ProductBaseSerializer):
|
||||||
'awards',
|
'awards',
|
||||||
'classifications',
|
'classifications',
|
||||||
'standards',
|
'standards',
|
||||||
'wine_region',
|
|
||||||
'wine_sub_region',
|
'wine_sub_region',
|
||||||
'wine_colors',
|
|
||||||
'bottles_produced',
|
'bottles_produced',
|
||||||
'sugar_contents',
|
'sugar_contents',
|
||||||
'image_url',
|
'image_url',
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from review.models import Review
|
|
||||||
|
from review.models import Review, Inquiries, GridItems
|
||||||
|
|
||||||
|
|
||||||
class ReviewBaseSerializer(serializers.ModelSerializer):
|
class ReviewBaseSerializer(serializers.ModelSerializer):
|
||||||
|
|
@ -27,3 +28,41 @@ class ReviewShortSerializer(ReviewBaseSerializer):
|
||||||
fields = (
|
fields = (
|
||||||
'text_translated',
|
'text_translated',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class InquiriesBaseSerializer(serializers.ModelSerializer):
|
||||||
|
"""Serializer for model Inquiries."""
|
||||||
|
class Meta:
|
||||||
|
model = Inquiries
|
||||||
|
fields = (
|
||||||
|
'id',
|
||||||
|
'review',
|
||||||
|
'comment',
|
||||||
|
'final_comment',
|
||||||
|
'mark',
|
||||||
|
'attachment_file',
|
||||||
|
'author',
|
||||||
|
'bill_file',
|
||||||
|
'price',
|
||||||
|
'moment',
|
||||||
|
'gallery',
|
||||||
|
'decibels',
|
||||||
|
'nomination',
|
||||||
|
'nominee',
|
||||||
|
'published',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class GridItemsBaseSerializer(serializers.ModelSerializer):
|
||||||
|
"""Serializer for model GridItems."""
|
||||||
|
class Meta:
|
||||||
|
model = GridItems
|
||||||
|
fields = (
|
||||||
|
'id',
|
||||||
|
'inquiry',
|
||||||
|
'sub_name',
|
||||||
|
'name',
|
||||||
|
'value',
|
||||||
|
'desc',
|
||||||
|
'dish_title',
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,134 @@
|
||||||
from django.test import TestCase
|
from http.cookies import SimpleCookie
|
||||||
|
|
||||||
# Create your tests here.
|
from rest_framework import status
|
||||||
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
|
from account.models import User
|
||||||
|
from location.models import Country
|
||||||
|
from review.models import Review, Inquiries, GridItems
|
||||||
|
from translation.models import Language
|
||||||
|
|
||||||
|
|
||||||
|
class BaseTestCase(APITestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.username = 'test_user'
|
||||||
|
self.password = 'test_user_password'
|
||||||
|
self.email = 'test_user@mail.com'
|
||||||
|
self.user = User.objects.create_user(
|
||||||
|
username=self.username,
|
||||||
|
email=self.email,
|
||||||
|
password=self.password,
|
||||||
|
)
|
||||||
|
|
||||||
|
tokens = User.create_jwt_tokens(self.user)
|
||||||
|
self.client.cookies = SimpleCookie({
|
||||||
|
'access_token': tokens.get('access_token'),
|
||||||
|
'refresh_token': tokens.get('refresh_token'),
|
||||||
|
})
|
||||||
|
|
||||||
|
self.lang = Language.objects.create(
|
||||||
|
title='Russia',
|
||||||
|
locale='ru-RU'
|
||||||
|
)
|
||||||
|
|
||||||
|
self.country_ru = Country.objects.create(
|
||||||
|
name={'en-GB': 'Russian'},
|
||||||
|
code='RU',
|
||||||
|
)
|
||||||
|
|
||||||
|
self.test_review = Review.objects.create(
|
||||||
|
reviewer=self.user,
|
||||||
|
status=Review.READY,
|
||||||
|
language=self.lang,
|
||||||
|
vintage=2020,
|
||||||
|
country=self.country_ru,
|
||||||
|
text={'en-GB': 'Text review'},
|
||||||
|
created_by=self.user,
|
||||||
|
modified_by=self.user,
|
||||||
|
object_id=1,
|
||||||
|
content_type_id=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.test_inquiry = Inquiries.objects.create(
|
||||||
|
review=self.test_review,
|
||||||
|
author=self.user,
|
||||||
|
comment='Test comment',
|
||||||
|
)
|
||||||
|
|
||||||
|
self.test_grid = GridItems.objects.create(
|
||||||
|
inquiry=self.test_inquiry,
|
||||||
|
name='Test name',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class InquiriesTestCase(BaseTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
def test_inquiry_list(self):
|
||||||
|
response = self.client.get('/api/back/review/inquiries/')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
def test_inquiry_list_by_review_id(self):
|
||||||
|
response = self.client.get(f'/api/back/review/{self.test_review.id}/inquiries/')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
def test_inquiry_post(self):
|
||||||
|
test_inquiry = {
|
||||||
|
'review': self.test_review.pk,
|
||||||
|
'author': self.user.pk,
|
||||||
|
'comment': 'New test comment',
|
||||||
|
}
|
||||||
|
response = self.client.post('/api/back/review/inquiries/', data=test_inquiry)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||||
|
|
||||||
|
def test_inquiry_detail(self):
|
||||||
|
response = self.client.get(f'/api/back/review/inquiries/{self.test_inquiry.id}/')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
def test_inquiry_detail_put(self):
|
||||||
|
data = {
|
||||||
|
'id': self.test_inquiry.id,
|
||||||
|
'review': self.test_review.pk,
|
||||||
|
'author': self.user.pk,
|
||||||
|
'comment': 'New test comment 2',
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.put(f'/api/back/review/inquiries/{self.test_inquiry.id}/', data=data)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
|
class GridItemsTestCase(BaseTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
def test_grid_list(self):
|
||||||
|
response = self.client.get('/api/back/review/inquiries/grid/')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
def test_grid_list_by_inquiry_id(self):
|
||||||
|
response = self.client.get(f'/api/back/review/inquiries/{self.test_inquiry.id}/grid/')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
def test_grid_post(self):
|
||||||
|
test_grid = {
|
||||||
|
'inquiry': self.test_inquiry.pk,
|
||||||
|
'name': 'New test name',
|
||||||
|
}
|
||||||
|
response = self.client.post('/api/back/review/inquiries/grid/', data=test_grid)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||||
|
|
||||||
|
def test_grid_detail(self):
|
||||||
|
response = self.client.get(f'/api/back/review/inquiries/grid/{self.test_grid.id}/')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
|
def test_grid_detail_put(self):
|
||||||
|
data = {
|
||||||
|
'id': self.test_grid.id,
|
||||||
|
'inquiry': self.test_inquiry.pk,
|
||||||
|
'name': 'New test name 2',
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.put(f'/api/back/review/inquiries/grid/{self.test_inquiry.id}/', data=data)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,10 @@ app_name = 'review'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.ReviewLstView.as_view(), name='review-list-create'),
|
path('', views.ReviewLstView.as_view(), name='review-list-create'),
|
||||||
path('<int:id>/', views.ReviewRUDView.as_view(), name='review-crud'),
|
path('<int:id>/', views.ReviewRUDView.as_view(), name='review-crud'),
|
||||||
|
path('<int:review_id>/inquiries/', views.InquiriesLstView.as_view(), name='inquiries-list'),
|
||||||
|
path('inquiries/', views.InquiriesLstView.as_view(), name='inquiries-list-create'),
|
||||||
|
path('inquiries/<int:id>/', views.InquiriesRUDView.as_view(), name='inquiries-crud'),
|
||||||
|
path('inquiries/<int:inquiry_id>/grid/', views.GridItemsLstView.as_view(), name='grid-list-create'),
|
||||||
|
path('inquiries/grid/', views.GridItemsLstView.as_view(), name='grid-list-create'),
|
||||||
|
path('inquiries/grid/<int:id>/', views.GridItemsRUDView.as_view(), name='grid-crud'),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
from rest_framework import generics, permissions
|
from rest_framework import generics, permissions
|
||||||
from review import serializers
|
|
||||||
from review import models
|
from review import models
|
||||||
|
from review import serializers
|
||||||
from utils.permissions import IsReviewerManager, IsRestaurantReviewer
|
from utils.permissions import IsReviewerManager, IsRestaurantReviewer
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -8,12 +9,55 @@ class ReviewLstView(generics.ListCreateAPIView):
|
||||||
"""Comment list create view."""
|
"""Comment list create view."""
|
||||||
serializer_class = serializers.ReviewBaseSerializer
|
serializer_class = serializers.ReviewBaseSerializer
|
||||||
queryset = models.Review.objects.all()
|
queryset = models.Review.objects.all()
|
||||||
permission_classes = [permissions.IsAuthenticatedOrReadOnly,]
|
permission_classes = [permissions.IsAuthenticatedOrReadOnly, ]
|
||||||
|
|
||||||
|
|
||||||
class ReviewRUDView(generics.RetrieveUpdateDestroyAPIView):
|
class ReviewRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
"""Comment RUD view."""
|
"""Comment RUD view."""
|
||||||
serializer_class = serializers.ReviewBaseSerializer
|
serializer_class = serializers.ReviewBaseSerializer
|
||||||
queryset = models.Review.objects.all()
|
queryset = models.Review.objects.all()
|
||||||
permission_classes = [IsReviewerManager|IsRestaurantReviewer]
|
permission_classes = [IsReviewerManager | IsRestaurantReviewer]
|
||||||
|
lookup_field = 'id'
|
||||||
|
|
||||||
|
|
||||||
|
class InquiriesLstView(generics.ListCreateAPIView):
|
||||||
|
"""Inquiries list create view."""
|
||||||
|
|
||||||
|
serializer_class = serializers.InquiriesBaseSerializer
|
||||||
|
queryset = models.Inquiries.objects.all()
|
||||||
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
review_id = self.kwargs.get('review_id')
|
||||||
|
if review_id:
|
||||||
|
return super().get_queryset().filter(review_id=review_id)
|
||||||
|
return super().get_queryset()
|
||||||
|
|
||||||
|
|
||||||
|
class InquiriesRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
"""Inquiries RUD view."""
|
||||||
|
serializer_class = serializers.InquiriesBaseSerializer
|
||||||
|
queryset = models.Inquiries.objects.all()
|
||||||
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
|
lookup_field = 'id'
|
||||||
|
|
||||||
|
|
||||||
|
class GridItemsLstView(generics.ListCreateAPIView):
|
||||||
|
"""GridItems list create view."""
|
||||||
|
serializer_class = serializers.GridItemsBaseSerializer
|
||||||
|
queryset = models.GridItems.objects.all()
|
||||||
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
inquiry_id = self.kwargs.get('inquiry_id')
|
||||||
|
if inquiry_id:
|
||||||
|
return super().get_queryset().filter(inquiry_id=inquiry_id)
|
||||||
|
return super().get_queryset()
|
||||||
|
|
||||||
|
|
||||||
|
class GridItemsRUDView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
"""GridItems RUD view."""
|
||||||
|
serializer_class = serializers.GridItemsBaseSerializer
|
||||||
|
queryset = models.GridItems.objects.all()
|
||||||
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
lookup_field = 'id'
|
lookup_field = 'id'
|
||||||
|
|
|
||||||
18
apps/tag/migrations/0013_auto_20191113_0930.py
Normal file
18
apps/tag/migrations/0013_auto_20191113_0930.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.7 on 2019-11-13 09:30
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('tag', '0012_merge_20191112_1552'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='tagcategory',
|
||||||
|
name='value_type',
|
||||||
|
field=models.CharField(choices=[('string', 'string'), ('list', 'list'), ('integer', 'integer'), ('float', 'float'), ('percentage', 'percentage')], default='list', max_length=255, verbose_name='value type'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -1156,7 +1156,6 @@ class GridItems(MigrateMixin):
|
||||||
|
|
||||||
|
|
||||||
class Assemblages(MigrateMixin):
|
class Assemblages(MigrateMixin):
|
||||||
|
|
||||||
using = 'legacy'
|
using = 'legacy'
|
||||||
|
|
||||||
percent = models.FloatField()
|
percent = models.FloatField()
|
||||||
|
|
@ -1169,7 +1168,6 @@ class Assemblages(MigrateMixin):
|
||||||
|
|
||||||
|
|
||||||
class Cepages(MigrateMixin):
|
class Cepages(MigrateMixin):
|
||||||
|
|
||||||
using = 'legacy'
|
using = 'legacy'
|
||||||
|
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
|
|
@ -1177,3 +1175,18 @@ class Cepages(MigrateMixin):
|
||||||
class Meta:
|
class Meta:
|
||||||
managed = False
|
managed = False
|
||||||
db_table = 'cepages'
|
db_table = 'cepages'
|
||||||
|
|
||||||
|
|
||||||
|
class NewsletterSubscriber(MigrateMixin):
|
||||||
|
using = 'legacy'
|
||||||
|
|
||||||
|
site = models.ForeignKey(Sites, models.DO_NOTHING, blank=True, null=True)
|
||||||
|
email_address = models.ForeignKey(EmailAddresses, models.DO_NOTHING, blank=True, null=True)
|
||||||
|
state = models.CharField(max_length=255, blank=True, null=True)
|
||||||
|
consent_at = models.DateTimeField()
|
||||||
|
created_at = models.DateTimeField()
|
||||||
|
updated_at = models.DateTimeField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
managed = False
|
||||||
|
db_table = 'newsletter_subscriber'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user