gva/gnuviechadmin/osusers/views.py

46 lines
1.3 KiB
Python
Raw Normal View History

"""
This module defines the views for gnuviechadmin operating system user handling.
"""
from __future__ import unicode_literals, absolute_import
from django.shortcuts import redirect
from django.views.generic import UpdateView
from django.utils.translation import ugettext as _
from django.contrib import messages
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
from .forms import ChangeOsUserPasswordForm
from .models import User
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'
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()
return context
def form_valid(self, form):
osuser = form.save()
messages.success(
self.request,
_("New password for {username} has been set successfully.").format(
username=osuser.username
))
return redirect(osuser.customerhostingpackage)