From 037d9323a46b2405b6e374a6908de884766444c6 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 15 Sep 2016 11:19:36 +0800 Subject: [PATCH] Modify and code review --- apps/assets/static/assets/example.png | 0 apps/common/utils.py | 3 +++ apps/users/models.py | 5 ++--- apps/users/views.py | 15 ++++++++++----- 4 files changed, 15 insertions(+), 8 deletions(-) delete mode 100644 apps/assets/static/assets/example.png diff --git a/apps/assets/static/assets/example.png b/apps/assets/static/assets/example.png deleted file mode 100644 index e69de29bb..000000000 diff --git a/apps/common/utils.py b/apps/common/utils.py index d2437537b..d44167ce3 100644 --- a/apps/common/utils.py +++ b/apps/common/utils.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals from six import string_types from itertools import chain import string +import logging from django.shortcuts import reverse as dj_reverse from django.conf import settings @@ -97,3 +98,5 @@ def search_object_attr(obj, value='', attr_list=None, ignore_case=False): return False +def get_logger(name=None): + return logging.getLogger('jumpserver.%s' % name) diff --git a/apps/users/models.py b/apps/users/models.py index 516c9dd20..0b27009ca 100644 --- a/apps/users/models.py +++ b/apps/users/models.py @@ -11,7 +11,6 @@ from django.db.models.signals import post_save from django.dispatch import receiver from django.utils import timezone from django.utils.translation import ugettext_lazy as _ - from rest_framework.authtoken.models import Token from common.utils import encrypt, decrypt, date_expired_default @@ -240,13 +239,13 @@ class User(AbstractUser): def init_all_models(): for model in (UserGroup, User): - if hasattr(model, 'initial'): + if hasattr(model, b'initial'): model.initial() def generate_fake(): for model in (UserGroup, User): - if hasattr(model, 'generate_fake'): + if hasattr(model, b'generate_fake'): model.generate_fake() diff --git a/apps/users/views.py b/apps/users/views.py index 18a9061c5..c752bc2eb 100644 --- a/apps/users/views.py +++ b/apps/users/views.py @@ -10,7 +10,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.messages.views import SuccessMessageMixin from django.core.files.storage import default_storage from django.db.models import Q -from django.http import HttpResponseRedirect,HttpResponse +from django.http import HttpResponseRedirect from django.shortcuts import get_object_or_404, reverse, redirect from django.utils.decorators import method_decorator from django.utils.translation import ugettext as _ @@ -25,14 +25,14 @@ from django.views.generic.detail import DetailView from formtools.wizard.views import SessionWizardView -from common.utils import get_object_or_none +from common.utils import get_object_or_none, get_logger from .models import User, UserGroup -from .forms import (UserCreateForm, UserUpdateForm, UserGroupForm, UserLoginForm, UserInfoForm, UserKeyForm) +from .forms import UserCreateForm, UserUpdateForm, UserGroupForm, UserLoginForm, UserInfoForm, UserKeyForm from .utils import AdminUserRequiredMixin, user_add_success_next, send_reset_password_mail -logger = logging.getLogger('jumpserver.users.views') +logger = get_logger(__name__) @method_decorator(sensitive_post_parameters(), name='dispatch') @@ -52,6 +52,10 @@ class UserLoginView(FormView): auth_login(self.request, form.get_user()) return redirect(self.get_success_url()) + def form_invalid(self, form): + logger.debug(form.errors) + return super(UserLoginView, self).form_invalid(form) + def get_success_url(self): if self.request.user.is_first_login: return reverse('users:user-first-login') @@ -176,6 +180,7 @@ class UserDeleteView(AdminUserRequiredMixin, DeleteView): return HttpResponseRedirect(success_url) + class UserDetailView(AdminUserRequiredMixin, DetailView): model = User template_name = 'users/user_detail.html' @@ -249,7 +254,7 @@ class UserGroupDeleteView(DeleteView): class UserForgotPasswordView(TemplateView): template_name = 'users/forgot_password.html' - def post(self, request, *args, **kwargs): + def post(self, request): email = request.POST.get('email') user = get_object_or_none(User, email=email) if not user: