Skip to content

Commit

Permalink
Merge pull request #289 from nossas/feature/form-actions
Browse files Browse the repository at this point in the history
Form Action para envio de E-mail
  • Loading branch information
igr-santos authored Sep 11, 2024
2 parents 88b5296 + 3a8154f commit 775fee3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
61 changes: 61 additions & 0 deletions app/contrib/bonde/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
# Register your models here.

from django.utils.translation import gettext_lazy as _
from django.core.mail import EmailMultiAlternatives
from django.template import Context, Template

from djangocms_text_ckeditor.widgets import TextEditorWidget
from djangocms_form_builder import actions

from .api import create_form_entry
Expand Down Expand Up @@ -33,3 +37,60 @@ def execute(self, form, request):

if len(list(filter(lambda x: not x, settings.values()))) == 0:
create_form_entry(settings, **form.cleaned_data)



@actions.register
class IntegrateWithEmail(actions.FormAction):
verbose_name = _("Integração com o EMAIL")

class Meta:
entangled_fields = {
"action_parameters": ["subject", "to_email", "email_text_html"]
}

# name = forms.CharField(label="Nome", required=False)
to_email = forms.EmailField(label="Email", required=False)
subject = forms.CharField(
label="Assunto",
required=False,
help_text="Você pode usar {{FieldName}} para inserir uma informaçâo do formulário nesse texto.",
)
email_text_html = forms.CharField(
label="Corpo do e-mail",
help_text="Você pode usar {{FieldName}} para inserir uma informaçâo do formulário nesse texto.",
required=False,
widget=TextEditorWidget
)

def execute(self, form, request):
# name = self.get_parameter(form, "name")
to_email = self.get_parameter(form, "to_email")
subject_text = self.get_parameter(form, "subject")
email_text_html = self.get_parameter(form, "email_text_html")

# context = form.cleaned_data
# email_template_name = "forms/body.html"
# html_email_template_name = email_template_name
# import ipdb;ipdb.set_trace()
# if to_email and body_text and subject_text:
"""
Send a django.core.mail.EmailMultiAlternatives to `to_email`.
"""
from_email = form.cleaned_data.get("email")
context = Context({**form.cleaned_data})
# subject = loader.render_to_string(subject_template_name, context)
# Email subject *must not* contain newlines
# subject = "".join(subject.splitlines())

subject = Template(subject_text).render(context)
body = Template(email_text_html).render(context)

# import ipdb;ipdb.set_trace()
email_message = EmailMultiAlternatives(subject, body, from_email, [to_email])
email_message.attach_alternative(body, "text/html")
email_message.send()

# TODO:
# Adicionar campos do formulário no contexto do assunto
#
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ <h3 class="fw-bold text-uppercase mb-3">Compartilhe nas redes sociais
<p class="w-75">Compartilhe esse perfil nas redes sociais e com seus amigos para que as propostas de {{ candidature.ballot_name }} cheguem em mais gente:</p>
</div>
<p>
Viu algo estranho? <a class="fw-bold text-black" href="mailto:[email protected]" target="_blank" rel="noopener noreferrer">Clique aqui para denunciar esse perfil.</a>
Viu algo estranho? <a class="fw-bold text-black" href="/denunciar-perfil" target="_blank" rel="noopener noreferrer">Clique aqui para denunciar esse perfil.</a>
</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
{% comment %} <li><a class="text-white text-uppercase fw-bold" href="{% url 'candidature-list' %}" rel="noopener noreferrer">Conheça as candidaturas</a></li> {% endcomment %}
<li><a class="text-white text-uppercase fw-bold" href="{% url 'register' %}" rel="noopener noreferrer">Cadastre-se</a></li>
<li><a class="text-white text-uppercase fw-bold" href="{% url 'dashboard' %}" rel="noopener noreferrer">Login</a></li>
<li><a class="text-white text-uppercase fw-bold" href="mailto:[email protected]" rel="noopener noreferrer">Contato</a></li>
<li><a class="text-white text-uppercase fw-bold" href="/contato" rel="noopener noreferrer">Contato</a></li>
</ul>
</div>
<div class="g-col-12 g-col-md-4">
Expand Down

0 comments on commit 775fee3

Please sign in to comment.