Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
alex 2020-01-09 16:29:45 +03:00
commit 989d0d4abd
13 changed files with 100 additions and 37 deletions

View File

@ -148,10 +148,11 @@ def export_guide(guide_id, user_id, file_type='csv'):
guide = Guide.objects.get(id=guide_id) guide = Guide.objects.get(id=guide_id)
root = GuideElement.objects.get_root_node(guide) root = GuideElement.objects.get_root_node(guide)
if root: if root:
nodes = root.get_descendants().select_related('review', 'establishment', 'wine_region', nodes = root.get_descendants().select_related(
'review', 'establishment', 'wine_region',
'product', 'city', 'wine_color_section', 'product', 'city', 'wine_color_section',
'section', 'label_photo', 'guide', 'section', 'label_photo', 'guide',
'city__country', 'establishment__establishment_type')[:100] 'city__country', 'establishment__establishment_type')
serializer = GuideElementExportSerializer(nodes, many=True) serializer = GuideElementExportSerializer(nodes, many=True)
data = serializer.data data = serializer.data
SendGuideExport( SendGuideExport(

View File

@ -9,22 +9,31 @@ from django.template.loader import get_template, render_to_string
from main.models import SiteSettings from main.models import SiteSettings
from news import models from news import models
from notification.models import Subscriber from notification.models import Subscribe
@shared_task @shared_task
def send_email_with_news(news_ids): def send_email_with_news(news_ids):
subscribers = Subscriber.objects.all() subscribes = Subscribe.objects.all() \
.prefetch_related('subscriber') \
.prefetch_related('subscription_type')
sent_news = models.News.objects.filter(id__in=news_ids) sent_news = models.News.objects.filter(id__in=news_ids)
htmly = get_template(settings.NEWS_EMAIL_TEMPLATE) htmly = get_template(settings.NEWS_EMAIL_TEMPLATE)
year = datetime.now().year year = datetime.now().year
socials = list(SiteSettings.objects.with_country()) socials = list(SiteSettings.objects.with_country().select_related('country'))
socials = dict(zip(map(lambda social: social.country.code, socials), socials)) socials = dict(zip(map(lambda social: social.country.code, socials), socials))
for subscriber in subscribers: for subscribe in subscribes.filter(unsubscribe_date=None):
socials_for_subscriber = socials.get(subscriber.country_code) country = subscribe.subscription_type.country
if country is None:
continue
socials_for_subscriber = socials.get(country.code)
subscriber = subscribe.subscriber
try: try:
for new in sent_news: for new in sent_news:
context = { context = {

View File

@ -145,7 +145,7 @@ def add_tags():
) )
if created: if created:
text_value = ' '.join(new_tag.value.split('_')) text_value = ' '.join(new_tag.value.split('_'))
translation = SiteInterfaceDictionary(page={'en-GB': text_value}, keywords=f'tag.{new_tag.category}.{new_tag.value}') translation = SiteInterfaceDictionary(text={'en-GB': text_value}, keywords=f'tag.{new_tag.category}.{new_tag.value}')
translation.save() translation.save()
new_tag.translation = translation new_tag.translation = translation
new_tag.save() new_tag.save()

View File

@ -0,0 +1,20 @@
# Generated by Django 2.2.7 on 2019-12-31 01:31
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('location', '0033_merge_20191224_0920'),
('notification', '0008_remove_subscribe_state'),
]
operations = [
migrations.AddField(
model_name='subscriptiontype',
name='country',
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='location.Country', verbose_name='Country'),
),
]

View File

@ -0,0 +1,19 @@
# Generated by Django 2.2.7 on 2019-12-31 01:35
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('notification', '0009_subscriptiontype_country'),
]
operations = [
migrations.AlterField(
model_name='subscriptiontype',
name='country',
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to='location.Country', verbose_name='country'),
),
]

View File

