Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move get_email_base_context to core
TOMEKcac053b148a2
diff --git a/saleor/account/emails.py b/saleor/account/emails.pyindex 93adb8dbef..d54000c210 100644--- a/saleor/account/emails.py+++ b/saleor/account/emails.py@@ -6,6 +6,7 @@ from django.urls import reversefrom templated_email import send_templated_mailfrom ..core.utils import build_absolute_uri+from ..core.utils.email import get_email_base_context@shared_task@@ -36,13 +37,3 @@ def send_account_delete_confirmation_email(token, recipient_email):from_email=settings.DEFAULT_FROM_EMAIL,recipient_list=[recipient_email],context=ctx)---def get_email_base_context():- site = Site.objects.get_current()- logo_url = build_absolute_uri(- location=None) + static('images/logo-document.svg')- return {- 'domain': site.domain,- 'logo_url': logo_url,- 'site_name': site.name}diff --git a/saleor/core/utils/email.py b/saleor/core/utils/email.pynew file mode 100644index 0000000000..0831608967--- /dev/null+++ b/saleor/core/utils/email.py@@ -0,0 +1,14 @@+from django.contrib.sites.models import Site+from django.templatetags.static import static++from ...core.utils import build_absolute_uri+++def get_email_base_context():+ site = Site.objects.get_current()+ logo_url = build_absolute_uri(+ location=None) + static('images/logo-document.svg')+ return {+ 'domain': site.domain,+ 'logo_url': logo_url,+ 'site_name': site.name}diff --git a/saleor/dashboard/emails.py b/saleor/dashboard/emails.pyindex 3b27b8cc41..5ef13fa65c 100644--- a/saleor/dashboard/emails.py+++ b/saleor/dashboard/emails.py@@ -9,6 +9,7 @@ from django.utils.http import urlsafe_base64_encodefrom templated_email import send_templated_mailfrom ..core.utils import build_absolute_uri+from ..core.utils.email import get_email_base_context@shared_task@@ -20,7 +21,7 @@ def send_set_password_email(staff):'account:reset-password-confirm',kwargs={'token': token, 'uidb64': uid}))ctx = get_email_base_context()- ctx.update({'password_set_url': password_set_url})+ ctx['password_set_url'] = password_set_urlsend_templated_mail(template_name='dashboard/staff/set_password',from_email=settings.DEFAULT_FROM_EMAIL,@@ -31,19 +32,9 @@ def send_set_password_email(staff):@shared_taskdef send_promote_customer_to_staff_email(staff):ctx = get_email_base_context()- ctx.update({'url': build_absolute_uri(reverse('dashboard:index'))})+ ctx['url'] = build_absolute_uri(reverse('dashboard:index'))send_templated_mail(template_name='dashboard/staff/promote_customer',from_email=settings.DEFAULT_FROM_EMAIL,recipient_list=[staff.email],context=ctx)---def get_email_base_context():- site = Site.objects.get_current()- logo_url = build_absolute_uri(- location=None) + static('images/logo-document.svg')- return {- 'domain': site.domain,- 'logo_url': logo_url,- 'site_name': site.name}diff --git a/saleor/order/emails.py b/saleor/order/emails.pyindex 9e18ef0752..57583cf139 100644--- a/saleor/order/emails.py+++ b/saleor/order/emails.py@@ -6,6 +6,7 @@ from django.urls import reversefrom templated_email import send_templated_mailfrom ..core.utils import build_absolute_uri+from ..core.utils.email import get_email_base_contextfrom ..seo.schema.email import get_order_confirmation_markupfrom .models import Fulfillment, Order@@ -16,17 +17,6 @@ CONFIRM_PAYMENT_TEMPLATE = 'order/payment/confirm_payment'CONFIRM_NOTE_TEMPLATE = 'order/note/confirm_note'-def get_email_context(order_token):- """Prepares context required for email template rendering."""- site = Site.objects.get_current()- logo_url = build_absolute_uri(- location=None) + static('images/logo-document.svg')- order_url = build_absolute_uri(- reverse('order:details', kwargs={'token': order_token}))- ctx = {'site_name': site.name, 'logo_url': logo_url, 'url': order_url}- return ctx--def collect_data_for_email(order_pk, template):"""Collects data required for email sending.@@ -36,7 +26,9 @@ def collect_data_for_email(order_pk, template):"""order = Order.objects.get(pk=order_pk)recipient_email = order.get_user_current_email()- email_context = get_email_context(order.token)+ email_context = get_email_base_context()+ email_context['url'] = build_absolute_uri(+ reverse('order:details', kwargs={'token': order.token}))# Order confirmation template requires additional informationif template == CONFIRM_ORDER_TEMPLATE:diff --git a/tests/test_emails.py b/tests/test_emails.pyindex d6a4ce039f..d4f0fd64fd 100644--- a/tests/test_emails.py+++ b/tests/test_emails.py@@ -8,20 +8,19 @@ from templated_email import get_connectionimport saleor.order.emails as emailsfrom saleor.core.utils import build_absolute_uri+from saleor.core.utils.email import get_email_base_context-def test_get_email_context(order, site_settings):+def test_get_email_base_context(order, site_settings):site = site_settings.sitelogo_url = build_absolute_uri(location=None) + static('images/logo-document.svg')- order_url = build_absolute_uri(- reverse('order:details', kwargs={'token': order.token}))proper_context = {- 'site_name': site.name,+ 'domain': site.domain,'logo_url': logo_url,- 'url': order_url}+ 'site_name': site.name}- received_context = emails.get_email_context(order.token)+ received_context = get_email_base_context()assert proper_context == received_context