From 63a502ba62f9252dda5c97a9c3e47e8bbcef61fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AB=E5=8D=83=E6=B5=81?= <40739051+jym503558564@users.noreply.github.com> Date: Thu, 11 Jul 2019 18:54:30 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E5=88=9B=E5=BB=BA/=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20=E7=94=A8=E6=88=B7=20=E4=BD=BF=E7=94=A8api=20(#2918?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Update] 创建/更新 用户 使用api * [Update] 修改小问题 * [Update] 修改小问题 --- apps/users/serializers/v1.py | 14 ++- apps/users/templates/users/user_create.html | 30 +++-- apps/users/templates/users/user_update.html | 118 +++++++++++--------- 3 files changed, 100 insertions(+), 62 deletions(-) diff --git a/apps/users/serializers/v1.py b/apps/users/serializers/v1.py index 63fe52699..864618823 100644 --- a/apps/users/serializers/v1.py +++ b/apps/users/serializers/v1.py @@ -36,7 +36,7 @@ class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer): 'date_password_last_updated', 'date_expired', 'avatar_url', ] extra_kwargs = { - 'password': {'write_only': True, 'required': False}, + 'password': {'write_only': True, 'required': False, 'allow_null': True, 'allow_blank': True}, 'public_key': {'write_only': True}, 'groups_display': {'label': _('Groups name')}, 'source_display': {'label': _('Source name')}, @@ -56,13 +56,17 @@ class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer): raise serializers.ValidationError(msg) return value - @staticmethod - def validate_password(value): + def validate_password(self, password): from ..utils import check_password_rules - if not check_password_rules(value): + password_strategy = self.initial_data.get('password_strategy') + if password_strategy == '0': + return + if password_strategy is None and not password: + return + if not check_password_rules(password): msg = _('Password does not match security rules') raise serializers.ValidationError(msg) - return value + return password @staticmethod def change_password_to_raw(validated_data): diff --git a/apps/users/templates/users/user_create.html b/apps/users/templates/users/user_create.html index 13bb26cbc..5e15b5469 100644 --- a/apps/users/templates/users/user_create.html +++ b/apps/users/templates/users/user_create.html @@ -4,9 +4,7 @@ {% block user_template_title %}{% trans "Create user" %}{% endblock %} {% block password %} {% bootstrap_field form.password_strategy layout="horizontal" %} -
- {% bootstrap_field form.password layout="horizontal" %} -
+ {% bootstrap_field form.password layout="horizontal" %} {# 密码popover #}