@ -6,6 +6,7 @@ from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from account.models import User from account.models import User
from location.models import Country
from utils.methods import generate_string_code from utils.methods import generate_string_code
from utils.models import ProjectBaseMixin, TJSONField, TranslatedFieldsMixin from utils.models import ProjectBaseMixin, TJSONField, TranslatedFieldsMixin
@ -15,6 +16,9 @@ class SubscriptionType(ProjectBaseMixin, TranslatedFieldsMixin):
name = TJSONField(blank=True, null=True, default=None, name = TJSONField(blank=True, null=True, default=None,
verbose_name=_('name'), verbose_name=_('name'),
help_text='{"en-GB":"some text"}') help_text='{"en-GB":"some text"}')
country = models.ForeignKey(Country, on_delete=models.PROTECT,
blank=True, null=True, default=None,
verbose_name=_('country'))
# todo: associate user & subscriber after users registration # todo: associate user & subscriber after users registration
@ -126,10 +130,6 @@ class Subscriber(ProjectBaseMixin):
query = f'?code={self.update_code}' query = f'?code={self.update_code}'
return f'{schema}://{site_domain}{url}{query}' return f'{schema}://{site_domain}{url}{query}'
@property
def subscribe_objects(self):
return Subscribe.objects.filter(subscriber=self)
class Subscribe(ProjectBaseMixin): class Subscribe(ProjectBaseMixin):
"""Subscribe model.""" """Subscribe model."""

View File

@ -2,6 +2,7 @@
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers from rest_framework import serializers
from location.serializers import CountrySimpleSerializer
from notification import models from notification import models
from utils.methods import get_user_ip from utils.methods import get_user_ip
from utils.serializers import TranslatedField from utils.serializers import TranslatedField
@ -11,6 +12,7 @@ class SubscriptionTypeSerializer(serializers.ModelSerializer):
"""Subscription type serializer.""" """Subscription type serializer."""
name_translated = TranslatedField() name_translated = TranslatedField()
country = CountrySimpleSerializer()
class Meta: class Meta:
"""Meta class.""" """Meta class."""
@ -20,6 +22,7 @@ class SubscriptionTypeSerializer(serializers.ModelSerializer):
'id', 'id',
'index_name', 'index_name',
'name_translated', 'name_translated',
'country',
) )
@ -80,7 +83,7 @@ class SubscribeObjectSerializer(serializers.ModelSerializer):
"""Meta class.""" """Meta class."""
model = models.Subscriber model = models.Subscriber
fields = () fields = ('subscriber', )
read_only_fields = ('subscribe_date', 'unsubscribe_date',) read_only_fields = ('subscribe_date', 'unsubscribe_date',)
@ -88,8 +91,7 @@ class SubscribeSerializer(serializers.ModelSerializer):
"""Subscribe serializer.""" """Subscribe serializer."""
email = serializers.EmailField(required=False, source='send_to') email = serializers.EmailField(required=False, source='send_to')
subscription_types = SubscriptionTypeSerializer(read_only=True, source='subscription_types_set') subscription_types = SubscriptionTypeSerializer(many=True, read_only=True)
subscribe_objects = SubscribeObjectSerializer(read_only=True)
class Meta: class Meta:
"""Meta class.""" """Meta class."""
@ -99,5 +101,4 @@ class SubscribeSerializer(serializers.ModelSerializer):
'email', 'email',
'subscription_types', 'subscription_types',
'link_to_unsubscribe', 'link_to_unsubscribe',
'subscribe_objects',
) )

View File

