wip send email with link to doc
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import smtplib
|
||||
import uuid
|
||||
import requests
|
||||
|
||||
from django.conf import settings
|
||||
from django.db.models import Q
|
||||
@@ -270,9 +271,17 @@ class RoomViewSet(
|
||||
transcript = self.request.data.get("transcript", None)
|
||||
|
||||
instance = self.get_object()
|
||||
owners = instance.get_owners()
|
||||
|
||||
email = owners[0].email
|
||||
|
||||
url = f"https://dinum-pad-dev.osc-fr1.scalingo.io/summary?email={email}"
|
||||
headers = {
|
||||
"Content-Type": "text/plain"
|
||||
}
|
||||
response = requests.post(url, headers=headers, data=summary, allow_redirects=False)
|
||||
try:
|
||||
instance.email_summary(summary=summary, transcript=transcript)
|
||||
instance.email_summary(summary=summary, transcript=transcript, owners=owners, link=response.headers['Location'])
|
||||
except smtplib.SMTPException:
|
||||
return drf_response.Response({"message": "Error"}, status=500)
|
||||
|
||||
|
||||
@@ -16,6 +16,9 @@ from django.utils.functional import lazy
|
||||
from django.utils.text import capfirst, slugify
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from django.core.mail import EmailMessage
|
||||
from django.core.files.base import ContentFile
|
||||
|
||||
from timezone_field import TimeZoneField
|
||||
|
||||
logger = getLogger(__name__)
|
||||
@@ -151,11 +154,28 @@ class User(AbstractBaseUser, BaseModel, auth_models.PermissionsMixin):
|
||||
def __str__(self):
|
||||
return self.email or self.admin_email or str(self.id)
|
||||
|
||||
def email_user(self, subject, message, from_email=None, **kwargs):
|
||||
def email_user(self, subject, transcript, from_email=None, **kwargs):
|
||||
"""Email this user."""
|
||||
if not self.email:
|
||||
raise ValueError("User has no email address.")
|
||||
mail.send_mail(subject, message, from_email, [self.email], **kwargs)
|
||||
# mail.send_mail(subject, message, from_email, [self.email], **kwargs)
|
||||
|
||||
email = EmailMessage(
|
||||
subject,
|
||||
kwargs['html_message'],
|
||||
from_email,
|
||||
[self.email],
|
||||
)
|
||||
|
||||
# email.attach_alternative(kwargs['html_message'], "text/html")
|
||||
|
||||
transcript = transcript or ''
|
||||
|
||||
wip_file = ContentFile(transcript, 'transcript.txt')
|
||||
|
||||
email.content_subtype = "html"
|
||||
email.attach(wip_file.name, wip_file.read(), 'text/plain')
|
||||
email.send()
|
||||
|
||||
def get_teams(self):
|
||||
"""
|
||||
@@ -332,16 +352,14 @@ class Room(Resource):
|
||||
owner_accesses = self.accesses.filter(role=RoleChoices.OWNER)
|
||||
return [access.user for access in owner_accesses]
|
||||
|
||||
def email_summary(self, summary, transcript):
|
||||
def email_summary(self, owners, summary, transcript, link):
|
||||
"""Wip"""
|
||||
|
||||
owners = self.get_owners()
|
||||
|
||||
template_vars = {
|
||||
"title": _("A new summary is ready"),
|
||||
"room": self.slug,
|
||||
"summary": summary,
|
||||
"transcript": transcript,
|
||||
"link": link,
|
||||
}
|
||||
|
||||
msg_plain = render_to_string("mail/text/summary.txt", template_vars)
|
||||
@@ -350,7 +368,7 @@ class Room(Resource):
|
||||
for owner in owners:
|
||||
owner.email_user(
|
||||
subject=_("A new summary is ready"),
|
||||
message=msg_plain,
|
||||
transcript=transcript,
|
||||
from_email=settings.EMAIL_FROM,
|
||||
html_message=msg_html,
|
||||
fail_silently=False,
|
||||
|
||||
@@ -2,25 +2,18 @@
|
||||
<mj-include path="./partial/header.mjml" />
|
||||
<mj-body mj-class="bg--blue-100">
|
||||
<mj-wrapper css-class="wrapper" padding="0 40px 40px 40px">
|
||||
<mj-section background-url="{% base64_static 'images/mail-header-background.png' %}" background-size="cover" background-repeat="no-repeat" background-position="0 -30px">
|
||||
<mj-column>
|
||||
<mj-image align="center" src="{% base64_static 'images/logo-suite-numerique.png' %}" width="250px" align="left" alt="{%trans 'La Suite Numérique' %}" />
|
||||
</mj-column>
|
||||
</mj-section>
|
||||
<mj-section mj-class="bg--white-100" padding="30px 20px 60px 20px">
|
||||
<mj-column>
|
||||
<mj-text font-size="14px">
|
||||
<p>Summary:</p>
|
||||
<p>{{summary}}</p>
|
||||
</mj-text>
|
||||
<mj-text font-size="14px">
|
||||
<p>Transcript:</p>
|
||||
<p>{{transcript}}</p>
|
||||
<p>Dear user,</p>
|
||||
<p>The meeting <strong>{{room}}</strong> has been successfully transcribed and summarized.</p>
|
||||
</mj-text>
|
||||
<mj-button href="{{link}}" font-size="14px" background-color="#346DB7" color="white">
|
||||
Get your summary
|
||||
</mj-button>
|
||||
</mj-column>
|
||||
</mj-section>
|
||||
</mj-wrapper>
|
||||
</mj-body>
|
||||
|
||||
<mj-include path="./partial/footer.mjml" />
|
||||
</mjml>
|
||||
|
||||
Reference in New Issue
Block a user