Added cron to send email and fixing settings error
This commit is contained in:
parent
14905db9dc
commit
9f2c78db33
15 changed files with 42 additions and 25 deletions
|
@ -55,6 +55,7 @@ INSTALLED_APPS = (
|
||||||
'easy_thumbnails',
|
'easy_thumbnails',
|
||||||
'utils',
|
'utils',
|
||||||
'stored_messages',
|
'stored_messages',
|
||||||
|
'mailer',
|
||||||
'mptt',
|
'mptt',
|
||||||
'parler',
|
'parler',
|
||||||
'taggit',
|
'taggit',
|
||||||
|
|
|
@ -8,6 +8,8 @@ ADMINS = (
|
||||||
)
|
)
|
||||||
# ('Sanghee Kim', 'sanghee.kim@ungleich.ch'),
|
# ('Sanghee Kim', 'sanghee.kim@ungleich.ch'),
|
||||||
|
|
||||||
|
EMAIL_BACKEND = "mailer.backend.DbBackend"
|
||||||
|
|
||||||
#MANAGERS = ADMINS
|
#MANAGERS = ADMINS
|
||||||
|
|
||||||
REGISTRATION_MESSAGE['message'] = REGISTRATION_MESSAGE['message'].format(host='digitalglarus.ungleich.ch',slug='{slug}')
|
REGISTRATION_MESSAGE['message'] = REGISTRATION_MESSAGE['message'].format(host='digitalglarus.ungleich.ch',slug='{slug}')
|
||||||
|
|
|
@ -25,7 +25,7 @@ urlpatterns += i18n_patterns('',
|
||||||
url(r'^digitalglarus/login/', include(membership_urls)),
|
url(r'^digitalglarus/login/', include(membership_urls)),
|
||||||
url(r'^digitalglarus/', include('digitalglarus.urls',
|
url(r'^digitalglarus/', include('digitalglarus.urls',
|
||||||
namespace="digitalglarus")),
|
namespace="digitalglarus")),
|
||||||
url(r'^blog/', include('ungleich.urls', namespace='ungleich')),
|
# url(r'^blog/', include('ungleich.urls', namespace='ungleich')),
|
||||||
url(r'^ungleich_page/',
|
url(r'^ungleich_page/',
|
||||||
include('ungleich_page.urls', namespace='ungleich_page'),
|
include('ungleich_page.urls', namespace='ungleich_page'),
|
||||||
name='ungleich_page'),
|
name='ungleich_page'),
|
||||||
|
|
3
email_cron
Normal file
3
email_cron
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
* * * * * (cd /home/app/app/; /usr/bin/python3 manage.py send_mail)
|
||||||
|
0,20,40 * * * * (cd /home/app/app/; /usr/bin/python3 manage.py retry_deferred)
|
||||||
|
0 0 * * * (cd /home/app/app/; /usr/bin/python3 manage.py purge_mail_log 7)
|
|
@ -32,10 +32,11 @@ class HostingOrderAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'order': obj,
|
'order': obj,
|
||||||
'vm': obj.vm_plan
|
'vm': obj.vm_plan,
|
||||||
|
'base_url': "{0}://{1}".format(request.scheme, request.get_host())
|
||||||
}
|
}
|
||||||
email_data = {
|
email_data = {
|
||||||
'subject': 'New VM request',
|
'subject': 'Your VM plan has been charged',
|
||||||
'to': obj.customer.user.email,
|
'to': obj.customer.user.email,
|
||||||
'context': context,
|
'context': context,
|
||||||
'template_name': 'vm_charged',
|
'template_name': 'vm_charged',
|
||||||
|
@ -75,7 +76,8 @@ class VirtualMachinePlanAdmin(admin.ModelAdmin):
|
||||||
email = self.email(obj)
|
email = self.email(obj)
|
||||||
if 'status' in form.changed_data:
|
if 'status' in form.changed_data:
|
||||||
context = {
|
context = {
|
||||||
'vm': obj
|
'vm': obj,
|
||||||
|
'base_url': "{0}://{1}".format(request.scheme, request.get_host())
|
||||||
}
|
}
|
||||||
email_data = {
|
email_data = {
|
||||||
'subject': 'Your VM has been activated',
|
'subject': 'Your VM has been activated',
|
||||||
|
|
|
@ -114,7 +114,7 @@
|
||||||
<w:anchorlock/>
|
<w:anchorlock/>
|
||||||
<center style="color:#ffffff;font-family:Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;">My Account</center>
|
<center style="color:#ffffff;font-family:Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;">My Account</center>
|
||||||
</v:roundrect>
|
</v:roundrect>
|
||||||
<![endif]--><a href="{% url 'hosting:orders' order.id %}" style="border-radius: 5px; color: #ffffff; display: inline-block; font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; font-size: 14px; font-weight: regular; line-height: 45px; text-align: center; text-decoration: none !important; width: 155px; -webkit-text-size-adjust: none; mso-hide: all; background: #ff6f6f;">View Invoice</a>
|
<![endif]--><a href="{{ base_url }}{% url 'hosting:orders' order.id %}" style="border-radius: 5px; color: #ffffff; display: inline-block; font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; font-size: 14px; font-weight: regular; line-height: 45px; text-align: center; text-decoration: none !important; width: 155px; -webkit-text-size-adjust: none; mso-hide: all; background: #ff6f6f;">View Invoice</a>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -101,7 +101,7 @@
|
||||||
<td class="free-text" style="border-collapse: collapse; font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; font-size: 14px; color: #777777; text-align: center; line-height: 21px; width: 100% !important; padding: 10px 60px 0px;" align="center">
|
<td class="free-text" style="border-collapse: collapse; font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; font-size: 14px; color: #777777; text-align: center; line-height: 21px; width: 100% !important; padding: 10px 60px 0px;" align="center">
|
||||||
Your virtual machine {{vm.name}} subscription has been charged,
|
Your virtual machine {{vm.name}} subscription has been charged,
|
||||||
<br/>
|
<br/>
|
||||||
We are going to contact you as soon your virtual machine has been activated.
|
we are going to contact you as soon your virtual machine has been activated.
|
||||||
<br/>
|
<br/>
|
||||||
You can view your invoice clicking on the button below.
|
You can view your invoice clicking on the button below.
|
||||||
</td>
|
</td>
|
||||||
|
@ -114,7 +114,7 @@
|
||||||
<w:anchorlock/>
|
<w:anchorlock/>
|
||||||
<center style="color:#ffffff;font-family:Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;">My Account</center>
|
<center style="color:#ffffff;font-family:Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;">My Account</center>
|
||||||
</v:roundrect>
|
</v:roundrect>
|
||||||
<![endif]--><a href="{% url 'hosting:orders' order.id %}" style="border-radius: 5px; color: #ffffff; display: inline-block; font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; font-size: 14px; font-weight: regular; line-height: 45px; text-align: center; text-decoration: none !important; width: 155px; -webkit-text-size-adjust: none; mso-hide: all; background: #ff6f6f;">View Invoice</a>
|
<![endif]--><a href="{{ base_url }}{% url 'hosting:orders' order.id %}" style="border-radius: 5px; color: #ffffff; display: inline-block; font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; font-size: 14px; font-weight: regular; line-height: 45px; text-align: center; text-decoration: none !important; width: 155px; -webkit-text-size-adjust: none; mso-hide: all; background: #ff6f6f;">View Invoice</a>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -110,7 +110,7 @@
|
||||||
<w:anchorlock/>
|
<w:anchorlock/>
|
||||||
<center style="color:#ffffff;font-family:Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;">My Account</center>
|
<center style="color:#ffffff;font-family:Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;">My Account</center>
|
||||||
</v:roundrect>
|
</v:roundrect>
|
||||||
<![endif]--><a href="{% url 'hosting:orders' order.id %}" style="border-radius: 5px; color: #ffffff; display: inline-block; font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; font-size: 14px; font-weight: regular; line-height: 45px; text-align: center; text-decoration: none !important; width: 155px; -webkit-text-size-adjust: none; mso-hide: all; background: #ff6f6f;">View Invoice</a>
|
<![endif]--><a href="{{ base_url }}{% url 'hosting:orders' order.id %}" style="border-radius: 5px; color: #ffffff; display: inline-block; font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; font-size: 14px; font-weight: regular; line-height: 45px; text-align: center; text-decoration: none !important; width: 155px; -webkit-text-size-adjust: none; mso-hide: all; background: #ff6f6f;">View Invoice</a>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -110,7 +110,7 @@
|
||||||
<w:anchorlock/>
|
<w:anchorlock/>
|
||||||
<center style="color:#ffffff;font-family:Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;">My Account</center>
|
<center style="color:#ffffff;font-family:Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;">My Account</center>
|
||||||
</v:roundrect>
|
</v:roundrect>
|
||||||
<![endif]--><a href="{% url 'hosting:orders' order.id %}" style="border-radius: 5px; color: #ffffff; display: inline-block; font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; font-size: 14px; font-weight: regular; line-height: 45px; text-align: center; text-decoration: none !important; width: 155px; -webkit-text-size-adjust: none; mso-hide: all; background: #ff6f6f;">View Invoice</a>
|
<![endif]--><a href="{{ base_url }}{% url 'hosting:orders' order.id %}" style="border-radius: 5px; color: #ffffff; display: inline-block; font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; font-size: 14px; font-weight: regular; line-height: 45px; text-align: center; text-decoration: none !important; width: 155px; -webkit-text-size-adjust: none; mso-hide: all; background: #ff6f6f;">View Invoice</a>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -111,7 +111,7 @@
|
||||||
<w:anchorlock/>
|
<w:anchorlock/>
|
||||||
<center style="color:#ffffff;font-family:Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;">My Account</center>
|
<center style="color:#ffffff;font-family:Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;">My Account</center>
|
||||||
</v:roundrect>
|
</v:roundrect>
|
||||||
<![endif]--><a href="{{request.HOS}}{% url 'hosting:virtual_machines' vm.id %}" style="border-radius: 5px; color: #ffffff; display: inline-block; font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; font-size: 14px; font-weight: regular; line-height: 45px; text-align: center; text-decoration: none !important; width: 155px; -webkit-text-size-adjust: none; mso-hide: all; background: #ff6f6f;">VM Dashboard</a>
|
<![endif]--><a href="{{base_url}}{% url 'hosting:virtual_machines' vm.id %}" style="border-radius: 5px; color: #ffffff; display: inline-block; font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; font-size: 14px; font-weight: regular; line-height: 45px; text-align: center; text-decoration: none !important; width: 155px; -webkit-text-size-adjust: none; mso-hide: all; background: #ff6f6f;">VM Dashboard</a>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -111,7 +111,7 @@
|
||||||
<w:anchorlock/>
|
<w:anchorlock/>
|
||||||
<center style="color:#ffffff;font-family:Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;">My Account</center>
|
<center style="color:#ffffff;font-family:Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;">My Account</center>
|
||||||
</v:roundrect>
|
</v:roundrect>
|
||||||
<![endif]--><a href="{{request.HOS}}{% url 'hosting:virtual_machines' vm.id %}" style="border-radius: 5px; color: #ffffff; display: inline-block; font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; font-size: 14px; font-weight: regular; line-height: 45px; text-align: center; text-decoration: none !important; width: 155px; -webkit-text-size-adjust: none; mso-hide: all; background: #ff6f6f;">VM Dashboard</a>
|
<![endif]--><a href="{{base_url}}{% url 'hosting:virtual_machines' vm.id %}" style="border-radius: 5px; color: #ffffff; display: inline-block; font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; font-size: 14px; font-weight: regular; line-height: 45px; text-align: center; text-decoration: none !important; width: 155px; -webkit-text-size-adjust: none; mso-hide: all; background: #ff6f6f;">VM Dashboard</a>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -10,7 +10,7 @@ from model_mommy import mommy
|
||||||
from membership.models import CustomUser, StripeCustomer
|
from membership.models import CustomUser, StripeCustomer
|
||||||
from .models import VirtualMachineType, HostingOrder, VirtualMachinePlan
|
from .models import VirtualMachineType, HostingOrder, VirtualMachinePlan
|
||||||
from .views import DjangoHostingView, RailsHostingView, NodeJSHostingView, LoginView, SignupView, \
|
from .views import DjangoHostingView, RailsHostingView, NodeJSHostingView, LoginView, SignupView, \
|
||||||
PaymentVMView, OrdersHostingDetailView, OrdersHostingListView, VirtualMachineDetailView, \
|
PaymentVMView, OrdersHostingDetailView, OrdersHostingListView, VirtualMachineView, \
|
||||||
VirtualMachinesPlanListView
|
VirtualMachinesPlanListView
|
||||||
from utils.tests import BaseTestCase
|
from utils.tests import BaseTestCase
|
||||||
|
|
||||||
|
@ -172,16 +172,16 @@ class PaymentVMViewTest(BaseTestCase):
|
||||||
settings.STRIPE_API_PUBLIC_KEY)
|
settings.STRIPE_API_PUBLIC_KEY)
|
||||||
|
|
||||||
|
|
||||||
class VirtualMachineDetailViewTest(BaseTestCase):
|
class VirtualMachineViewTest(BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(VirtualMachineDetailViewTest, self).setUp()
|
super(VirtualMachineViewTest, self).setUp()
|
||||||
|
|
||||||
self.stripe_customer = mommy.make(StripeCustomer, user=self.customer)
|
self.stripe_customer = mommy.make(StripeCustomer, user=self.customer)
|
||||||
self.vm = mommy.make(VirtualMachinePlan)
|
self.vm = mommy.make(VirtualMachinePlan)
|
||||||
self.order = mommy.make(HostingOrder, customer=self.stripe_customer, vm_plan=self.vm)
|
self.order = mommy.make(HostingOrder, customer=self.stripe_customer, vm_plan=self.vm)
|
||||||
self.url = reverse('hosting:virtual_machines', kwargs={'pk': self.vm.id})
|
self.url = reverse('hosting:virtual_machines', kwargs={'pk': self.vm.id})
|
||||||
self.view = VirtualMachineDetailView()
|
self.view = VirtualMachineView()
|
||||||
self.expected_template = 'hosting/virtual_machine_detail.html'
|
self.expected_template = 'hosting/virtual_machine_detail.html'
|
||||||
|
|
||||||
def url_resolve_to_view_correctly(self):
|
def url_resolve_to_view_correctly(self):
|
||||||
|
|
|
@ -285,13 +285,26 @@ class PaymentVMView(LoginRequiredMixin, FormView):
|
||||||
|
|
||||||
# Send notification to ungleich as soon as VM has been booked
|
# Send notification to ungleich as soon as VM has been booked
|
||||||
# TODO send email using celery
|
# TODO send email using celery
|
||||||
|
|
||||||
|
from django.core.mail import send_mail
|
||||||
|
|
||||||
|
send_mail(
|
||||||
|
'Subject here',
|
||||||
|
'Here is the message.',
|
||||||
|
'levinoelvm@gmail.com',
|
||||||
|
['levinoelvm@gmail.com'],
|
||||||
|
fail_silently=False,
|
||||||
|
)
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'vm': plan,
|
'vm': plan,
|
||||||
'order': order
|
'order': order,
|
||||||
|
'base_url': "{0}://{1}".format(request.scheme, request.get_host())
|
||||||
|
|
||||||
}
|
}
|
||||||
email_data = {
|
email_data = {
|
||||||
'subject': 'New VM request',
|
'subject': 'New VM request',
|
||||||
'to': 'info@ungleich.ch',
|
'to': request.user.email,
|
||||||
'context': context,
|
'context': context,
|
||||||
'template_name': 'new_booked_vm',
|
'template_name': 'new_booked_vm',
|
||||||
'template_path': 'emails/'
|
'template_path': 'emails/'
|
||||||
|
@ -299,11 +312,6 @@ class PaymentVMView(LoginRequiredMixin, FormView):
|
||||||
email = BaseEmail(**email_data)
|
email = BaseEmail(**email_data)
|
||||||
email.send()
|
email.send()
|
||||||
|
|
||||||
# request.session.update({
|
|
||||||
# 'charge': charge,
|
|
||||||
# 'order': order.id,
|
|
||||||
# 'billing_address': billing_address.id
|
|
||||||
# })
|
|
||||||
return HttpResponseRedirect(reverse('hosting:orders', kwargs={'pk': order.id}))
|
return HttpResponseRedirect(reverse('hosting:orders', kwargs={'pk': order.id}))
|
||||||
else:
|
else:
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
@ -368,7 +376,8 @@ class VirtualMachineView(LoginRequiredMixin, UpdateView):
|
||||||
vm.cancel_plan()
|
vm.cancel_plan()
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'vm': vm
|
'vm': vm,
|
||||||
|
'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host())
|
||||||
}
|
}
|
||||||
email_data = {
|
email_data = {
|
||||||
'subject': 'Virtual machine plan canceled',
|
'subject': 'Virtual machine plan canceled',
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% load cms_tags menu_tags sekizai_tags staticfiles bootstrap3 %}
|
{% load i18n cms_tags menu_tags sekizai_tags staticfiles bootstrap3 %}
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
|
|
@ -21,7 +21,7 @@ class BaseEmail(object):
|
||||||
|
|
||||||
self.email = EmailMultiAlternatives(self.subject, text_content)
|
self.email = EmailMultiAlternatives(self.subject, text_content)
|
||||||
self.email.attach_alternative(html_content, "text/html")
|
self.email.attach_alternative(html_content, "text/html")
|
||||||
self.email.to = ['info@digitalglarus.ch']
|
self.email.to = ['levinoelvm@gmail.com']
|
||||||
|
|
||||||
def send(self):
|
def send(self):
|
||||||
self.email.send()
|
self.email.send()
|
||||||
|
|
Loading…
Reference in a new issue