@ -80,7 +80,7 @@ class NotificationSubscribeInfoTestCase(APITestCase):
class NotificationUnsubscribeAuthUserTestCase(BaseTestCase): class NotificationUnsubscribeAuthUserTestCase(BaseTestCase):
def test_unsubscribe_auth_user(self): def test_unsubscribe_auth_user(self):
Subscriber.objects.create(user=self.user, email=self.email, state=1) Subscriber.objects.create(user=self.user, email=self.email)
self.test_data = { self.test_data = {
"email": self.email "email": self.email
@ -174,7 +174,7 @@ class NotificationManySubscribeTestCase(APITestCase):
test_data = { test_data = {
'email': self.email, 'email': self.email,
'subscription_types_pk': [ 'subscription_types_pk': [
self.test_subscribe_type self.test_subscribe_type.id
] ]
} }
@ -183,6 +183,12 @@ class NotificationManySubscribeTestCase(APITestCase):
self.assertEqual(response.json()["email"], test_data["email"]) self.assertEqual(response.json()["email"], test_data["email"])
def test_unsubscribe(self): def test_unsubscribe(self):
self.username = 'sedragurda'
self.password = 'sedragurdaredips19'
self.email = 'sedragurda@desoz.com'
self.user = User.objects.create_user(
username=self.username, email=self.email, password=self.password)
test_data = { test_data = {
"email": self.email "email": self.email
} }

View File

@ -0,0 +1 @@
urlpatterns = []

View File

@ -10,10 +10,12 @@ class TagsBaseFilterSet(filters.FilterSet):
# Object type choices # Object type choices
NEWS = 'news' NEWS = 'news'
ESTABLISHMENT = 'establishment' ESTABLISHMENT = 'establishment'
RECIPES = 'recipe'
TYPE_CHOICES = ( TYPE_CHOICES = (
(NEWS, 'News'), (NEWS, 'News'),
(ESTABLISHMENT, 'Establishment'), (ESTABLISHMENT, 'Establishment'),
(RECIPES, 'Recipe'),
) )
type = filters.MultipleChoiceFilter(choices=TYPE_CHOICES, type = filters.MultipleChoiceFilter(choices=TYPE_CHOICES,
@ -91,5 +93,7 @@ class TagsFilterSet(TagsBaseFilterSet):
if self.ESTABLISHMENT in value: if self.ESTABLISHMENT in value:
queryset = queryset.for_establishments().filter(category__value_type='list').filter(value__in=settings.ESTABLISHMENT_CHOSEN_TAGS).distinct( queryset = queryset.for_establishments().filter(category__value_type='list').filter(value__in=settings.ESTABLISHMENT_CHOSEN_TAGS).distinct(
'value') 'value')
if self.RECIPES in value:
queryset = queryset.for_news().filter(value__in=settings.RECIPES_CHOSEN_TAGS).distinct('value')
return queryset return queryset

View File

@ -81,13 +81,12 @@ class DocTemplate:
def template(self, data: list): def template(self, data: list):
for instance in data: for obj in data:
instance = dict(instance) obj = dict(obj)
element_id = instance.get('id') index_name = section_name_into_index_name(obj.get('section_name'))
index_name = section_name_into_index_name(instance.get('section_name'))
# ESTABLISHMENT HEADING (LEVEL 1) # ESTABLISHMENT HEADING (LEVEL 1)
self.add_heading(name=instance['name'], self.add_heading(name=obj['name'],
font_style={'size': Pt(18), 'name': 'Palatino', 'bold': False}, font_style={'size': Pt(18), 'name': 'Palatino', 'bold': False},
level=1) level=1)
# ESTABLISHMENT TYPE PARAGRAPH # ESTABLISHMENT TYPE PARAGRAPH
@ -100,13 +99,13 @@ class DocTemplate:
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True}, font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
level=2) level=2)
# CITY NAME HEADING (LEVEL 3) # CITY NAME HEADING (LEVEL 3)
self.add_heading(name=instance['city_name'], self.add_heading(name=obj['city_name'],
font_style={'size': Pt(12), 'name': 'Arial', 'bold': True, 'italic': True}, font_style={'size': Pt(12), 'name': 'Arial', 'bold': True, 'italic': True},
color_rgb=(102, 102, 102)) color_rgb=(102, 102, 102))
self.add_empty_line() self.add_empty_line()
# REVIEW HEADING (LEVEL 2) # REVIEW HEADING (LEVEL 2)
review = instance.get('review') review = obj.get('review')
if review: if review:
self.add_heading(name='Review', self.add_heading(name='Review',
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True}, font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
@ -123,7 +122,7 @@ class DocTemplate:
self.add_empty_line() self.add_empty_line()
# PHONE HEADING (LEVEL 2) # PHONE HEADING (LEVEL 2)
phones = instance.get('phones') phones = obj.get('phones')
if phones: if phones:
self.add_heading(name='Phones', self.add_heading(name='Phones',
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True}, font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
@ -133,18 +132,18 @@ class DocTemplate:
self.add_empty_line() self.add_empty_line()
# ADDRESS HEADING (LEVEL 2) # ADDRESS HEADING (LEVEL 2)
address = instance.get('address') address = obj.get('address')
if address: if address:
self.add_heading(name='Address', self.add_heading(name='Address',
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True}, font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
level=2) level=2)
# ADDRESS DATA PARAGRAPH # ADDRESS DATA PARAGRAPH
self.add_paragraph(name=instance.get('address'), self.add_paragraph(name=obj.get('address'),
font_style={'size': Pt(10), 'name': 'Arial'}) font_style={'size': Pt(10), 'name': 'Arial'})
self.add_empty_line() self.add_empty_line()
# TIMETABLE HEADING (LEVEL 2) # TIMETABLE HEADING (LEVEL 2)
schedule = instance.get('schedule') schedule = obj.get('schedule')
if schedule: if schedule:
self.add_heading(name='Schedule', self.add_heading(name='Schedule',
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True}, font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
@ -158,7 +157,7 @@ class DocTemplate:
self.add_empty_line() self.add_empty_line()
# PUBLIC MARK HEADING (LEVEL 2) # PUBLIC MARK HEADING (LEVEL 2)
public_mark = instance.get('public_mark') public_mark = obj.get('public_mark')
if public_mark: if public_mark:
self.add_heading(name='Mark', self.add_heading(name='Mark',
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True}, font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
@ -169,7 +168,7 @@ class DocTemplate:
self.add_empty_line() self.add_empty_line()
# TOQUE HEADING (LEVEL 2) # TOQUE HEADING (LEVEL 2)
toque = instance.get('toque_number') toque = obj.get('toque_number')
if toque: if toque:
self.add_heading(name='Toque', self.add_heading(name='Toque',
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True}, font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
@ -180,7 +179,7 @@ class DocTemplate:
self.add_empty_line() self.add_empty_line()
# TOQUE HEADING (LEVEL 2) # TOQUE HEADING (LEVEL 2)
price_level = instance.get('price_level') price_level = obj.get('price_level')
if price_level: if price_level:
self.add_heading(name='Price level', self.add_heading(name='Price level',
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True}, font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
@ -191,7 +190,7 @@ class DocTemplate:
self.add_empty_line() self.add_empty_line()
# SERVICES HEADING (LEVEL 2) # SERVICES HEADING (LEVEL 2)
services = instance.get('services') services = obj.get('services')
if services: if services:
self.add_heading(name='Services', self.add_heading(name='Services',
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True}, font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
@ -201,7 +200,7 @@ class DocTemplate:
self.add_empty_line() self.add_empty_line()
# METADATA HEADING (LEVEL 2) # METADATA HEADING (LEVEL 2)
metadata = instance.get('metadata') metadata = obj.get('metadata')
if metadata: if metadata:
for obj in metadata: for obj in metadata:
for section, tags in obj.items(): for section, tags in obj.items():

View File

@ -30,7 +30,6 @@ MEDIA_ROOT = os.path.join(PUBLIC_ROOT, MEDIA_LOCATION)
THUMBNAIL_DEBUG = True THUMBNAIL_DEBUG = True
# DATABASES # DATABASES
DATABASES = { DATABASES = {
'default': { 'default': {
@ -119,3 +118,6 @@ EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'anatolyfeteleu@gmail.com' EMAIL_HOST_USER = 'anatolyfeteleu@gmail.com'
EMAIL_HOST_PASSWORD = 'nggrlnbehzksgmbt' EMAIL_HOST_PASSWORD = 'nggrlnbehzksgmbt'
EMAIL_PORT = 587 EMAIL_PORT = 587
# ADD TRANSFER TO INSTALLED APPS
INSTALLED_APPS.append('transfer.apps.TransferConfig')

View File

@ -10,6 +10,7 @@ urlpatterns = [
path('gallery/', include(('gallery.urls', 'gallery'), namespace='gallery')), path('gallery/', include(('gallery.urls', 'gallery'), namespace='gallery')),
path('location/', include('location.urls.back')), path('location/', include('location.urls.back')),
path('news/', include('news.urls.back')), path('news/', include('news.urls.back')),
path('notifications/', include(('notification.urls.back', 'notification'), namespace='notification')),
path('review/', include('review.urls.back')), path('review/', include('review.urls.back')),
path('tags/', include(('tag.urls.back', 'tag'), namespace='tag')), path('tags/', include(('tag.urls.back', 'tag'), namespace='tag')),
path('products/', include(('product.urls.back', 'product'), namespace='product')), path('products/', include(('product.urls.back', 'product'), namespace='product')),