2017-02-15 04:34:06 +00:00
|
|
|
from django.views.generic import FormView, CreateView, TemplateView
|
|
|
|
from django.http import HttpResponseRedirect
|
2016-12-20 23:05:20 +00:00
|
|
|
from .forms import BetaAccessForm
|
2017-02-15 04:34:06 +00:00
|
|
|
from .models import BetaAccess, BetaAccessVMType, BetaAccessVM
|
2016-12-20 23:05:20 +00:00
|
|
|
from django.contrib import messages
|
2016-12-21 06:24:04 +00:00
|
|
|
from django.core.urlresolvers import reverse_lazy, reverse
|
2017-01-05 01:31:53 +00:00
|
|
|
from utils.mailer import BaseEmail
|
2016-12-20 23:05:20 +00:00
|
|
|
|
|
|
|
|
2017-02-15 04:34:06 +00:00
|
|
|
class LandingProgramView(TemplateView):
|
|
|
|
template_name = "datacenterlight/landing.html"
|
|
|
|
|
|
|
|
|
|
|
|
class BetaProgramView(CreateView):
|
|
|
|
template_name = "datacenterlight/beta.html"
|
|
|
|
model = BetaAccessVM
|
|
|
|
fields = '__all__'
|
|
|
|
# form_class = BetaAccessForm
|
|
|
|
# success_url = "/datacenterlight#requestform"
|
|
|
|
success_message = "Thank you, we will contact you as soon as possible"
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
success_url = reverse('datacenterlight:beta')
|
|
|
|
success_url += "#success"
|
|
|
|
return success_url
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
vms = BetaAccessVMType.objects.all()
|
|
|
|
context = super(BetaProgramView, self).get_context_data(**kwargs)
|
|
|
|
context.update({
|
|
|
|
'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host()),
|
|
|
|
'vms': vms
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
|
data = request.POST
|
2017-02-17 03:32:14 +00:00
|
|
|
vms = BetaAccessVM.create(data)
|
|
|
|
|
|
|
|
context = {
|
|
|
|
'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host()),
|
|
|
|
'email': data.get('email'),
|
|
|
|
'vms': vms
|
|
|
|
}
|
|
|
|
|
|
|
|
email_data = {
|
|
|
|
'subject': 'DatacenterLight Beta Access Request',
|
|
|
|
'to': 'info@ungleich.ch',
|
|
|
|
'context': context,
|
|
|
|
'template_name': 'request_beta_access_notification',
|
|
|
|
'template_path': 'datacenterlight/emails/'
|
|
|
|
}
|
|
|
|
email = BaseEmail(**email_data)
|
|
|
|
email.send()
|
|
|
|
|
|
|
|
messages.add_message(self.request, messages.SUCCESS, self.success_message)
|
2017-02-15 04:34:06 +00:00
|
|
|
return HttpResponseRedirect(self.get_success_url())
|
2017-02-17 03:32:14 +00:00
|
|
|
# return super(BetaProgramView, self).form_valid(form)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-15 04:34:06 +00:00
|
|
|
|
|
|
|
# def form_valid(self, form):
|
|
|
|
|
|
|
|
# context = {
|
|
|
|
# 'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host())
|
|
|
|
# }
|
|
|
|
|
|
|
|
# email_data = {
|
|
|
|
# 'subject': 'DatacenterLight Beta Access Request',
|
|
|
|
# 'to': form.cleaned_data.get('email'),
|
|
|
|
# 'context': context,
|
|
|
|
# 'template_name': 'request_access_confirmation',
|
|
|
|
# 'template_path': 'datacenterlight/emails/'
|
|
|
|
# }
|
|
|
|
# email = BaseEmail(**email_data)
|
|
|
|
# email.send()
|
|
|
|
|
|
|
|
# context.update({
|
|
|
|
# 'email': form.cleaned_data.get('email')
|
|
|
|
# })
|
|
|
|
|
|
|
|
# email_data = {
|
|
|
|
# 'subject': 'DatacenterLight Beta Access Request',
|
|
|
|
# 'to': 'info@ungleich.ch',
|
|
|
|
# 'context': context,
|
|
|
|
# 'template_name': 'request_access_notification',
|
|
|
|
# 'template_path': 'datacenterlight/emails/'
|
|
|
|
# }
|
|
|
|
# email = BaseEmail(**email_data)
|
|
|
|
# email.send()
|
|
|
|
|
|
|
|
# messages.add_message(self.request, messages.SUCCESS, self.success_message)
|
|
|
|
# return super(IndexView, self).form_valid(form)
|
|
|
|
|
|
|
|
|
2016-12-20 23:05:20 +00:00
|
|
|
class IndexView(CreateView):
|
|
|
|
template_name = "datacenterlight/index.html"
|
|
|
|
model = BetaAccess
|
|
|
|
form_class = BetaAccessForm
|
|
|
|
success_url = "/datacenterlight#requestform"
|
|
|
|
success_message = "Thank you, we will contact you as soon as possible"
|
|
|
|
|
2016-12-21 06:24:04 +00:00
|
|
|
def get_success_url(self):
|
|
|
|
success_url = reverse('datacenterlight:index')
|
|
|
|
success_url += "#requestform"
|
|
|
|
return success_url
|
|
|
|
|
2017-01-13 17:26:03 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(IndexView, self).get_context_data(**kwargs)
|
|
|
|
context.update({
|
|
|
|
'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host())
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
2016-12-20 23:05:20 +00:00
|
|
|
def form_valid(self, form):
|
2017-01-05 01:31:53 +00:00
|
|
|
|
|
|
|
context = {
|
|
|
|
'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host())
|
|
|
|
}
|
|
|
|
|
|
|
|
email_data = {
|
|
|
|
'subject': 'DatacenterLight Beta Access Request',
|
|
|
|
'to': form.cleaned_data.get('email'),
|
|
|
|
'context': context,
|
|
|
|
'template_name': 'request_access_confirmation',
|
|
|
|
'template_path': 'datacenterlight/emails/'
|
|
|
|
}
|
|
|
|
email = BaseEmail(**email_data)
|
|
|
|
email.send()
|
|
|
|
|
|
|
|
context.update({
|
|
|
|
'email': form.cleaned_data.get('email')
|
|
|
|
})
|
|
|
|
|
|
|
|
email_data = {
|
|
|
|
'subject': 'DatacenterLight Beta Access Request',
|
|
|
|
'to': 'info@ungleich.ch',
|
|
|
|
'context': context,
|
|
|
|
'template_name': 'request_access_notification',
|
|
|
|
'template_path': 'datacenterlight/emails/'
|
|
|
|
}
|
|
|
|
email = BaseEmail(**email_data)
|
|
|
|
email.send()
|
|
|
|
|
2016-12-20 23:05:20 +00:00
|
|
|
messages.add_message(self.request, messages.SUCCESS, self.success_message)
|
|
|
|
return super(IndexView, self).form_valid(form)
|