From 778d65d84ec305fbd81886c5f91dc096b616cb0a Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 12 Mar 2021 12:37:27 +0000 Subject: [PATCH] implemented new email templates, but not rendering --- products/tests.py | 5 + products/views.py | 8 + templates/purchase_contact_confirmation.html | 197 ++++++++++++++++++- templates/purchase_notification.html | 180 ++++++++++++++++- 4 files changed, 378 insertions(+), 12 deletions(-) mode change 100644 => 100755 templates/purchase_contact_confirmation.html mode change 100644 => 100755 templates/purchase_notification.html diff --git a/products/tests.py b/products/tests.py index d9db3ea..6efa7dd 100644 --- a/products/tests.py +++ b/products/tests.py @@ -1217,8 +1217,13 @@ class PurchaseEmailTest(APITestCase): self.assertEquals(2, len(mail.outbox)) def test_auth_user_can_use(self): + # required instances company = CompanyFactory() product = ProductFactory(company=company) + # make user the manager + self.user.company = company + self.user.role = 'COOP_MANAGER' + self.user.save() data = { 'telephone': '123123123', diff --git a/products/views.py b/products/views.py index 4e132ae..f75efdb 100644 --- a/products/views.py +++ b/products/views.py @@ -273,10 +273,16 @@ def purchase_email(request): validate_email(user_email) except: return Response({"error": "Value for email is not valid"}, status=status.HTTP_406_NOT_ACCEPTABLE) + # get comment + comment = data.get('comment') # get company company = Company.objects.filter(id=data['company']).first() if not company: return Response({"error": "Invalid value for company"}, status=status.HTTP_406_NOT_ACCEPTABLE) + # get managing user + managing_user = User.objects.filter(company=company, role='COOP_MANAGER').first() + if not managing_user: + return Response({"error": "No managing user found for company"}, status=status.HTTP_406_NOT_ACCEPTABLE) # get product product = Product.objects.filter(id=data['product'], company=company).first() if not product: @@ -291,6 +297,7 @@ def purchase_email(request): 'user': request.user, 'product': product, 'telephone': data['telephone'], + 'comment': comment, }) subject = "[latienda.coop] Solicitud de compra" email = EmailMessage(subject, company_message, to=[company.email]) @@ -301,6 +308,7 @@ def purchase_email(request): 'company': company, 'product': product, 'company_message': company_message, + 'manager': managing_user, }) subject = 'Confirmación de petición de compra' email = EmailMessage(subject, user_message, to=[user_email]) diff --git a/templates/purchase_contact_confirmation.html b/templates/purchase_contact_confirmation.html old mode 100644 new mode 100755 index 7d5deb6..32652ff --- a/templates/purchase_contact_confirmation.html +++ b/templates/purchase_contact_confirmation.html @@ -1,10 +1,197 @@ -Hola usuario. + + + + + + + + + -Hemos envíado correctamente el siguiente email a la empresa {{company}} sobre el producto {{product}}: + + Interés en copra de producto + + + +
+
+ + + +

+ Confirmación de + solicitud enviada +

+
+
+ +
+ + + + Enlace al producto + Nombre del producto: {{product.name}} + {{product.sku}} + {{product.price}} +

¡Hola! Tu solicitud de compra de este producto ha sido comunicado a la cooperativa. Pronto tendrás noticias suyas. Para cualquier duda o asistencia, ponte en contacto con {{company.short_name}}.

+
+
+

Contacto cooperativa

+
+
Nombre:
+
{{manager.full_name}}
+
Email:
+
{{company.email}}
+ +
+ + + +
+
+
+ 2021 La Tienda.Coop +
+
+ + diff --git a/templates/purchase_notification.html b/templates/purchase_notification.html old mode 100644 new mode 100755 index 896baef..c377a12 --- a/templates/purchase_notification.html +++ b/templates/purchase_notification.html @@ -1,9 +1,175 @@ -Hola {{company}}. + + + + + + + + + -El usuario {{user.email}} ha mostrado interés en la compra del producto {{product}}. + + Interés en copra de producto + + + +
+
+ + + +

+ Interés en compra + de producto +

+
+
+
+ + + + Enlace al producto + Nombre del producto: {{product.name}} + {{product.sku}} + {{product.price}} +
+
+

Datos cliente

+
+
Nombre:
+
{{user.full_name}}
+
Email:
+
{{user.email}}
+
Teléfono:
+
{{telephone}}
+
Comentarios:
+
{{comment}}
+
+
+
+
+ +
+ +