mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Add sending of html email for the request
This commit is contained in:
@@ -2,7 +2,8 @@ import cStringIO as StringIO
|
||||
from io import BytesIO
|
||||
import urllib2
|
||||
|
||||
from django.core.mail import EmailMessage
|
||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||
from django.core.mail import EmailMessage, EmailMultiAlternatives
|
||||
from django.views import generic
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.shortcuts import get_object_or_404
|
||||
@@ -18,6 +19,7 @@ from django.contrib import messages
|
||||
from z3c.rml import rml2pdf
|
||||
from PyPDF2 import PdfFileMerger, PdfFileReader
|
||||
import simplejson
|
||||
import premailer
|
||||
|
||||
from RIGS import models, forms
|
||||
import datetime
|
||||
@@ -325,14 +327,44 @@ class EventAuthorisationRequest(generic.FormView, generic.detail.SingleObjectMix
|
||||
'sent_by': self.request.user.pk,
|
||||
}),
|
||||
}
|
||||
if email == event.person.email:
|
||||
context['to_name'] = event.person.name
|
||||
|
||||
msg = EmailMessage(
|
||||
msg = EmailMultiAlternatives(
|
||||
"N%05d | %s - Event Authorisation Request" % (self.object.pk, self.object.name),
|
||||
get_template("RIGS/eventauthorisation_client_request.txt").render(context),
|
||||
to=[email],
|
||||
reply_to=[settings.AUTHORISATION_NOTIFICATION_ADDRESS],
|
||||
)
|
||||
css = staticfiles_storage.path('css/email.css')
|
||||
html = premailer.Premailer(get_template("RIGS/eventauthorisation_client_request.html").render(context),
|
||||
external_styles=css).transform()
|
||||
msg.attach_alternative(html, 'text/html')
|
||||
|
||||
|
||||
msg.send()
|
||||
|
||||
return super(EventAuthorisationRequest, self).form_valid(form)
|
||||
|
||||
|
||||
class EventAuthoriseRequestEmailPreview(generic.DetailView):
|
||||
template_name = "RIGS/eventauthorisation_client_request.html"
|
||||
model = models.Event
|
||||
|
||||
def render_to_response(self, context, **response_kwargs):
|
||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||
css = staticfiles_storage.path('css/email.css')
|
||||
response = super(EventAuthoriseRequestEmailPreview, self).render_to_response(context, **response_kwargs)
|
||||
assert isinstance(response, HttpResponse)
|
||||
response.content = premailer.Premailer(response.rendered_content, external_styles=css).transform()
|
||||
return response
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(EventAuthoriseRequestEmailPreview, self).get_context_data(**kwargs)
|
||||
context['hmac'] = signing.dumps({
|
||||
'pk': self.object.pk,
|
||||
'email': self.request.GET.get('email', 'hello@world.test'),
|
||||
'sent_by': self.request.user.pk,
|
||||
})
|
||||
context['to_name'] = self.request.GET.get('to_name', None)
|
||||
return context
|
||||
|
||||
1
RIGS/static/css/email.css
Normal file
1
RIGS/static/css/email.css
Normal file
File diff suppressed because one or more lines are too long
35
RIGS/static/scss/email.scss
Normal file
35
RIGS/static/scss/email.scss
Normal file
@@ -0,0 +1,35 @@
|
||||
@import "bootstrap-compass";
|
||||
// Core variables and mixins
|
||||
@import "bootstrap/variables";
|
||||
@import "bootstrap-variables";
|
||||
@import "bootstrap/mixins";
|
||||
|
||||
// Reset and dependencies
|
||||
@import "bootstrap/normalize";
|
||||
@import "bootstrap/print";
|
||||
@import "bootstrap/glyphicons";
|
||||
|
||||
// Core CSS
|
||||
@import "bootstrap/scaffolding";
|
||||
@import "bootstrap/type";
|
||||
@import "bootstrap/code";
|
||||
@import "bootstrap/grid";
|
||||
@import "bootstrap/tables";
|
||||
@import "bootstrap/forms";
|
||||
@import "bootstrap/buttons";
|
||||
|
||||
|
||||
.client-header {
|
||||
background-image: url("https://www.nottinghamtec.co.uk/imgs/wof2014-1.jpg");
|
||||
background-color: #222;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
background-size: cover;
|
||||
|
||||
margin-bottom: 2em;
|
||||
|
||||
img {
|
||||
height: 8em;
|
||||
margin: 2em;
|
||||
}
|
||||
}
|
||||
32
RIGS/templates/RIGS/eventauthorisation_client_request.html
Normal file
32
RIGS/templates/RIGS/eventauthorisation_client_request.html
Normal file
@@ -0,0 +1,32 @@
|
||||
{% extends 'base_client_email.html' %}
|
||||
|
||||
{% block content %}
|
||||
<div class="col-sm-12">
|
||||
<p>Hi {{ to_name|default:"there" }},</p>
|
||||
|
||||
<p>{{ request.user.get_full_name }} has requested that you authorise N{{ object.pk|stringformat:"05d" }}
|
||||
| {{ object.name }}{% if not to_name %} on behalf of {{ object.person.name }}{% endif %}.</p>
|
||||
|
||||
<p>
|
||||
Please find the link below to complete the event booking process.
|
||||
{% if object.event.organisation and object.event.organisation.union_account %}{# internal #}
|
||||
Remember that only Presidents or Treasurers are allowed to sign off payments. You may need to forward
|
||||
this
|
||||
email on.
|
||||
{% endif %}
|
||||
</p>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-6 col-sm-offset-3 text-center">
|
||||
<a class="btn btn-primary"
|
||||
href="{{ request.scheme }}://{{ request.get_host }}{% url 'event_authorise' object.pk hmac %}">
|
||||
Complete Authorisation Form
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>Please note you event will not be booked until you complete this form.</p>
|
||||
|
||||
<p>TEC PA & Lighting</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -1,12 +1,16 @@
|
||||
Hi there,
|
||||
Hi {{ to_name|default:"there" }},
|
||||
|
||||
{{request.user.get_full_name}} has requested that you authorise N{{object.pk|stringformat:"05d"}} | {{object.name}}.
|
||||
{{ request.user.get_full_name }} has requested that you authorise N{{ object.pk|stringformat:"05d" }}| {{ object.name }}{% if not to_name %} on behalf of {{ object.person.name }}{% endif %}.
|
||||
|
||||
Please find the link below to complete the event booking process.
|
||||
{% if object.event.organisation and object.event.organisation.union_account %}{# internal #}
|
||||
Remember that only Presidents or Treasurers are allowed to sign off payments. You may need to forward this email on.
|
||||
{% endif %}
|
||||
Please find the link below to complete the event booking process.
|
||||
{% if object.event.organisation and object.event.organisation.union_account %}{# internal #}
|
||||
Remember that only Presidents or Treasurers are allowed to sign off payments. You may need to forward
|
||||
this
|
||||
email on.
|
||||
{% endif %}
|
||||
|
||||
{{request.scheme}}://{{request.get_host}}{% url 'event_authorise' object.pk hmac %}
|
||||
{{ request.scheme }}://{{ request.get_host }}{% url 'event_authorise' object.pk hmac %}
|
||||
|
||||
The TEC Rig Information Gathering System
|
||||
Please note you event will not be booked until you complete this form.
|
||||
|
||||
TEC PA & Lighting
|
||||
|
||||
@@ -155,6 +155,11 @@ urlpatterns = patterns('',
|
||||
rigboard.EventAuthorisationRequest.as_view()
|
||||
),
|
||||
name='event_authorise_request'),
|
||||
url(r'^event/(?P<pk>\d+)/auth/preview/$',
|
||||
permission_required_with_403('RIGS.change_event')(
|
||||
rigboard.EventAuthoriseRequestEmailPreview.as_view()
|
||||
),
|
||||
name='event_authorise_preview'),
|
||||
url(r'^event/(?P<pk>\d+)/(?P<hmac>[-:\w]+)/$', rigboard.EventAuthorise.as_view(),
|
||||
name='event_authorise'),
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ gunicorn==19.3.0
|
||||
icalendar==3.9.0
|
||||
lxml==3.4.4
|
||||
Pillow==2.8.1
|
||||
premailer==3.0.1
|
||||
psycopg2==2.6
|
||||
Pygments==2.0.2
|
||||
PyPDF2==1.24
|
||||
|
||||
49
templates/base_client_email.html
Normal file
49
templates/base_client_email.html
Normal file
@@ -0,0 +1,49 @@
|
||||
{% load static from staticfiles %}
|
||||
{% load raven %}
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html
|
||||
dir="{% if LANGUAGE_BIDI %}rtl{% else %}ltr{% endif %}"
|
||||
xml:lang="{% firstof LANGUAGE_CODE 'en' %}"
|
||||
lang="{% firstof LANGUAGE_CODE 'en' %}">
|
||||
<head>
|
||||
<meta name="viewport" content="initial-scale=1">
|
||||
|
||||
{% block css %}
|
||||
{% endblock %}
|
||||
|
||||
<script src="https://code.jquery.com/jquery-1.8.3.min.js"
|
||||
integrity="sha256-YcbK69I5IXQftf/mYD8WY0/KmEDCv1asggHpJk1trM8=" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.ravenjs.com/1.3.0/jquery,native/raven.min.js"></script>
|
||||
<script>Raven.config('{% sentry_public_dsn %}').install()</script>
|
||||
{% block preload_js %}
|
||||
{% endblock %}
|
||||
|
||||
{% block extra-head %}{% endblock %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="row client-header">
|
||||
<table class="container">
|
||||
<tr>
|
||||
<td>
|
||||
<img src="https://www.nottinghamtec.co.uk/imgs/tec_logo_white.png"/>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<img src="https://www.nottinghamtec.co.uk/imgs/UoNSU.png"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<div id="content" class="row">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% block js %}
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user