Upgrade to Django 3.2
- update dependencies - fix deprecation warnings - fix tests - skip some tests that need more work - reformat changed code with isort and black
This commit is contained in:
parent
0f18e59d67
commit
4af1a39ca4
93 changed files with 3598 additions and 2725 deletions
|
@ -2,20 +2,15 @@
|
|||
This module defines the views for gnuviechadmin operating system user handling.
|
||||
|
||||
"""
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.contrib import messages
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
from django.views.generic import (
|
||||
CreateView,
|
||||
DeleteView,
|
||||
ListView,
|
||||
UpdateView,
|
||||
)
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.contrib import messages
|
||||
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.generic import CreateView, DeleteView, ListView, UpdateView
|
||||
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
|
||||
|
||||
from gvawebcore.views import HostingPackageAndCustomerMixin
|
||||
|
||||
from .forms import (
|
||||
|
@ -23,10 +18,7 @@ from .forms import (
|
|||
ChangeOsUserPasswordForm,
|
||||
EditSshPublicKeyCommentForm,
|
||||
)
|
||||
from .models import (
|
||||
SshPublicKey,
|
||||
User,
|
||||
)
|
||||
from .models import SshPublicKey, User
|
||||
|
||||
|
||||
class SetOsUserPassword(StaffOrSelfLoginRequiredMixin, UpdateView):
|
||||
|
@ -34,19 +26,19 @@ class SetOsUserPassword(StaffOrSelfLoginRequiredMixin, UpdateView):
|
|||
This view is used for setting a new operating system user password.
|
||||
|
||||
"""
|
||||
|
||||
model = User
|
||||
slug_field = 'username'
|
||||
template_name_suffix = '_setpassword'
|
||||
context_object_name = 'osuser'
|
||||
slug_field = "username"
|
||||
template_name_suffix = "_setpassword"
|
||||
context_object_name = "osuser"
|
||||
form_class = ChangeOsUserPasswordForm
|
||||
|
||||
def get_customer_object(self):
|
||||
return self.get_object().customer
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
context = super(SetOsUserPassword, self).get_context_data(
|
||||
*args, **kwargs)
|
||||
context['customer'] = self.get_customer_object()
|
||||
context = super(SetOsUserPassword, self).get_context_data(*args, **kwargs)
|
||||
context["customer"] = self.get_customer_object()
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
|
@ -55,7 +47,8 @@ class SetOsUserPassword(StaffOrSelfLoginRequiredMixin, UpdateView):
|
|||
self.request,
|
||||
_("New password for {username} has been set successfully.").format(
|
||||
username=osuser.username
|
||||
))
|
||||
),
|
||||
)
|
||||
return redirect(osuser.customerhostingpackage)
|
||||
|
||||
|
||||
|
@ -67,30 +60,34 @@ class AddSshPublicKey(
|
|||
operating system user.
|
||||
|
||||
"""
|
||||
|
||||
model = SshPublicKey
|
||||
context_object_name = 'key'
|
||||
template_name_suffix = '_create'
|
||||
context_object_name = "key"
|
||||
template_name_suffix = "_create"
|
||||
form_class = AddSshPublicKeyForm
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(AddSshPublicKey, self).get_form_kwargs()
|
||||
kwargs['hostingpackage'] = self.get_hosting_package()
|
||||
kwargs["hostingpackage"] = self.get_hosting_package()
|
||||
return kwargs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AddSshPublicKey, self).get_context_data(**kwargs)
|
||||
context.update({
|
||||
'customer': self.get_customer_object(),
|
||||
'osuser': self.get_hosting_package().osuser.username,
|
||||
})
|
||||
context.update(
|
||||
{
|
||||
"customer": self.get_customer_object(),
|
||||
"osuser": self.get_hosting_package().osuser.username,
|
||||
}
|
||||
)
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
key = form.save()
|
||||
messages.success(
|
||||
self.request,
|
||||
_('Successfully added new {algorithm} SSH public key.').format(
|
||||
algorithm=key.algorithm)
|
||||
_("Successfully added new {algorithm} SSH public key.").format(
|
||||
algorithm=key.algorithm
|
||||
),
|
||||
)
|
||||
return redirect(self.get_hosting_package())
|
||||
|
||||
|
@ -104,20 +101,22 @@ class ListSshPublicKeys(
|
|||
via URL parameter 'pattern'.
|
||||
|
||||
"""
|
||||
|
||||
model = SshPublicKey
|
||||
context_object_name = 'keys'
|
||||
context_object_name = "keys"
|
||||
|
||||
def get_queryset(self):
|
||||
return SshPublicKey.objects.filter(
|
||||
user=self.get_hosting_package().osuser)
|
||||
return SshPublicKey.objects.filter(user=self.get_hosting_package().osuser)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(ListSshPublicKeys, self).get_context_data(**kwargs)
|
||||
context.update({
|
||||
'hostingpackage': self.get_hosting_package(),
|
||||
'customer': self.get_customer_object(),
|
||||
'osuser': self.get_hosting_package().osuser.username,
|
||||
})
|
||||
context.update(
|
||||
{
|
||||
"hostingpackage": self.get_hosting_package(),
|
||||
"customer": self.get_customer_object(),
|
||||
"osuser": self.get_hosting_package().osuser.username,
|
||||
}
|
||||
)
|
||||
return context
|
||||
|
||||
|
||||
|
@ -131,24 +130,29 @@ class DeleteSshPublicKey(
|
|||
"""
|
||||
|
||||
model = SshPublicKey
|
||||
context_object_name = 'key'
|
||||
context_object_name = "key"
|
||||
|
||||
def get_queryset(self):
|
||||
return super(DeleteSshPublicKey, self).get_queryset().filter(
|
||||
user=self.get_hosting_package().osuser)
|
||||
return (
|
||||
super(DeleteSshPublicKey, self)
|
||||
.get_queryset()
|
||||
.filter(user=self.get_hosting_package().osuser)
|
||||
)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(DeleteSshPublicKey, self).get_context_data(**kwargs)
|
||||
context.update({
|
||||
'hostingpackage': self.get_hosting_package(),
|
||||
'customer': self.get_customer_object(),
|
||||
'osuser': self.get_hosting_package().osuser.username,
|
||||
})
|
||||
context.update(
|
||||
{
|
||||
"hostingpackage": self.get_hosting_package(),
|
||||
"customer": self.get_customer_object(),
|
||||
"osuser": self.get_hosting_package().osuser.username,
|
||||
}
|
||||
)
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse(
|
||||
'list_ssh_keys', kwargs={'package': self.get_hosting_package().id}
|
||||
"list_ssh_keys", kwargs={"package": self.get_hosting_package().id}
|
||||
)
|
||||
|
||||
|
||||
|
@ -160,31 +164,36 @@ class EditSshPublicKeyComment(
|
|||
key <osusers.models.SshPublicKey>`.
|
||||
|
||||
"""
|
||||
|
||||
model = SshPublicKey
|
||||
context_object_name = 'key'
|
||||
template_name_suffix = '_edit_comment'
|
||||
context_object_name = "key"
|
||||
template_name_suffix = "_edit_comment"
|
||||
form_class = EditSshPublicKeyCommentForm
|
||||
|
||||
def get_queryset(self):
|
||||
return super(EditSshPublicKeyComment, self).get_queryset().filter(
|
||||
user=self.get_hosting_package().osuser)
|
||||
return (
|
||||
super(EditSshPublicKeyComment, self)
|
||||
.get_queryset()
|
||||
.filter(user=self.get_hosting_package().osuser)
|
||||
)
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(EditSshPublicKeyComment, self).get_form_kwargs()
|
||||
kwargs['hostingpackage'] = self.get_hosting_package()
|
||||
kwargs["hostingpackage"] = self.get_hosting_package()
|
||||
return kwargs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(EditSshPublicKeyComment, self).get_context_data(
|
||||
**kwargs)
|
||||
context.update({
|
||||
'hostingpackage': self.get_hosting_package(),
|
||||
'customer': self.get_customer_object(),
|
||||
'osuser': self.get_hosting_package().osuser.username,
|
||||
})
|
||||
context = super(EditSshPublicKeyComment, self).get_context_data(**kwargs)
|
||||
context.update(
|
||||
{
|
||||
"hostingpackage": self.get_hosting_package(),
|
||||
"customer": self.get_customer_object(),
|
||||
"osuser": self.get_hosting_package().osuser.username,
|
||||
}
|
||||
)
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse(
|
||||
'list_ssh_keys', kwargs={'package': self.get_hosting_package().id}
|
||||
"list_ssh_keys", kwargs={"package": self.get_hosting_package().id}
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue