From 0896050fc9f1ec03526184ff41399fab230e0bad Mon Sep 17 00:00:00 2001 From: Gena Date: Wed, 17 Jun 2015 00:57:49 +0600 Subject: [PATCH] auto --- accounts/utils.py | 16 +++++++++++++++- batiskaf/templates/jinja2/mail/base.jinja | 11 +++++++++++ batiskaf/templates/jinja2/mail/order.jinja | 8 ++++++++ .../templates/jinja2/mail/registration.jinja | 10 ++++++++++ store/views.py | 4 +++- 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 batiskaf/templates/jinja2/mail/base.jinja create mode 100644 batiskaf/templates/jinja2/mail/order.jinja create mode 100644 batiskaf/templates/jinja2/mail/registration.jinja diff --git a/accounts/utils.py b/accounts/utils.py index b44c918..b0ed3d8 100644 --- a/accounts/utils.py +++ b/accounts/utils.py @@ -1,7 +1,21 @@ import re +from django.core.mail import send_mail +from django.conf import settings +from django.template.loader import render_to_string + def normalize_phone(phone): retval = re.sub("\D", "", phone) if len(retval) > 10: retval = retval[len(retval)-10:] - return retval \ No newline at end of file + return retval + +def send_email(profile, subject='Робот Batiskaf-kz.kz', template='mail/base.jinja', context={}): + context['user'] = profile + message = render_to_string(template, context) + send_mail( + subject, + message, + recipient_list=[profile.email, ], + from_email=settings.DEFAULT_FROM_EMAIL + ) \ No newline at end of file diff --git a/batiskaf/templates/jinja2/mail/base.jinja b/batiskaf/templates/jinja2/mail/base.jinja new file mode 100644 index 0000000..0a39a11 --- /dev/null +++ b/batiskaf/templates/jinja2/mail/base.jinja @@ -0,0 +1,11 @@ +Привет, {{ user.first_name }}! +{% block content %} +{% endblock %} + +Это автоматическое сообщение. Отвечать на него не нужно! + +С Уважением, +Администрация Batiskaf-kz.kz +-- +Skype: batiskaf_kz +Тел: +7 (777) 163-14-34 или +7 (775) 859-12-17 \ No newline at end of file diff --git a/batiskaf/templates/jinja2/mail/order.jinja b/batiskaf/templates/jinja2/mail/order.jinja new file mode 100644 index 0000000..73cb55e --- /dev/null +++ b/batiskaf/templates/jinja2/mail/order.jinja @@ -0,0 +1,8 @@ +{% extends 'mail/base.jinja' %} +{% block content %} +Поздравляем, вы успешно оформили заказ. + +Для того, чтобы его было удобнее отслеживать, войдите в свой личный кабинет, используя свой номер телефона +7{{ user.phone }}: + +http://batiskaf-kz.kz/account/ +{% endblock %} \ No newline at end of file diff --git a/batiskaf/templates/jinja2/mail/registration.jinja b/batiskaf/templates/jinja2/mail/registration.jinja new file mode 100644 index 0000000..c4c3b43 --- /dev/null +++ b/batiskaf/templates/jinja2/mail/registration.jinja @@ -0,0 +1,10 @@ +{% extends 'mail/base.jinja' %} +{% block content %} +Поздравляем, вы успешно оформили заказ. + +Для того, чтобы его было удобнее отслеживать, мы создали для вас аккаунт в нашем интернет-магазине. + +Вы можете войти в него, используя свой номер телефона +7{{ user.phone }}: + +http://batiskaf-kz.kz/account/ +{% endblock %} \ No newline at end of file diff --git a/store/views.py b/store/views.py index 38a2115..e768600 100644 --- a/store/views.py +++ b/store/views.py @@ -3,7 +3,7 @@ from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage from django.shortcuts import get_object_or_404, redirect, render from django.views.generic import * from accounts.models import Profile -from accounts.utils import normalize_phone +from accounts.utils import normalize_phone, send_email from batiskaf.jinja2_ext.html_filters import escape from .models import * from store.alemtat import AlemTat @@ -216,6 +216,7 @@ class CartDetailView(TemplateView): profile = Profile.objects.get(phone=normalize_phone(order.phone)) profile.set_password(settings.PROFILE_TEMP_PASSWORD) profile.save() + send_email(profile, template='mail/order.jinja') except: profile = Profile.objects.create( phone=normalize_phone(order.phone), @@ -225,6 +226,7 @@ class CartDetailView(TemplateView): ) profile.set_password(settings.PROFILE_TEMP_PASSWORD) profile.save() + send_email(profile, template='mail/registration.jinja') user = authenticate(username=profile.phone, password=settings.PROFILE_TEMP_PASSWORD) if user.is_active: login(request, user)