From 13c42a33a7fbc64cc5243efa57dacaf4e5bdb95d Mon Sep 17 00:00:00 2001 From: julio Date: Thu, 30 May 2024 11:51:53 +0200 Subject: [PATCH] #166 - added new admin email field and email confirmation sending when new user is created --- authentication/models/preregister.py | 10 ++++++++++ core/migrations/0012_node_admin_email.py | 18 ++++++++++++++++++ core/models/node.py | 1 + .../email/admin_preregister_confirm_msg.html | 11 +++++++++++ .../email/admin_preregister_confirm_msg.txt | 9 +++++++++ templates/market/form.html | 1 + 6 files changed, 50 insertions(+) create mode 100644 core/migrations/0012_node_admin_email.py create mode 100644 templates/email/admin_preregister_confirm_msg.html create mode 100644 templates/email/admin_preregister_confirm_msg.txt diff --git a/authentication/models/preregister.py b/authentication/models/preregister.py index 4d1ccbb..6514e48 100644 --- a/authentication/models/preregister.py +++ b/authentication/models/preregister.py @@ -47,6 +47,16 @@ def send_email(self): self.email_sent = True self.save() + + # Admin confirmation email + send_template_email( + title=_('Nueva usuaria creada en la app'), + destination=self.account.node.admin_email, + template_name='admin_preregister_confirm_msg', + template_params={ + 'user': self.user, + 'account': self.account } + ) except Exception as e: print(e) diff --git a/core/migrations/0012_node_admin_email.py b/core/migrations/0012_node_admin_email.py new file mode 100644 index 0000000..a83fb01 --- /dev/null +++ b/core/migrations/0012_node_admin_email.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0 on 2024-05-30 09:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0011_node_add_takahe_invite_url'), + ] + + operations = [ + migrations.AddField( + model_name='node', + name='admin_email', + field=models.EmailField(blank=True, help_text='Para mensajes de la herramienta', max_length=200, null=True, verbose_name='Email de administración'), + ), + ] diff --git a/core/models/node.py b/core/models/node.py index db96f57..d280f03 100644 --- a/core/models/node.py +++ b/core/models/node.py @@ -14,6 +14,7 @@ class Node(models.Model): longitude = models.FloatField(null=False, verbose_name=_('Longitud'), default=0) contact_email = models.EmailField(null=True, blank=True, max_length=200, verbose_name=_('Email de contacto')) + admin_email = models.EmailField(null=True, blank=True, max_length=200, verbose_name=_('Email de administración'), help_text=_('Para mensajes de la herramienta')) self_register_allowed = models.BooleanField(default=False, verbose_name=_('Permitir el registro abierto')) register_provider_url = models.TextField(blank=True, null=True, verbose_name=_('Enlace al formulario de registro de proveedoras')) register_consumer_url = models.TextField(blank=True, null=True, verbose_name=_('Enlace al formulario de registro de consumidoras')) diff --git a/templates/email/admin_preregister_confirm_msg.html b/templates/email/admin_preregister_confirm_msg.html new file mode 100644 index 0000000..ecb9b3e --- /dev/null +++ b/templates/email/admin_preregister_confirm_msg.html @@ -0,0 +1,11 @@ +{% load settings_value %} + +

Nueva usuaria registrada en la app.

+ +

+{% if account %} + Se ha creado correctamente un usuario en la app para {{account.display_name}} y se le ha enviado el email de bienvenida a {{account.email}} +{% else %} + Se ha creado correctamente un usuario en la app para {{user.email}} (Sin cuenta de miembro asociada) y se le ha enviado el email de bienvenida. +{% endif %} +

\ No newline at end of file diff --git a/templates/email/admin_preregister_confirm_msg.txt b/templates/email/admin_preregister_confirm_msg.txt new file mode 100644 index 0000000..5b23216 --- /dev/null +++ b/templates/email/admin_preregister_confirm_msg.txt @@ -0,0 +1,9 @@ +{% load settings_value %} + +Nueva usuaria registrada en la app. + +{% if account %} + Se ha creado correctamente un usuario en la app para {{account.display_name}} y se le ha enviado el email de bienvenida a {{account.email}} +{% else %} + Se ha creado correctamente un usuario en la app para {{user.email}} (Sin cuenta de miembro asociada) y se le ha enviado el email de bienvenida. +{% endif %} \ No newline at end of file diff --git a/templates/market/form.html b/templates/market/form.html index 3aee0e1..e2bd130 100644 --- a/templates/market/form.html +++ b/templates/market/form.html @@ -43,6 +43,7 @@

edit_location {% translate {% include "common/forms/field.html" with field=form.info_page_url %} {% include "common/forms/field.html" with field=form.contact_email %} + {% include "common/forms/field.html" with field=form.admin_email %}