Merge branch 'migration_fix' into develop
# Conflicts: # apps/establishment/admin.py # apps/transfer/models.py
This commit is contained in:
commit
962d24f737
|
|
@ -60,6 +60,8 @@ class EstablishmentAdmin(BaseModelAdminMixin, admin.ModelAdmin):
|
|||
inlines = [
|
||||
AwardInline, ContactPhoneInline, ContactEmailInline,
|
||||
ReviewInline, CommentInline, ProductInline]
|
||||
raw_id_fields = ('address',)
|
||||
fields = ['old_id', 'name']
|
||||
|
||||
|
||||
@admin.register(models.Position)
|
||||
|
|
|
|||
14
apps/establishment/migrations/0046_merge_20191030_0858.py
Normal file
14
apps/establishment/migrations/0046_merge_20191030_0858.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# Generated by Django 2.2.4 on 2019-10-30 08:58
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('establishment', '0045_auto_20191029_0719'),
|
||||
('establishment', '0044_position_index_name'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
]
|
||||
14
apps/location/migrations/0019_merge_20191030_0858.py
Normal file
14
apps/location/migrations/0019_merge_20191030_0858.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# Generated by Django 2.2.4 on 2019-10-30 08:58
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('location', '0018_address_old_id'),
|
||||
('location', '0013_wineappellation_wineregion'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
]
|
||||
14
apps/news/migrations/0032_merge_20191030_0858.py
Normal file
14
apps/news/migrations/0032_merge_20191030_0858.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# Generated by Django 2.2.4 on 2019-10-30 08:58
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('news', '0029_auto_20191025_1241'),
|
||||
('news', '0031_merge_20191029_0858'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
]
|
||||
|
|
@ -4,6 +4,7 @@ from django.db.models import Aggregate, CharField, Value
|
|||
from django.db.models import IntegerField, F
|
||||
|
||||
from news.models import NewsType
|
||||
from tag.models import TagCategory
|
||||
from transfer.models import PageTexts
|
||||
from transfer.serializers.news import NewsSerializer
|
||||
|
||||
|
|
@ -23,16 +24,21 @@ class GroupConcat(Aggregate):
|
|||
|
||||
def transfer_news():
|
||||
news_type, _ = NewsType.objects.get_or_create(name='News')
|
||||
tag_cat, _ = TagCategory.objects.get_or_create(index_name='tag', public=True)
|
||||
news_type.tag_categories.add(tag_cat)
|
||||
news_type.save()
|
||||
|
||||
queryset = PageTexts.objects.filter(
|
||||
page__type='News',
|
||||
).annotate(
|
||||
news_type=Value(news_type.id, output_field=IntegerField()),
|
||||
tag_cat_id=Value(tag_cat.id, output_field=IntegerField()),
|
||||
news_type_id=Value(news_type.id, output_field=IntegerField()),
|
||||
country_code=F('page__site__country_code_2'),
|
||||
news_title=F('page__root_title'),
|
||||
image=F('page__attachment_suffix_url'),
|
||||
template=F('page__template'),
|
||||
tags=GroupConcat('page__tags__id'),
|
||||
)[:100]
|
||||
)
|
||||
|
||||
serialized_data = NewsSerializer(data=list(queryset.values()), many=True)
|
||||
if serialized_data.is_valid():
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
"""Product admin conf."""
|
||||
from django.contrib import admin
|
||||
from utils.admin import BaseModelAdminMixin
|
||||
from .models import Product, ProductType, ProductSubType
|
||||
|
||||
|
||||
@admin.register(Product)
|
||||
class ProductAdmin(admin.ModelAdmin):
|
||||
class ProductAdmin(BaseModelAdminMixin, admin.ModelAdmin):
|
||||
"""Admin page for model Product."""
|
||||
|
||||
|
||||
|
|
|
|||
0
apps/product/management/__init__.py
Normal file
0
apps/product/management/__init__.py
Normal file
0
apps/product/management/commands/__init__.py
Normal file
0
apps/product/management/commands/__init__.py
Normal file
54
apps/product/management/commands/add_product.py
Normal file
54
apps/product/management/commands/add_product.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from product.models import ProductType, ProductSubType
|
||||
|
||||
|
||||
def add_type():
|
||||
product_type = ProductType.objects.create(
|
||||
name={'"en-GB"': "Wine"},
|
||||
index_name=ProductType.WINE
|
||||
)
|
||||
return product_type.save()
|
||||
|
||||
|
||||
def add_subtype(id_type):
|
||||
subtypes = ProductSubType.objects.bulk_create([
|
||||
ProductSubType(product_type=id_type,
|
||||
name={"en-GB", ProductSubType.EXTRA_BRUT},
|
||||
index_name=ProductSubType.EXTRA_BRUT),
|
||||
ProductSubType(product_type=id_type,
|
||||
name={"en-GB", ProductSubType.BRUT},
|
||||
index_name=ProductSubType.BRUT),
|
||||
ProductSubType(product_type=id_type,
|
||||
name={"en-GB", ProductSubType.BRUT_NATURE},
|
||||
index_name=ProductSubType.BRUT_NATURE),
|
||||
ProductSubType(product_type=id_type,
|
||||
name={"en-GB", ProductSubType.DEMI_SEC},
|
||||
index_name=ProductSubType.DEMI_SEC),
|
||||
ProductSubType(product_type=id_type,
|
||||
name={"en-GB", ProductSubType.EXTRA_DRY},
|
||||
index_name=ProductSubType.EXTRA_DRY),
|
||||
ProductSubType(product_type=id_type,
|
||||
name={"en-GB", ProductSubType.DOSAGE_ZERO},
|
||||
index_name=ProductSubType.DOSAGE_ZERO),
|
||||
ProductSubType(product_type=id_type,
|
||||
name={"en-GB", ProductSubType.SEC},
|
||||
index_name=ProductSubType.SEC),
|
||||
ProductSubType(product_type=id_type,
|
||||
name={"en-GB", ProductSubType.SEC},
|
||||
index_name=ProductSubType.SEC),
|
||||
ProductSubType(product_type=id_type,
|
||||
name={"en-GB", ProductSubType.MOELLEUX},
|
||||
index_name=ProductSubType.MOELLEUX),
|
||||
])
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Add product data'
|
||||
|
||||
def handle(self, *args, **kwarg):
|
||||
product_type = add_type()
|
||||
add_subtype(product_type.id)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -46,10 +46,28 @@ class ProductSubType(TranslatedFieldsMixin, ProjectBaseMixin):
|
|||
# INDEX NAME CHOICES
|
||||
RUM = 'rum'
|
||||
OTHER = 'other'
|
||||
EXTRA_BRUT = 'extra brut'
|
||||
BRUT = 'brut'
|
||||
BRUT_NATURE = 'brut nature'
|
||||
DEMI_SEC = 'demi-sec'
|
||||
EXTRA_DRY = 'Extra Dry'
|
||||
DOSAGE_ZERO = 'dosage zero'
|
||||
SEC = 'sec'
|
||||
DOUX = 'doux'
|
||||
MOELLEUX= 'moelleux'
|
||||
|
||||
INDEX_NAME_TYPES = (
|
||||
(RUM, _('Rum')),
|
||||
(OTHER, _('Other')),
|
||||
(EXTRA_BRUT, _('extra brut')),
|
||||
(BRUT, _('brut')),
|
||||
(BRUT_NATURE, _('brut nature')),
|
||||
(DEMI_SEC, _('demi-sec')),
|
||||
(EXTRA_DRY, _('Extra Dry')),
|
||||
(DOSAGE_ZERO, _('dosage zero')),
|
||||
(SEC, _('sec')),
|
||||
(DOUX, _('doux')),
|
||||
(MOELLEUX, _('moelleux'))
|
||||
)
|
||||
|
||||
product_type = models.ForeignKey(ProductType, on_delete=models.CASCADE,
|
||||
|
|
|
|||
|
|
@ -61,9 +61,6 @@ class EstablishmentDocumentViewSet(BaseDocumentViewSet):
|
|||
def get_queryset(self):
|
||||
qs = super(EstablishmentDocumentViewSet, self).get_queryset()
|
||||
qs = qs.filter('match', is_publish=True)
|
||||
if self.request.country_code:
|
||||
qs = qs.filter('term',
|
||||
**{'address.city.country.code': self.request.country_code})
|
||||
return qs
|
||||
|
||||
filter_backends = [
|
||||
|
|
|
|||
|
|
@ -895,3 +895,46 @@ class KeyValueMetadatumKeyValueMetadatumEstablishments(MigrateMixin):
|
|||
class Meta:
|
||||
managed = False
|
||||
db_table = 'key_value_metadatum_key_value_metadatum_establishments'
|
||||
|
||||
|
||||
class Products(models.Model):
|
||||
establishment = models.ForeignKey('Establishments', models.DO_NOTHING, blank=True, null=True)
|
||||
brand = models.CharField(max_length=255, blank=True, null=True)
|
||||
name = models.CharField(max_length=255, blank=True, null=True)
|
||||
vintage = models.CharField(max_length=255, blank=True, null=True)
|
||||
type = models.CharField(max_length=255, blank=True, null=True)
|
||||
unique_key = models.CharField(max_length=255, blank=True, null=True)
|
||||
price = models.FloatField(blank=True, null=True)
|
||||
average_price_in_shops = models.FloatField(blank=True, null=True)
|
||||
fra_encima_id = models.IntegerField(blank=True, null=True)
|
||||
wine_sub_region_id = models.IntegerField(blank=True, null=True)
|
||||
classification = models.ForeignKey('WineClassifications', models.DO_NOTHING, blank=True, null=True)
|
||||
wine_region = models.ForeignKey('WineLocations', models.DO_NOTHING, blank=True, null=True)
|
||||
wine_type = models.ForeignKey('WineTypes', models.DO_NOTHING, blank=True, null=True)
|
||||
wine_color = models.ForeignKey('WineColors', models.DO_NOTHING, blank=True, null=True)
|
||||
appellation = models.ForeignKey('WineClassifications', models.DO_NOTHING, blank=True, null=True)
|
||||
created_at = models.DateTimeField()
|
||||
updated_at = models.DateTimeField()
|
||||
state = models.CharField(max_length=255, blank=True, null=True)
|
||||
wine_style = models.ForeignKey('WineStyles', models.DO_NOTHING, blank=True, null=True)
|
||||
village = models.ForeignKey('WineLocations', models.DO_NOTHING, blank=True, null=True)
|
||||
vineyard = models.ForeignKey('WineLocations', models.DO_NOTHING, blank=True, null=True)
|
||||
yard_classification = models.ForeignKey('WineClassifications', models.DO_NOTHING, blank=True, null=True)
|
||||
wine_quality = models.ForeignKey('WineClassifications', models.DO_NOTHING, blank=True, null=True)
|
||||
bottles_produced = models.CharField(max_length=3000, blank=True, null=True)
|
||||
deu_import_id = models.IntegerField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = 'products'
|
||||
|
||||
|
||||
class WineTypes(models.Model):
|
||||
name = models.CharField(max_length=255, blank=True, null=True)
|
||||
fra_encima_id = models.IntegerField(blank=True, null=True)
|
||||
created_at = models.DateTimeField()
|
||||
updated_at = models.DateTimeField()
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = 'wine_types'
|
||||
|
|
|
|||
|
|
@ -1,15 +1,18 @@
|
|||
from rest_framework import serializers
|
||||
|
||||
from gallery.models import Image
|
||||
from location.models import Country
|
||||
from news.models import News
|
||||
from tag.models import TagCategory
|
||||
from news.models import News, NewsGallery
|
||||
from tag.models import Tag
|
||||
from transfer.models import PageMetadata
|
||||
from utils.legacy_parser import parse_legacy_news_content
|
||||
from utils.slug_generator import generate_unique_slug
|
||||
|
||||
|
||||
class NewsSerializer(serializers.Serializer):
|
||||
old_id = serializers.IntegerField()
|
||||
news_type = serializers.IntegerField()
|
||||
id = serializers.IntegerField()
|
||||
tag_cat_id = serializers.IntegerField()
|
||||
news_type_id = serializers.IntegerField()
|
||||
news_title = serializers.CharField()
|
||||
title = serializers.CharField()
|
||||
body = serializers.CharField(allow_null=True)
|
||||
|
|
@ -25,8 +28,8 @@ class NewsSerializer(serializers.Serializer):
|
|||
def create(self, validated_data):
|
||||
|
||||
payload = {
|
||||
'old_id': validated_data['old_id'],
|
||||
'news_type': validated_data['news_type'],
|
||||
'old_id': validated_data['id'],
|
||||
'news_type_id': validated_data['news_type_id'],
|
||||
'title': {validated_data['locale']: validated_data['news_title']},
|
||||
'subtitle': self.get_subtitle(validated_data),
|
||||
'description': self.get_description(validated_data),
|
||||
|
|
@ -39,23 +42,47 @@ class NewsSerializer(serializers.Serializer):
|
|||
obj = News.objects.create(**payload)
|
||||
|
||||
tags = self.get_tags(validated_data)
|
||||
for tag in tags:
|
||||
obj.tags.add(tag)
|
||||
obj.save()
|
||||
|
||||
self.make_gallery(validated_data, obj)
|
||||
return obj
|
||||
|
||||
# TODO: теги
|
||||
# TODO: галерея с картинкой
|
||||
@staticmethod
|
||||
def make_gallery(data, obj):
|
||||
if not data['image'] or data['image'] == 'default/missing.png':
|
||||
return
|
||||
|
||||
img = Image.objects.create(
|
||||
image=data['image'],
|
||||
title=data['news_title'],
|
||||
)
|
||||
NewsGallery.objects.create(
|
||||
news=obj,
|
||||
image=img,
|
||||
is_main=True,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_tags(data):
|
||||
results = []
|
||||
if not data['tags']:
|
||||
return None
|
||||
tag_cat, _ = TagCategory.objects.get_or_create(
|
||||
public=True,
|
||||
label={'en-GB': 'tag'},
|
||||
index_name='tag',
|
||||
country='tag',
|
||||
)
|
||||
return results
|
||||
|
||||
meta_ids = (int(_id) for _id in data['tags'].split(','))
|
||||
tags = PageMetadata.objects.filter(
|
||||
id__in=meta_ids,
|
||||
key='tag',
|
||||
value__isnull=False,
|
||||
)
|
||||
for old_tag in tags:
|
||||
tag, _ = Tag.objects.get_or_create(
|
||||
category_id=data['tag_cat_id'],
|
||||
label={data['locale']: old_tag.value},
|
||||
)
|
||||
results.append(tag)
|
||||
return results
|
||||
|
||||
@staticmethod
|
||||
def get_description(data):
|
||||
|
|
|
|||
|
|
@ -329,8 +329,8 @@ REDOC_SETTINGS = {
|
|||
# RabbitMQ
|
||||
# BROKER_URL = 'amqp://rabbitmq:5672'
|
||||
# Redis
|
||||
BROKER_URL = 'redis://localhost:6379/1'
|
||||
# BROKER_URL = 'redis://redis:6379/1'
|
||||
# BROKER_URL = 'redis://localhost:6379/1'
|
||||
BROKER_URL = 'redis://redis:6379/1'
|
||||
CELERY_RESULT_BACKEND = BROKER_URL
|
||||
CELERY_BROKER_URL = BROKER_URL
|
||||
CELERY_ACCEPT_CONTENT = ['application/json']
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ DOMAIN_URI = 'gm.id-east.ru'
|
|||
# ELASTICSEARCH SETTINGS
|
||||
ELASTICSEARCH_DSL = {
|
||||
'default': {
|
||||
'hosts': 'localhost:9200'
|
||||
# 'hosts': 'elasticsearch:9200'
|
||||
# 'hosts': 'localhost:9200'
|
||||
'hosts': 'elasticsearch:9200'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user