Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
989d0d4abd
|
|
@ -148,10 +148,11 @@ def export_guide(guide_id, user_id, file_type='csv'):
|
|||
guide = Guide.objects.get(id=guide_id)
|
||||
root = GuideElement.objects.get_root_node(guide)
|
||||
if root:
|
||||
nodes = root.get_descendants().select_related('review', 'establishment', 'wine_region',
|
||||
'product', 'city', 'wine_color_section',
|
||||
'section', 'label_photo', 'guide',
|
||||
'city__country', 'establishment__establishment_type')[:100]
|
||||
nodes = root.get_descendants().select_related(
|
||||
'review', 'establishment', 'wine_region',
|
||||
'product', 'city', 'wine_color_section',
|
||||
'section', 'label_photo', 'guide',
|
||||
'city__country', 'establishment__establishment_type')
|
||||
serializer = GuideElementExportSerializer(nodes, many=True)
|
||||
data = serializer.data
|
||||
SendGuideExport(
|
||||
|
|
|
|||
|
|
@ -9,22 +9,31 @@ from django.template.loader import get_template, render_to_string
|
|||
|
||||
from main.models import SiteSettings
|
||||
from news import models
|
||||
from notification.models import Subscriber
|
||||
from notification.models import Subscribe
|
||||
|
||||
|
||||
@shared_task
|
||||
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)
|
||||
|
||||
htmly = get_template(settings.NEWS_EMAIL_TEMPLATE)
|
||||
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))
|
||||
|
||||
for subscriber in subscribers:
|
||||
socials_for_subscriber = socials.get(subscriber.country_code)
|
||||
for subscribe in subscribes.filter(unsubscribe_date=None):
|
||||
country = subscribe.subscription_type.country
|
||||
|
||||
if country is None:
|
||||
continue
|
||||
|
||||
socials_for_subscriber = socials.get(country.code)
|
||||
subscriber = subscribe.subscriber
|
||||
|
||||
try:
|
||||
for new in sent_news:
|
||||
context = {
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ def add_tags():
|
|||
)
|
||||
if created:
|
||||
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()
|
||||
new_tag.translation = translation
|
||||
new_tag.save()
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
),
|
||||
]
|
||||
19
apps/notification/migrations/0010_auto_20191231_0135.py
Normal file
19
apps/notification/migrations/0010_auto_20191231_0135.py
Normal 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'),
|
||||
),
|
||||
]
|
||||
|
|
@ -6,6 +6,7 @@ from django.utils.timezone import now
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from account.models import User
|
||||
from location.models import Country
|
||||
from utils.methods import generate_string_code
|
||||
from utils.models import ProjectBaseMixin, TJSONField, TranslatedFieldsMixin
|
||||
|
||||
|
|
@ -15,6 +16,9 @@ class SubscriptionType(ProjectBaseMixin, TranslatedFieldsMixin):
|
|||
name = TJSONField(blank=True, null=True, default=None,
|
||||
verbose_name=_('name'),
|
||||
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
|
||||
|
|
@ -126,10 +130,6 @@ class Subscriber(ProjectBaseMixin):
|
|||
query = f'?code={self.update_code}'
|
||||
return f'{schema}://{site_domain}{url}{query}'
|
||||
|
||||
@property
|
||||
def subscribe_objects(self):
|
||||
return Subscribe.objects.filter(subscriber=self)
|
||||
|
||||
|
||||
class Subscribe(ProjectBaseMixin):
|
||||
"""Subscribe model."""
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
from rest_framework import serializers
|
||||
|
||||
from location.serializers import CountrySimpleSerializer
|
||||
from notification import models
|
||||
from utils.methods import get_user_ip
|
||||
from utils.serializers import TranslatedField
|
||||
|
|
@ -11,6 +12,7 @@ class SubscriptionTypeSerializer(serializers.ModelSerializer):
|
|||
"""Subscription type serializer."""
|
||||
|
||||
name_translated = TranslatedField()
|
||||
country = CountrySimpleSerializer()
|
||||
|
||||
class Meta:
|
||||
"""Meta class."""
|
||||
|
|
@ -20,6 +22,7 @@ class SubscriptionTypeSerializer(serializers.ModelSerializer):
|
|||
'id',
|
||||
'index_name',
|
||||
'name_translated',
|
||||
'country',
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -80,7 +83,7 @@ class SubscribeObjectSerializer(serializers.ModelSerializer):
|
|||
"""Meta class."""
|
||||
|
||||
model = models.Subscriber
|
||||
fields = ()
|
||||
fields = ('subscriber', )
|
||||
read_only_fields = ('subscribe_date', 'unsubscribe_date',)
|
||||
|
||||
|
||||
|
|
@ -88,8 +91,7 @@ class SubscribeSerializer(serializers.ModelSerializer):
|
|||
"""Subscribe serializer."""
|
||||
|
||||
email = serializers.EmailField(required=False, source='send_to')
|
||||
subscription_types = SubscriptionTypeSerializer(read_only=True, source='subscription_types_set')
|
||||
subscribe_objects = SubscribeObjectSerializer(read_only=True)
|
||||
subscription_types = SubscriptionTypeSerializer(many=True, read_only=True)
|
||||
|
||||
class Meta:
|
||||
"""Meta class."""
|
||||
|
|
@ -99,5 +101,4 @@ class SubscribeSerializer(serializers.ModelSerializer):
|
|||
'email',
|
||||
'subscription_types',
|
||||
'link_to_unsubscribe',
|
||||
'subscribe_objects',
|
||||
)
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class NotificationSubscribeInfoTestCase(APITestCase):
|
|||
class NotificationUnsubscribeAuthUserTestCase(BaseTestCase):
|
||||
|
||||
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 = {
|
||||
"email": self.email
|
||||
|
|
@ -174,7 +174,7 @@ class NotificationManySubscribeTestCase(APITestCase):
|
|||
test_data = {
|
||||
'email': self.email,
|
||||
'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"])
|
||||
|
||||
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 = {
|
||||
"email": self.email
|
||||
}
|
||||
|
|
|
|||
1
apps/notification/urls/back.py
Normal file
1
apps/notification/urls/back.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
urlpatterns = []
|
||||
|
|
@ -10,10 +10,12 @@ class TagsBaseFilterSet(filters.FilterSet):
|
|||
# Object type choices
|
||||
NEWS = 'news'
|
||||
ESTABLISHMENT = 'establishment'
|
||||
RECIPES = 'recipe'
|
||||
|
||||
TYPE_CHOICES = (
|
||||
(NEWS, 'News'),
|
||||
(ESTABLISHMENT, 'Establishment'),
|
||||
(RECIPES, 'Recipe'),
|
||||
)
|
||||
|
||||
type = filters.MultipleChoiceFilter(choices=TYPE_CHOICES,
|
||||
|
|
@ -91,5 +93,7 @@ class TagsFilterSet(TagsBaseFilterSet):
|
|||
if self.ESTABLISHMENT in value:
|
||||
queryset = queryset.for_establishments().filter(category__value_type='list').filter(value__in=settings.ESTABLISHMENT_CHOSEN_TAGS).distinct(
|
||||
'value')
|
||||
if self.RECIPES in value:
|
||||
queryset = queryset.for_news().filter(value__in=settings.RECIPES_CHOSEN_TAGS).distinct('value')
|
||||
return queryset
|
||||
|
||||
|
|
|
|||
|
|
@ -81,13 +81,12 @@ class DocTemplate:
|
|||
|
||||
def template(self, data: list):
|
||||
|
||||
for instance in data:
|
||||
instance = dict(instance)
|
||||
element_id = instance.get('id')
|
||||
index_name = section_name_into_index_name(instance.get('section_name'))
|
||||
for obj in data:
|
||||
obj = dict(obj)
|
||||
index_name = section_name_into_index_name(obj.get('section_name'))
|
||||
|
||||
# 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},
|
||||
level=1)
|
||||
# ESTABLISHMENT TYPE PARAGRAPH
|
||||
|
|
@ -100,13 +99,13 @@ class DocTemplate:
|
|||
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
|
||||
level=2)
|
||||
# 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},
|
||||
color_rgb=(102, 102, 102))
|
||||
self.add_empty_line()
|
||||
|
||||
# REVIEW HEADING (LEVEL 2)
|
||||
review = instance.get('review')
|
||||
review = obj.get('review')
|
||||
if review:
|
||||
self.add_heading(name='Review',
|
||||
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
|
||||
|
|
@ -123,7 +122,7 @@ class DocTemplate:
|
|||
self.add_empty_line()
|
||||
|
||||
# PHONE HEADING (LEVEL 2)
|
||||
phones = instance.get('phones')
|
||||
phones = obj.get('phones')
|
||||
if phones:
|
||||
self.add_heading(name='Phones',
|
||||
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
|
||||
|
|
@ -133,18 +132,18 @@ class DocTemplate:
|
|||
self.add_empty_line()
|
||||
|
||||
# ADDRESS HEADING (LEVEL 2)
|
||||
address = instance.get('address')
|
||||
address = obj.get('address')
|
||||
if address:
|
||||
self.add_heading(name='Address',
|
||||
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
|
||||
level=2)
|
||||
# ADDRESS DATA PARAGRAPH
|
||||
self.add_paragraph(name=instance.get('address'),
|
||||
self.add_paragraph(name=obj.get('address'),
|
||||
font_style={'size': Pt(10), 'name': 'Arial'})
|
||||
self.add_empty_line()
|
||||
|
||||
# TIMETABLE HEADING (LEVEL 2)
|
||||
schedule = instance.get('schedule')
|
||||
schedule = obj.get('schedule')
|
||||
if schedule:
|
||||
self.add_heading(name='Schedule',
|
||||
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
|
||||
|
|
@ -158,7 +157,7 @@ class DocTemplate:
|
|||
self.add_empty_line()
|
||||
|
||||
# PUBLIC MARK HEADING (LEVEL 2)
|
||||
public_mark = instance.get('public_mark')
|
||||
public_mark = obj.get('public_mark')
|
||||
if public_mark:
|
||||
self.add_heading(name='Mark',
|
||||
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
|
||||
|
|
@ -169,7 +168,7 @@ class DocTemplate:
|
|||
self.add_empty_line()
|
||||
|
||||
# TOQUE HEADING (LEVEL 2)
|
||||
toque = instance.get('toque_number')
|
||||
toque = obj.get('toque_number')
|
||||
if toque:
|
||||
self.add_heading(name='Toque',
|
||||
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
|
||||
|
|
@ -180,7 +179,7 @@ class DocTemplate:
|
|||
self.add_empty_line()
|
||||
|
||||
# TOQUE HEADING (LEVEL 2)
|
||||
price_level = instance.get('price_level')
|
||||
price_level = obj.get('price_level')
|
||||
if price_level:
|
||||
self.add_heading(name='Price level',
|
||||
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
|
||||
|
|
@ -191,7 +190,7 @@ class DocTemplate:
|
|||
self.add_empty_line()
|
||||
|
||||
# SERVICES HEADING (LEVEL 2)
|
||||
services = instance.get('services')
|
||||
services = obj.get('services')
|
||||
if services:
|
||||
self.add_heading(name='Services',
|
||||
font_style={'size': Pt(13), 'name': 'Arial', 'bold': True},
|
||||
|
|
@ -201,7 +200,7 @@ class DocTemplate:
|
|||
self.add_empty_line()
|
||||
|
||||
# METADATA HEADING (LEVEL 2)
|
||||
metadata = instance.get('metadata')
|
||||
metadata = obj.get('metadata')
|
||||
if metadata:
|
||||
for obj in metadata:
|
||||
for section, tags in obj.items():
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ MEDIA_ROOT = os.path.join(PUBLIC_ROOT, MEDIA_LOCATION)
|
|||
THUMBNAIL_DEBUG = True
|
||||
|
||||
|
||||
|
||||
# DATABASES
|
||||
DATABASES = {
|
||||
'default': {
|
||||
|
|
@ -119,3 +118,6 @@ EMAIL_HOST = 'smtp.gmail.com'
|
|||
EMAIL_HOST_USER = 'anatolyfeteleu@gmail.com'
|
||||
EMAIL_HOST_PASSWORD = 'nggrlnbehzksgmbt'
|
||||
EMAIL_PORT = 587
|
||||
|
||||
# ADD TRANSFER TO INSTALLED APPS
|
||||
INSTALLED_APPS.append('transfer.apps.TransferConfig')
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ urlpatterns = [
|
|||
path('gallery/', include(('gallery.urls', 'gallery'), namespace='gallery')),
|
||||
path('location/', include('location.urls.back')),
|
||||
path('news/', include('news.urls.back')),
|
||||
path('notifications/', include(('notification.urls.back', 'notification'), namespace='notification')),
|
||||
path('review/', include('review.urls.back')),
|
||||
path('tags/', include(('tag.urls.back', 'tag'), namespace='tag')),
|
||||
path('products/', include(('product.urls.back', 'product'), namespace='product')),
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user