Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
2c4966c6
Commit
2c4966c6
authored
Sep 03, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改form
parent
d1390a1c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
33 deletions
+21
-33
fields.py
apps/common/fields.py
+6
-1
forms.py
apps/common/forms.py
+15
-32
No files found.
apps/common/fields.py
View file @
2c4966c6
...
...
@@ -13,7 +13,7 @@ from .utils import get_signer
signer
=
get_signer
()
class
DictField
(
forms
.
Field
):
class
Form
DictField
(
forms
.
Field
):
widget
=
forms
.
Textarea
def
to_python
(
self
,
value
):
...
...
@@ -23,6 +23,7 @@ class DictField(forms.Field):
# RadioSelect will provide. Because bool("True") == bool('1') == True,
# we don't need to handle that explicitly.
if
isinstance
(
value
,
six
.
string_types
):
value
=
value
.
replace
(
"'"
,
'"'
)
try
:
value
=
json
.
loads
(
value
)
return
value
...
...
@@ -81,3 +82,7 @@ class FormEncryptMixin:
class
FormEncryptCharField
(
FormEncryptMixin
,
forms
.
CharField
):
pass
class
FormEncryptDictField
(
FormEncryptMixin
,
FormDictField
):
pass
apps/common/forms.py
View file @
2c4966c6
# -*- coding: utf-8 -*-
#
import
json
from
django
import
forms
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.db
import
transaction
from
django.conf
import
settings
from
.models
import
Setting
,
common_settings
from
.fields
import
DictField
,
FormEncryptCharField
,
FormEncryptMixin
# def to_model_value(value):
# try:
# return json.dumps(value)
# except json.JSONDecodeError:
# return None
#
#
# def to_form_value(value):
# try:
# data = json.loads(value)
# if isinstance(data, dict):
# data = value
# return data
# except json.JSONDecodeError:
# return ""
from
.fields
import
FormDictField
,
FormEncryptCharField
,
\
FormEncryptMixin
,
FormEncryptDictField
class
BaseForm
(
forms
.
Form
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
()
.
__init__
(
*
args
,
**
kwargs
)
# db_settings = Setting.objects.all()
for
name
,
field
in
self
.
fields
.
items
():
db_value
=
getattr
(
common_settings
,
name
)
django_value
=
getattr
(
settings
,
name
)
if
hasattr
(
settings
,
name
)
else
None
if
db_value
is
False
or
db_value
:
field
.
initial
=
db_value
if
isinstance
(
db_value
,
dict
):
db_value
=
json
.
dumps
(
db_value
)
initial_value
=
db_value
elif
django_value
is
False
or
django_value
:
field
.
initial
=
django_value
initial_value
=
django_value
else
:
initial_value
=
''
field
.
initial
=
initial_value
def
save
(
self
,
category
=
"default"
):
if
not
self
.
is_bound
:
...
...
@@ -67,7 +54,6 @@ class BaseForm(forms.Form):
setting
.
encrypted
=
encrypted
setting
.
cleaned_value
=
value
setting
.
save
()
return
setting
class
BasicSettingForm
(
BaseForm
):
...
...
@@ -126,15 +112,12 @@ class LDAPSettingForm(BaseForm):
label
=
_
(
"User search filter"
),
initial
=
'(cn=
%(user)
s)'
,
help_text
=
_
(
"Choice may be (cn|uid|sAMAccountName)=
%(user)
s)"
)
)
AUTH_LDAP_USER_ATTR_MAP
=
DictField
(
AUTH_LDAP_USER_ATTR_MAP
=
Form
DictField
(
label
=
_
(
"User attr map"
),
initial
=
json
.
dumps
({
"username"
:
"cn"
,
"name"
:
"sn"
,
"email"
:
"mail"
}),
help_text
=
_
(
"User attr map present how to map LDAP user attr to jumpserver, username,name,email is jumpserver attr"
)
"User attr map present how to map LDAP user attr to jumpserver, "
"username,name,email is jumpserver attr"
)
)
# AUTH_LDAP_GROUP_SEARCH_OU = CONFIG.AUTH_LDAP_GROUP_SEARCH_OU
# AUTH_LDAP_GROUP_SEARCH_FILTER = CONFIG.AUTH_LDAP_GROUP_SEARCH_FILTER
...
...
@@ -161,13 +144,13 @@ class TerminalSettingForm(BaseForm):
TERMINAL_PUBLIC_KEY_AUTH
=
forms
.
BooleanField
(
initial
=
True
,
required
=
False
,
label
=
_
(
"Public key auth"
)
)
TERMINAL_COMMAND_STORAGE
=
DictField
(
TERMINAL_COMMAND_STORAGE
=
FormEncrypt
DictField
(
label
=
_
(
"Command storage"
),
help_text
=
_
(
"Set terminal storage setting, `default` is the using as default,"
"You can set other storage and some terminal using"
)
)
TERMINAL_REPLAY_STORAGE
=
DictField
(
TERMINAL_REPLAY_STORAGE
=
FormEncrypt
DictField
(
label
=
_
(
"Replay storage"
),
help_text
=
_
(
"Set replay storage setting, `default` is the using as default,"
"You can set other storage and some terminal using"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment