Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
plugin_dbui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
w2pext
plugin_dbui
Commits
e3754609
Commit
e3754609
authored
13 years ago
by
tux091
Browse files
Options
Downloads
Patches
Plain Diff
Add a mechanism to transport database validator on the client side.
parent
bb97c65f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/plugin_dbui/cfgsvc.py
+62
-6
62 additions, 6 deletions
modules/plugin_dbui/cfgsvc.py
static/plugin_dbui/CHANGELOG
+3
-1
3 additions, 1 deletion
static/plugin_dbui/CHANGELOG
with
65 additions
and
7 deletions
modules/plugin_dbui/cfgsvc.py
+
62
−
6
View file @
e3754609
"""
$Id$
"""
Service to determine ExtJS widget configuration parameters
from the web2py model.
Author: R. Le Gac
"""
from
reportlab.lib.yaml
import
BaseParser
__version__
=
"
$Revision$
"
from
basesvc
import
BaseSvc
from
foreignfield
import
ForeignField
from
gluon.validators
import
(
IS_DATE_IN_RANGE
,
IS_DATETIME_IN_RANGE
,
IS_DECIMAL_IN_RANGE
,
IS_FLOAT_IN_RANGE
,
IS_INT_IN_RANGE
,
IS_MATCH
,
IS_LENGTH
)
from
helper
import
encode_field
from
mapper
import
map_default
from
modifier
import
Widget
...
...
@@ -20,7 +29,8 @@ FIELD_IN_DBFIELD = "Field %s already in the dbFields list."
FTYPE_TO_XTYPE
=
{
'
boolean
'
:
{
'
xtype
'
:
'
checkbox
'
},
\
'
date
'
:
{
'
xtype
'
:
'
datefield
'
,
'
format
'
:
'
Y-m-d
'
},
\
'
datetime
'
:
{
'
xtype
'
:
'
datefield
'
,
'
format
'
:
'
Y-m-d H:i:s
'
},
\
'
double
'
:
{
'
xtype
'
:
'
numberfield
'
},
\
'
double
'
:
{
'
xtype
'
:
'
numberfield
'
,
'
decimalPrecision
'
:
2
,
'
decimalSeparator
'
:
'
.
'
},
\
'
id
'
:
{
'
xtype
'
:
'
textfield
'
},
\
'
integer
'
:
{
'
xtype
'
:
'
numberfield
'
},
\
'
password
'
:
{
'
xtype
'
:
'
textfield
'
,
'
inputType
'
:
'
password
'
},
\
...
...
@@ -38,8 +48,6 @@ SUCCESS= 'success'
TOTAL
=
'
count
'
class
CfgSvc
(
BaseSvc
):
"""
The configuration service which build the configuration options
for the ExtJS widget.
...
...
@@ -248,7 +256,10 @@ class CfgSvc(BaseSvc):
# tool tip
if
field
.
comment
:
cfg
[
"
tipText
"
]
=
field
.
comment
# validators
cfg
.
update
(
self
.
_get_field_validators
(
field
))
# hide primary key
# hide field which are not readable and not writable
# hide field request by the form modifier
...
...
@@ -372,6 +383,51 @@ class CfgSvc(BaseSvc):
return
di
def
_get_field_validators
(
self
,
field
):
"""
Determine configuration parameters to handle database validators
on the client side.
It mainly set value for minValue, maxValue, regular expression, ....
Return a dictionary
"""
cfg
=
{}
validators
=
field
.
requires
if
not
isinstance
(
validators
,
(
list
,
tuple
)):
validators
=
[
validators
]
for
vdt
in
validators
:
# date and time validators
if
isinstance
(
vdt
,
IS_DATE_IN_RANGE
):
format
=
'
%Y-%m-%d
'
cfg
[
'
minValue
'
]
=
vdt
.
minimum
.
strftime
(
format
)
cfg
[
'
maxValue
'
]
=
vdt
.
maximum
.
strftime
(
format
)
elif
isinstance
(
vdt
,
IS_DATETIME_IN_RANGE
):
format
=
'
%Y-%m-%d %H:%M:%S
'
cfg
[
'
minValue
'
]
=
vdt
.
minimum
.
strftime
(
format
)
cfg
[
'
maxValue
'
]
=
vdt
.
maximum
.
strftime
(
format
)
# number validators
elif
isinstance
(
vdt
,
(
IS_DECIMAL_IN_RANGE
,
IS_FLOAT_IN_RANGE
,
IS_INT_IN_RANGE
)):
cfg
[
'
minValue
'
]
=
vdt
.
minimum
cfg
[
'
maxValue
'
]
=
vdt
.
maximum
# string validator
elif
isinstance
(
vdt
,
IS_MATCH
):
cfg
[
"
regex
"
]
=
vdt
.
regex
.
pattern
# others validator
elif
isinstance
(
vdt
,
IS_LENGTH
):
cfg
[
"
maxLength
"
]
=
vdt
.
maxsize
cfg
[
"
minLength
"
]
=
vdt
.
minsize
return
cfg
def
_is_foreign_field
(
self
,
tablename
,
fieldname
):
"""
Wrapper method
...
...
This diff is collapsed.
Click to expand it.
static/plugin_dbui/CHANGELOG
+
3
−
1
View file @
e3754609
--------------------------------- CHANGE LOG ----------------------------------
0.4.x (Rev)
HEAD
- Add mechanism to transport database validators on the client side.
- Improve the GridModifier to modify column parameters.
- Bugs fixed
0.4.2 (Oct 11)
- Migrate to git and to ExtJS 3.4
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment