Added Flake8 lib and fixed PEP8 violations

This commit is contained in:
Siarhei Puhach 2017-06-29 17:34:40 +03:00
commit edcfd3e9f4
65 changed files with 340 additions and 387 deletions

View file

@ -1,5 +1,3 @@
from collections import namedtuple
from django.shortcuts import render
from django.http import Http404
from django.core.urlresolvers import reverse_lazy, reverse
@ -7,7 +5,6 @@ from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import View, CreateView, FormView, ListView, DetailView,\
DeleteView, TemplateView, UpdateView
from django.http import HttpResponseRedirect
from django.contrib.auth import authenticate, login
from django.contrib import messages
from django.conf import settings
from django.shortcuts import redirect
@ -35,7 +32,6 @@ from opennebula_api.serializers import VirtualMachineSerializer,\
from django.utils.translation import ugettext_lazy as _
from oca.exceptions import OpenNebulaException
from oca.pool import WrongNameError, WrongIdError
CONNECTION_ERROR = "Your VMs cannot be displayed at the moment due to a backend \
@ -205,31 +201,35 @@ class SignupView(CreateView):
return HttpResponseRedirect(reverse_lazy('hosting:signup-validate'))
class SignupValidateView(TemplateView):
template_name = "hosting/signup_validate.html"
def get_context_data(self, **kwargs):
context = super(SignupValidateView, self).get_context_data(**kwargs)
login_url = reverse('hosting:login')
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 ") + '<a href="' + login_url +'">login</a>'
section_title='Sign up'
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 ") + '<a href="' + login_url + '">login</a>'
section_title = 'Sign up'
context['message'] = mark_safe(message)
context['section_title'] = section_title
return context
class SignupValidatedView(SignupValidateView):
template_name = "hosting/signup_validate.html"
def get_context_data(self, **kwargs):
context = super(SignupValidateView, self).get_context_data(**kwargs)
validated = CustomUser.validate_url(self.kwargs['validate_slug'])
login_url = reverse('hosting:login')
if validated:
message= _("Your account has been activated. You can now ") + '<a href="' + login_url +'">login</a>'
section_title=_('Account activation')
message = _("Your account has been activated. You can now ") + '<a href="' + login_url + '">login</a>'
section_title = _('Account activation')
else:
message= _("Sorry. Your request is invalid.") + '<a href="' + login_url +'">login</a>'
section_title=_('Account activation')
message = _("Sorry. Your request is invalid.") + '<a href="' + login_url + '">login</a>'
section_title = _('Account activation')
context['message'] = mark_safe(message)
context['section_title'] = section_title
return context
@ -338,6 +338,7 @@ class SSHKeyDeleteView(LoginRequiredMixin, DeleteView):
return super(SSHKeyDeleteView, self).delete(request, *args, **kwargs)
class SSHKeyListView(LoginRequiredMixin, ListView):
template_name = "hosting/user_keys.html"
login_url = reverse_lazy('hosting:login')
@ -346,7 +347,6 @@ class SSHKeyListView(LoginRequiredMixin, ListView):
paginate_by = 10
ordering = '-id'
def get_queryset(self):
user = self.request.user
self.queryset = UserHostingKey.objects.filter(user=user)
@ -366,7 +366,6 @@ class SSHKeyCreateView(LoginRequiredMixin, FormView):
context_object_name = "virtual_machine"
success_url = reverse_lazy('hosting:ssh_keys')
def get_form_kwargs(self):
kwargs = super(SSHKeyCreateView, self).get_form_kwargs()
kwargs.update({'request': self.request})
@ -463,7 +462,7 @@ class PaymentVMView(LoginRequiredMixin, FormView):
return context
def get(self, request, *args, **kwargs):
if not UserHostingKey.objects.filter( user=self.request.user).exists():
if not UserHostingKey.objects.filter(user=self.request.user).exists():
messages.success(
request,
'In order to create a VM, you create/upload your SSH KEY first.'
@ -525,7 +524,7 @@ class PaymentVMView(LoginRequiredMixin, FormView):
manager = OpenNebulaManager(email=owner.email,
password=owner.password)
# Get user ssh key
if not UserHostingKey.objects.filter( user=self.request.user).exists():
if not UserHostingKey.objects.filter(user=self.request.user).exists():
context.update({
'sshError': 'error',
'form': form
@ -534,7 +533,7 @@ class PaymentVMView(LoginRequiredMixin, FormView):
# For now just get first one
user_key = UserHostingKey.objects.filter(
user=self.request.user).first()
# Create a vm using logged user
vm_id = manager.create_vm(
template_id=vm_template_id,
@ -552,8 +551,9 @@ class PaymentVMView(LoginRequiredMixin, FormView):
)
# Create a Hosting Bill
bill = HostingBill.create(
customer=customer, billing_address=billing_address)
# variable bill is not used
# bill = HostingBill.create(
# customer=customer, billing_address=billing_address)
# Create Billing Address for User if he does not have one
if not customer.user.billing_addresses.count():
@ -686,7 +686,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
def get(self, request, *args, **kwargs):
if not UserHostingKey.objects.filter( user=self.request.user).exists():
if not UserHostingKey.objects.filter(user=self.request.user).exists():
messages.success(
request,
'In order to create a VM, you need to create/upload your SSH KEY first.'
@ -710,7 +710,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
)
context = {
'error': 'connection'
}
}
return render(request, self.template_name, context)