Added sending email to user on create vm

This commit is contained in:
PCoder 2017-09-16 19:30:31 +05:30
parent f2ee0ea657
commit acb739944b
2 changed files with 26 additions and 1 deletions

View File

@ -5,6 +5,7 @@ from celery.utils.log import get_task_logger
from celery import current_task
from django.conf import settings
from django.core.mail import EmailMessage
from django.utils.translation import ugettext_lazy as _
from dynamicweb.celery import app
from hosting.models import HostingOrder, HostingBill
@ -13,6 +14,7 @@ from opennebula_api.models import OpenNebulaManager
from opennebula_api.serializers import VirtualMachineSerializer
from utils.hosting_utils import get_all_public_keys
from utils.forms import UserBillingAddressForm
from utils.mailer import BaseEmail
from utils.models import BillingAddress
logger = get_task_logger(__name__)
@ -139,6 +141,27 @@ def create_vm_task(self, vm_template_id, user, specs, template,
email.send()
if 'pass' in user:
# Send notification to the user as soon as VM has been booked
context = {
'vm': vm,
'order': order,
'base_url': "{0}://{1}".format(user.get('request_scheme'),
user.get('request_host')),
'page_header': _(
'Your New VM %(vm_name)s at Data Center Light') % {
'vm_name': vm.get('name')}
}
email_data = {
'subject': context.get('page_header'),
'to': user.get('email'),
'context': context,
'template_name': 'new_booked_vm',
'template_path': 'hosting/emails/',
'from_address': settings.DCL_SUPPORT_FROM_ADDRESS,
}
email = BaseEmail(**email_data)
email.send()
# try to see if we have the IP and that if the ssh keys can
# be configured
new_host = manager.get_primary_ipv4(vm_id)

View File

@ -754,7 +754,9 @@ class OrdersHostingDetailView(LoginRequiredMixin,
user = {
'name': self.request.user.name,
'email': self.request.user.email,
'pass': self.request.user.password
'pass': self.request.user.password,
'request_scheme': request.scheme,
'request_host': request.get_host(),
}
create_vm_task.delay(vm_template_id, user, specs, template,
stripe_customer_id, billing_address_data,