Fixed PEP8 violations
This commit is contained in:
parent
e681b0d8c2
commit
a9c9f74aed
5 changed files with 63 additions and 63 deletions
|
@ -1,6 +1,7 @@
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from .views import IndexView, BetaProgramView, LandingProgramView, BetaAccessView, PricingView, SuccessView, PaymentOrderView, OrderConfirmationView
|
from .views import IndexView, BetaProgramView, LandingProgramView, \
|
||||||
|
BetaAccessView, PricingView, SuccessView, PaymentOrderView, OrderConfirmationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
|
|
@ -13,12 +13,11 @@ from django.core.exceptions import ValidationError
|
||||||
from django.views.decorators.cache import cache_control
|
from django.views.decorators.cache import cache_control
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from utils.forms import BillingAddressForm, UserBillingAddressForm
|
from utils.forms import BillingAddressForm, UserBillingAddressForm
|
||||||
from membership.models import StripeCustomer
|
from hosting.models import HostingOrder
|
||||||
from hosting.models import HostingOrder, HostingBill
|
|
||||||
from utils.stripe_utils import StripeUtils
|
from utils.stripe_utils import StripeUtils
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from membership.models import CustomUser, StripeCustomer
|
from membership.models import CustomUser, StripeCustomer
|
||||||
|
from oca.pool import WrongIdError
|
||||||
from opennebula_api.models import OpenNebulaManager
|
from opennebula_api.models import OpenNebulaManager
|
||||||
from opennebula_api.serializers import VirtualMachineTemplateSerializer, VirtualMachineSerializer
|
from opennebula_api.serializers import VirtualMachineTemplateSerializer, VirtualMachineSerializer
|
||||||
|
|
||||||
|
@ -33,11 +32,12 @@ class SuccessView(TemplateView):
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
if 'specs' not in request.session or 'user' not in request.session:
|
if 'specs' not in request.session or 'user' not in request.session:
|
||||||
return HttpResponseRedirect(reverse('datacenterlight:index'))
|
return HttpResponseRedirect(reverse('datacenterlight:index'))
|
||||||
else :
|
else:
|
||||||
del request.session['specs']
|
del request.session['specs']
|
||||||
del request.session['user']
|
del request.session['user']
|
||||||
return render(request, self.template_name)
|
return render(request, self.template_name)
|
||||||
|
|
||||||
|
|
||||||
class PricingView(TemplateView):
|
class PricingView(TemplateView):
|
||||||
template_name = "datacenterlight/pricing.html"
|
template_name = "datacenterlight/pricing.html"
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ class PricingView(TemplateView):
|
||||||
)
|
)
|
||||||
context = {
|
context = {
|
||||||
'error': 'connection'
|
'error': 'connection'
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, self.template_name, context)
|
return render(request, self.template_name, context)
|
||||||
|
|
||||||
|
@ -93,7 +93,6 @@ class BetaAccessView(FormView):
|
||||||
success_message = "Thank you, we will contact you as soon as possible"
|
success_message = "Thank you, we will contact you as soon as possible"
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host())
|
'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host())
|
||||||
}
|
}
|
||||||
|
@ -190,9 +189,9 @@ class IndexView(CreateView):
|
||||||
|
|
||||||
@cache_control(no_cache=True, must_revalidate=True, no_store=True)
|
@cache_control(no_cache=True, must_revalidate=True, no_store=True)
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
if 'specs' in request.session :
|
if 'specs' in request.session:
|
||||||
del request.session['specs']
|
del request.session['specs']
|
||||||
if 'user' in request.session :
|
if 'user' in request.session:
|
||||||
del request.session['user']
|
del request.session['user']
|
||||||
try:
|
try:
|
||||||
manager = OpenNebulaManager()
|
manager = OpenNebulaManager()
|
||||||
|
@ -207,7 +206,7 @@ class IndexView(CreateView):
|
||||||
)
|
)
|
||||||
context = {
|
context = {
|
||||||
'error': 'connection'
|
'error': 'connection'
|
||||||
}
|
}
|
||||||
return render(request, self.template_name, context)
|
return render(request, self.template_name, context)
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
|
@ -242,7 +241,7 @@ class IndexView(CreateView):
|
||||||
'disk_size': storage,
|
'disk_size': storage,
|
||||||
'price': price
|
'price': price
|
||||||
}
|
}
|
||||||
|
|
||||||
this_user = {
|
this_user = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'email': email
|
'email': email
|
||||||
|
@ -332,17 +331,16 @@ class PaymentOrderView(FormView):
|
||||||
final_price = specs.get('price')
|
final_price = specs.get('price')
|
||||||
token = form.cleaned_data.get('token')
|
token = form.cleaned_data.get('token')
|
||||||
try:
|
try:
|
||||||
custom_user = CustomUser.objects.get(email=user.get('email'))
|
CustomUser.objects.get(email=user.get('email'))
|
||||||
except CustomUser.DoesNotExist:
|
except CustomUser.DoesNotExist:
|
||||||
password = CustomUser.get_random_password()
|
password = CustomUser.get_random_password()
|
||||||
# Register the user, and do not send emails
|
# Register the user, and do not send emails
|
||||||
CustomUser.register(user.get('name'),
|
CustomUser.register(user.get('name'),
|
||||||
password,
|
password,
|
||||||
user.get('email'),
|
user.get('email'),
|
||||||
app='dcl',
|
app='dcl',
|
||||||
base_url=None, send_email=False)
|
base_url=None, send_email=False)
|
||||||
|
|
||||||
|
|
||||||
# Get or create stripe customer
|
# Get or create stripe customer
|
||||||
customer = StripeCustomer.get_or_create(email=user.get('email'),
|
customer = StripeCustomer.get_or_create(email=user.get('email'),
|
||||||
token=token)
|
token=token)
|
||||||
|
@ -368,21 +366,21 @@ class PaymentOrderView(FormView):
|
||||||
return render(request, self.template_name, context)
|
return render(request, self.template_name, context)
|
||||||
|
|
||||||
charge = charge_response.get('response_object')
|
charge = charge_response.get('response_object')
|
||||||
|
|
||||||
# Create OpenNebulaManager
|
# Create OpenNebulaManager
|
||||||
manager = OpenNebulaManager(email=settings.OPENNEBULA_USERNAME,
|
manager = OpenNebulaManager(email=settings.OPENNEBULA_USERNAME,
|
||||||
password=settings.OPENNEBULA_PASSWORD)
|
password=settings.OPENNEBULA_PASSWORD)
|
||||||
|
|
||||||
# Create a vm using logged user
|
# Create a vm using logged user
|
||||||
vm_id = manager.create_vm(
|
vm_id = manager.create_vm(
|
||||||
template_id=vm_template_id,
|
template_id=vm_template_id,
|
||||||
specs=specs,
|
specs=specs,
|
||||||
vm_name="{email}-{template_name}-{date}".format(
|
vm_name="{email}-{template_name}-{date}".format(
|
||||||
email=user.get('email'),
|
email=user.get('email'),
|
||||||
template_name=template.get('name'),
|
template_name=template.get('name'),
|
||||||
date=int(datetime.now().strftime("%s")))
|
date=int(datetime.now().strftime("%s")))
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create a Hosting Order
|
# Create a Hosting Order
|
||||||
order = HostingOrder.create(
|
order = HostingOrder.create(
|
||||||
price=final_price,
|
price=final_price,
|
||||||
|
@ -390,10 +388,11 @@ class PaymentOrderView(FormView):
|
||||||
customer=customer,
|
customer=customer,
|
||||||
billing_address=billing_address
|
billing_address=billing_address
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create a Hosting Bill
|
# Create a Hosting Bill
|
||||||
bill = HostingBill.create(
|
# not used
|
||||||
customer=customer, billing_address=billing_address)
|
# bill = HostingBill.create(
|
||||||
|
# customer=customer, billing_address=billing_address)
|
||||||
|
|
||||||
# Create Billing Address for User if he does not have one
|
# Create Billing Address for User if he does not have one
|
||||||
if not customer.user.billing_addresses.count():
|
if not customer.user.billing_addresses.count():
|
||||||
|
@ -410,9 +409,9 @@ class PaymentOrderView(FormView):
|
||||||
|
|
||||||
# If the Stripe payment was successed, set order status approved
|
# If the Stripe payment was successed, set order status approved
|
||||||
order.set_approved()
|
order.set_approved()
|
||||||
|
|
||||||
vm = VirtualMachineSerializer(manager.get_vm(vm_id)).data
|
vm = VirtualMachineSerializer(manager.get_vm(vm_id)).data
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'name': user.get('name'),
|
'name': user.get('name'),
|
||||||
'email': user.get('email'),
|
'email': user.get('email'),
|
||||||
|
@ -438,10 +437,12 @@ class PaymentOrderView(FormView):
|
||||||
else:
|
else:
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
|
||||||
|
|
||||||
class OrderConfirmationView(DetailView):
|
class OrderConfirmationView(DetailView):
|
||||||
template_name = "datacenterlight/order_detail.html"
|
template_name = "datacenterlight/order_detail.html"
|
||||||
context_object_name = "order"
|
context_object_name = "order"
|
||||||
model = HostingOrder
|
model = HostingOrder
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
# Get context
|
# Get context
|
||||||
context = super(DetailView, self).get_context_data(**kwargs)
|
context = super(DetailView, self).get_context_data(**kwargs)
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
from oca.pool import WrongNameError, WrongIdError
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.core.urlresolvers import reverse_lazy, reverse
|
from django.core.urlresolvers import reverse_lazy, reverse
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.views.generic import View, CreateView, FormView, ListView, DetailView,\
|
from django.views.generic import View, CreateView, FormView, ListView, DetailView, \
|
||||||
DeleteView, TemplateView, UpdateView
|
DeleteView, TemplateView, UpdateView
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
@ -15,9 +16,7 @@ from guardian.mixins import PermissionRequiredMixin
|
||||||
from stored_messages.settings import stored_messages_settings
|
from stored_messages.settings import stored_messages_settings
|
||||||
from stored_messages.models import Message
|
from stored_messages.models import Message
|
||||||
from stored_messages.api import mark_read
|
from stored_messages.api import mark_read
|
||||||
from django.utils.safestring import mark_safe>>>>>>> master
|
from django.utils.safestring import mark_safe
|
||||||
246
|
|
||||||
|
|
||||||
|
|
||||||
from membership.models import CustomUser, StripeCustomer
|
from membership.models import CustomUser, StripeCustomer
|
||||||
from utils.stripe_utils import StripeUtils
|
from utils.stripe_utils import StripeUtils
|
||||||
|
@ -29,13 +28,11 @@ from .forms import HostingUserSignupForm, HostingUserLoginForm, UserHostingKeyFo
|
||||||
from .mixins import ProcessVMSelectionMixin
|
from .mixins import ProcessVMSelectionMixin
|
||||||
|
|
||||||
from opennebula_api.models import OpenNebulaManager
|
from opennebula_api.models import OpenNebulaManager
|
||||||
from opennebula_api.serializers import VirtualMachineSerializer,\
|
from opennebula_api.serializers import VirtualMachineSerializer, \
|
||||||
VirtualMachineTemplateSerializer
|
VirtualMachineTemplateSerializer
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
from oca.pool import WrongNameError, WrongIdError
|
|
||||||
|
|
||||||
CONNECTION_ERROR = "Your VMs cannot be displayed at the moment due to a backend \
|
CONNECTION_ERROR = "Your VMs cannot be displayed at the moment due to a backend \
|
||||||
connection error. please try again in a few minutes."
|
connection error. please try again in a few minutes."
|
||||||
|
|
||||||
|
@ -140,7 +137,6 @@ class HostingPricingView(ProcessVMSelectionMixin, View):
|
||||||
'templates': templates,
|
'templates': templates,
|
||||||
'configuration_options': configuration_options,
|
'configuration_options': configuration_options,
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
@ -171,7 +167,6 @@ class IndexView(View):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
|
||||||
context = self.get_context_data()
|
context = self.get_context_data()
|
||||||
|
|
||||||
return render(request, self.template_name, context)
|
return render(request, self.template_name, context)
|
||||||
|
@ -209,15 +204,17 @@ class SignupValidateView(TemplateView):
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(SignupValidateView, self).get_context_data(**kwargs)
|
context = super(SignupValidateView, self).get_context_data(**kwargs)
|
||||||
login_url = '<a href="' + reverse('hosting:login') + '">' + str(_('login')) +'</a>'
|
login_url = '<a href="' + reverse('hosting:login') + '">' + str(_('login')) + '</a>'
|
||||||
home_url = '<a href="' + reverse('datacenterlight:index') + '">Data Center Light</a>'
|
home_url = '<a href="' + reverse('datacenterlight:index') + '">Data Center Light</a>'
|
||||||
message='{signup_success_message} {lurl}</a> \
|
message = '{signup_success_message} {lurl}</a> \
|
||||||
<br />{go_back} {hurl}.'.format(
|
<br />{go_back} {hurl}.'.format(
|
||||||
signup_success_message = _('Thank you for signing up. We have sent an email to you. Please follow the instructions in it to activate your account. Once activated, you can login using'),
|
signup_success_message=_(
|
||||||
go_back = _('Go back to'),
|
'Thank you for signing up. We have sent an email to you. '
|
||||||
lurl = login_url,
|
'Please follow the instructions in it to activate your account. Once activated, you can login using'),
|
||||||
hurl = home_url
|
go_back=_('Go back to'),
|
||||||
)
|
lurl=login_url,
|
||||||
|
hurl=home_url
|
||||||
|
)
|
||||||
context['message'] = mark_safe(message)
|
context['message'] = mark_safe(message)
|
||||||
context['section_title'] = _('Sign up')
|
context['section_title'] = _('Sign up')
|
||||||
return context
|
return context
|
||||||
|
@ -229,20 +226,20 @@ class SignupValidatedView(SignupValidateView):
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(SignupValidateView, self).get_context_data(**kwargs)
|
context = super(SignupValidateView, self).get_context_data(**kwargs)
|
||||||
validated = CustomUser.validate_url(self.kwargs['validate_slug'])
|
validated = CustomUser.validate_url(self.kwargs['validate_slug'])
|
||||||
login_url = '<a href="' + reverse('hosting:login') + '">' + str(_('login')) +'</a>'
|
login_url = '<a href="' + reverse('hosting:login') + '">' + str(_('login')) + '</a>'
|
||||||
section_title=_('Account activation')
|
section_title = _('Account activation')
|
||||||
if validated:
|
if validated:
|
||||||
message='{account_activation_string} <br /> {login_string} {lurl}.'.format(
|
message = '{account_activation_string} <br /> {login_string} {lurl}.'.format(
|
||||||
account_activation_string = _("Your account has been activated."),
|
account_activation_string=_("Your account has been activated."),
|
||||||
login_string = _("You can now"),
|
login_string=_("You can now"),
|
||||||
lurl = login_url)
|
lurl=login_url)
|
||||||
else:
|
else:
|
||||||
home_url = '<a href="' + reverse('datacenterlight:index') + '">Data Center Light</a>'
|
home_url = '<a href="' + reverse('datacenterlight:index') + '">Data Center Light</a>'
|
||||||
message = '{sorry_message} <br />{go_back_to} {hurl}'.format(
|
message = '{sorry_message} <br />{go_back_to} {hurl}'.format(
|
||||||
sorry_message = _("Sorry. Your request is invalid."),
|
sorry_message=_("Sorry. Your request is invalid."),
|
||||||
go_back_to = _('Go back to'),
|
go_back_to=_('Go back to'),
|
||||||
hurl = home_url
|
hurl=home_url
|
||||||
)
|
)
|
||||||
context['message'] = mark_safe(message)
|
context['message'] = mark_safe(message)
|
||||||
context['section_title'] = section_title
|
context['section_title'] = section_title
|
||||||
return context
|
return context
|
||||||
|
@ -545,7 +542,7 @@ class PaymentVMView(LoginRequiredMixin, FormView):
|
||||||
return render(request, self.template_name, context)
|
return render(request, self.template_name, context)
|
||||||
# For now just get first one
|
# For now just get first one
|
||||||
user_key = UserHostingKey.objects.filter(
|
user_key = UserHostingKey.objects.filter(
|
||||||
user=self.request.user).first()
|
user=self.request.user).first()
|
||||||
|
|
||||||
# Create a vm using logged user
|
# Create a vm using logged user
|
||||||
vm_id = manager.create_vm(
|
vm_id = manager.create_vm(
|
||||||
|
|
|
@ -85,7 +85,8 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||||
dg.send_mail(to=user.email)
|
dg.send_mail(to=user.email)
|
||||||
elif app == 'dcl':
|
elif app == 'dcl':
|
||||||
dcl_text = settings.DCL_TEXT
|
dcl_text = settings.DCL_TEXT
|
||||||
dcl_from_address = settings.DCL_SUPPORT_FROM_ADDRESS
|
# not used
|
||||||
|
# dcl_from_address = settings.DCL_SUPPORT_FROM_ADDRESS
|
||||||
user.is_active = False
|
user.is_active = False
|
||||||
|
|
||||||
if send_email is True:
|
if send_email is True:
|
||||||
|
@ -93,9 +94,10 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||||
'subject': str(_('Activate your ')) + dcl_text + str(_(' account')),
|
'subject': str(_('Activate your ')) + dcl_text + str(_(' account')),
|
||||||
'from_address': settings.DCL_SUPPORT_FROM_ADDRESS,
|
'from_address': settings.DCL_SUPPORT_FROM_ADDRESS,
|
||||||
'to': user.email,
|
'to': user.email,
|
||||||
'context': {'base_url' : base_url,
|
'context': {'base_url': base_url,
|
||||||
'activation_link' : reverse('hosting:validate', kwargs={'validate_slug': user.validation_slug}),
|
'activation_link': reverse('hosting:validate',
|
||||||
'dcl_text' : dcl_text
|
kwargs={'validate_slug': user.validation_slug}),
|
||||||
|
'dcl_text': dcl_text
|
||||||
},
|
},
|
||||||
'template_name': 'user_activation',
|
'template_name': 'user_activation',
|
||||||
'template_path': 'datacenterlight/emails/'
|
'template_path': 'datacenterlight/emails/'
|
||||||
|
@ -189,7 +191,7 @@ class StripeCustomer(models.Model):
|
||||||
if stripe_data.get('response_object'):
|
if stripe_data.get('response_object'):
|
||||||
stripe_cus_id = stripe_data.get('response_object').get('id')
|
stripe_cus_id = stripe_data.get('response_object').get('id')
|
||||||
|
|
||||||
stripe_customer = StripeCustomer.objects.\
|
stripe_customer = StripeCustomer.objects. \
|
||||||
create(user=user, stripe_id=stripe_cus_id)
|
create(user=user, stripe_id=stripe_cus_id)
|
||||||
|
|
||||||
return stripe_customer
|
return stripe_customer
|
||||||
|
|
|
@ -208,7 +208,7 @@ class OpenNebulaManager():
|
||||||
except:
|
except:
|
||||||
raise ConnectionRefusedError
|
raise ConnectionRefusedError
|
||||||
|
|
||||||
def create_vm(self, template_id, specs, ssh_key=None):
|
def create_vm(self, template_id, specs, ssh_key=None, vm_name=None):
|
||||||
|
|
||||||
template = self.get_template(template_id)
|
template = self.get_template(template_id)
|
||||||
vm_specs_formatter = """<TEMPLATE>
|
vm_specs_formatter = """<TEMPLATE>
|
||||||
|
@ -256,7 +256,6 @@ class OpenNebulaManager():
|
||||||
image=image,
|
image=image,
|
||||||
image_uname=image_uname)
|
image_uname=image_uname)
|
||||||
|
|
||||||
|
|
||||||
vm_specs += "<CONTEXT>"
|
vm_specs += "<CONTEXT>"
|
||||||
if ssh_key:
|
if ssh_key:
|
||||||
vm_specs += "<SSH_PUBLIC_KEY>{ssh}</SSH_PUBLIC_KEY>".format(ssh=ssh_key)
|
vm_specs += "<SSH_PUBLIC_KEY>{ssh}</SSH_PUBLIC_KEY>".format(ssh=ssh_key)
|
||||||
|
@ -276,7 +275,7 @@ class OpenNebulaManager():
|
||||||
'release',
|
'release',
|
||||||
vm_id
|
vm_id
|
||||||
)
|
)
|
||||||
|
|
||||||
if vm_name is not None:
|
if vm_name is not None:
|
||||||
self.oneadmin_client.call(
|
self.oneadmin_client.call(
|
||||||
'vm.rename',
|
'vm.rename',
|
||||||
|
|
Loading…
Reference in a new issue