Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
w2pext
plugin_dbui
Commits
85e0cb0d
Commit
85e0cb0d
authored
Apr 11, 2015
by
legac
Browse files
Remove authors and convert @type, param, rtpype, return to :type, ...
parent
18316a3e
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
329 additions
and
361 deletions
+329
-361
modules/plugin_dbui/__init__.py
modules/plugin_dbui/__init__.py
+7
-1
modules/plugin_dbui/basesvc.py
modules/plugin_dbui/basesvc.py
+1
-3
modules/plugin_dbui/callback.py
modules/plugin_dbui/callback.py
+6
-10
modules/plugin_dbui/constant.py
modules/plugin_dbui/constant.py
+0
-2
modules/plugin_dbui/converter.py
modules/plugin_dbui/converter.py
+63
-65
modules/plugin_dbui/dbsvc.py
modules/plugin_dbui/dbsvc.py
+55
-57
modules/plugin_dbui/directsvc.py
modules/plugin_dbui/directsvc.py
+14
-16
modules/plugin_dbui/extjs.py
modules/plugin_dbui/extjs.py
+6
-8
modules/plugin_dbui/fieldsmodifier.py
modules/plugin_dbui/fieldsmodifier.py
+5
-7
modules/plugin_dbui/filters.py
modules/plugin_dbui/filters.py
+8
-10
modules/plugin_dbui/formmodifier.py
modules/plugin_dbui/formmodifier.py
+15
-17
modules/plugin_dbui/gridmodifier.py
modules/plugin_dbui/gridmodifier.py
+15
-17
modules/plugin_dbui/helper.py
modules/plugin_dbui/helper.py
+78
-80
modules/plugin_dbui/mapper.py
modules/plugin_dbui/mapper.py
+7
-9
modules/plugin_dbui/modifier.py
modules/plugin_dbui/modifier.py
+5
-7
modules/plugin_dbui/navtree.py
modules/plugin_dbui/navtree.py
+15
-17
modules/plugin_dbui/selector.py
modules/plugin_dbui/selector.py
+17
-17
modules/plugin_dbui/storemodifier.py
modules/plugin_dbui/storemodifier.py
+6
-8
modules/plugin_dbui/validator.py
modules/plugin_dbui/validator.py
+0
-2
modules/plugin_dbui/viewportmodifier.py
modules/plugin_dbui/viewportmodifier.py
+6
-8
No files found.
modules/plugin_dbui/__init__.py
View file @
85e0cb0d
""" Author: R. Le Gac
""" The package is structured in several modules.
The most import ones are:
* *constant*
* *helper* a set of helper functions.
* *formmodifier* and *gridmodifier*, *viewportmodifier*
* *dbsvc* linking the user interface to the database
"""
from
callback
import
INHIBIT_DELETE_UNDEF
,
INHIBIT_UPDATE_UNDEF
...
...
modules/plugin_dbui/basesvc.py
View file @
85e0cb0d
""" base class to build service
@author: R. Le Gac
"""
import
pprint
...
...
@@ -16,7 +14,7 @@ class BaseSvc:
def
dbg
(
self
,
*
args
):
"""Print
C{
args
}
if the attribute debug is true.
"""Print
``
args
``
if the attribute debug is true.
"""
if
self
.
debug
:
...
...
modules/plugin_dbui/callback.py
View file @
85e0cb0d
# -*- coding: utf-8 -*-
""" callback
@author: R. Le Gac
"""
from
constant
import
UNDEF_ID
from
dbsvc
import
CALLBACK_ERRORS
...
...
@@ -12,11 +10,10 @@ from gluon import current
def
INHIBIT_DELETE_UNDEF
(
set
):
"""Delete the row containing undefined value is not allowed
@
type set: gluon.dal.Set
@
param set:
:
type set: gluon.dal.Set
:
param set:
@rtype: bool
@return:
:returns: bool
"""
db
,
T
=
current
.
globalenv
[
'db'
],
current
.
T
...
...
@@ -39,11 +36,10 @@ def INHIBIT_DELETE_UNDEF(set):
def
INHIBIT_UPDATE_UNDEF
(
set
,
values
):
"""Update the row containing undefined value is not allowed
@
type set: gluon.dal.Set
@
param set:
:
type set: gluon.dal.Set
:
param set:
@rtype: bool
@return:
:returns: bool
"""
db
,
T
=
current
.
globalenv
[
'db'
],
current
.
T
...
...
modules/plugin_dbui/constant.py
View file @
85e0cb0d
# -*- coding: utf-8 -*-
""" constant
@author: R. Le Gac
"""
INLINE_ALERT
=
"<script>Ext.Msg.alert('%s', '%s');</script>"
UNDEF
=
'undefined'
...
...
modules/plugin_dbui/converter.py
View file @
85e0cb0d
""" a series of converter to transform L{gluon.dal} objects into Ext JS widgets.
@author: R. Le Gac
"""
import
gluon.dal
import
re
...
...
@@ -54,25 +52,25 @@ def _to_field(field, linkedcombo=True, **kwargs):
The conversion takes into account the L{FieldsModifier} instructions
but does not handle C{FieldContainer}.
@
param field:
@
type field: gluon.dal.Field
:
param field:
:
type field: gluon.dal.Field
@
type linkedcombo: bool
@
param linkedcombo: C{LinkedComboBox} are ignored when C{False}.
:
type linkedcombo: bool
:
param linkedcombo: C{LinkedComboBox} are ignored when C{False}.
Useful to build grid filter.
@
keyword kwargs: any Ext JS configuration parameters of the
:
keyword kwargs: any Ext JS configuration parameters of the
C{Ext.form.Field} class. They are applied in the following order:
constructor, modifiers and keyword arguments.
@rtype
: Field
:returns
: Field
@
note: The return configurator is a L{Field}. However it can be a
:
note: The return configurator is a L{Field}. However it can be a
L{ComboBox}, a L{FieldDate}, a L{FieldTextArea}, ...
depending on the C{type} of the database field.
The association is defined in the dictionary L{FTYPE_TO_XTYPE}.
@
attention: It is recommended to used the more general method L{to_field}
:
attention: It is recommended to used the more general method L{to_field}
which also understands C{FieldContainer}.
"""
...
...
@@ -174,32 +172,32 @@ def to_field(field, composite=True, linkedcombo=True, **kwargs):
The conversion handles L{FieldContainer} and takes into account
the C{FieldsModifier} instructions.
@
note: The return configurator is a L{Field}. However it can be a
:
note: The return configurator is a L{Field}. However it can be a
L{ComboBox}, a L{FieldDate}, a L{FieldTextArea}, ...
depending on the C{type} of the database field.
The association is defined in the dictionary L{FTYPE_TO_XTYPE}.
@
note: The database fields can be organized in L{FieldContainer}
:
note: The database fields can be organized in L{FieldContainer}
in the application model using the modifiers L{FieldsModifier}.
@
type field: gluon.dal.Field
@
param field:
:
type field: gluon.dal.Field
:
param field:
@
type composite: bool
@
param composite: C{FieldContainer} is ignored when C{False}.
:
type composite: bool
:
param composite: C{FieldContainer} is ignored when C{False}.
Useful to build grid filter.
@
type linkedcombo: bool
@
param linkedcombo: C{LinkedComboBox} are ignored when C{False}.
:
type linkedcombo: bool
:
param linkedcombo: C{LinkedComboBox} are ignored when C{False}.
Useful to build grid filter.
@
param kwargs: any Ext JS configuration parameter of the C{Ext.form.Field}
:
param kwargs: any Ext JS configuration parameter of the C{Ext.form.Field}
class. They are applied in the following order:
constructor, modifiers and keyword arguments.
@rtype
: Field or C{None}
:retruns
: Field or C{None}
@
note: Return None when composite is C{True} and when
:
note: Return None when composite is C{True} and when
the field is consumed by a C{FieldContainer}.
"""
...
...
@@ -244,19 +242,19 @@ def to_fields(table):
"""Build the list L{Field} configuration for each field
of the database C{table}.
@
note: The return configuration is a L{Field}. However it can be a
:
note: The return configuration is a L{Field}. However it can be a
L{ComboBox}, a L{FieldDate}, a L{FieldTextArea}, ...
depending on the C{type} of the database field.
The association is defined in the dictionary L{FTYPE_TO_XTYPE}.
@
note: The function handles L{FieldSet} and L{FieldContainer}
:
note: The function handles L{FieldSet} and L{FieldContainer}
as well as the L{FieldsModifier} instructions.
The C{FieldSet} and C{FieldContainer} can be defined in the application
model using the modifier L{FormModifier} and the L{FieldsModifier}
respectively.
@
type table: gluon.dal.Table
@rtype
: list
:
type table: gluon.dal.Table
:returns
: list
"""
li
=
[]
...
...
@@ -325,15 +323,15 @@ def to_formPanel(table, **kwargs):
"""Build the L{FormPanel} configuration for the database C{table}.
The conversion takes into account the L{FormModifier} instructions.
@
type table: gluon.dal.Table
@
param table:
:
type table: gluon.dal.Table
:
param table:
@
param kwargs: any Ext JS configuration parameter of the
:
param kwargs: any Ext JS configuration parameter of the
C{Ext.form.Panel} class. They are
applied in the following order: constructor, modifiers
and keyword arguments.
@rtype
: FormPanel
:returns
: FormPanel
"""
tablename
=
table
.
_tablename
...
...
@@ -360,15 +358,15 @@ def to_gridColumn(field, **kwargs):
"""Build the L{GridColumn} configuration for the database C{field}.
The conversion takes into account the L{GridModifier} instructions.
@
type field: gluon.dal.Field
@
param field:
:
type field: gluon.dal.Field
:
param field:
@
param kwargs: any Ext JS configuration parameter of the
:
param kwargs: any Ext JS configuration parameter of the
C{Ext.grid.Column} class.
They are applied in the following order: constructor, modifiers
and keyword arguments.
@rtype
: GridColumn
:returns
: GridColumn
"""
T
=
current
.
T
...
...
@@ -423,10 +421,10 @@ def to_gridColumnModel(table):
"""Build the L{GridColumnModel} configuration for the database C{table}.
The conversion takes into account the L{GridModifier} instructions.
@
type table: gluon.dal.Table
@
param table:
:
type table: gluon.dal.Table
:
param table:
@rtype
: GridColumnModel
:returns
: GridColumnModel
"""
delete_columns
=
[]
...
...
@@ -465,19 +463,19 @@ def to_gridFilter(table, **kwargs):
"""Build the L{GridFilter} configuration for the database C{table}.
The GridFilter is parametrized using the L{GridModifier}.
@
type table: gluon.dal.Table
@
param table:
:
type table: gluon.dal.Table
:
param table:
@
keyword kwargs: any of the Ext JS configuration parameters of the
:
keyword kwargs: any of the Ext JS configuration parameters of the
C{App.grid.Filter} class. They are applied in the following order:
constructor, modifiers, keyword arguments.
@rtype
: GridFilter
:returns
: GridFilter
@
note: Return an empty dictionary if the GridFilter is
:
note: Return an empty dictionary if the GridFilter is
not defined in the application model.
@
note: A filter rule is defined in the model via the L{GridModifier}.
:
note: A filter rule is defined in the model via the L{GridModifier}.
The rule is a C{tuple} containing 3 strings
C{("field1", "operator", "comment")}
where C{field1} is the name of a field belonging to the C{table}.
...
...
@@ -485,7 +483,7 @@ def to_gridFilter(table, **kwargs):
the syntax is C{("table2.field1", "operator", "comments")}.
Valid operators are defined in the method L{dbsvc.DbSvc._encode_query}.
@
note: Rules are store in the modifier section C{grid_filters}.
:
note: Rules are store in the modifier section C{grid_filters}.
"""
T
=
current
.
T
...
...
@@ -580,14 +578,14 @@ def to_gridPanel(table, **kwargs):
"""Build the L{App.grid.Panel} configuration for the database C{table}.
The conversion takes into account the L{GridModifier} instructions.
@
type table: gluon.dal.Table
@
param table:
:
type table: gluon.dal.Table
:
param table:
@
keyword kwargs: any of the Ext JS configuration parameters of the
:
keyword kwargs: any of the Ext JS configuration parameters of the
C{App.grid.Panel} class. They are applied in the following order:
constructor, modifiers, keyword arguments.
@rtype
: GridPanel
:returns
: GridPanel
"""
tablename
=
table
.
_tablename
...
...
@@ -624,14 +622,14 @@ def to_jsonstore(table, **kwargs):
"""Build the L{DirectStore} configuration for the database C{table}.
The conversion takes into account the L{StoreModifier} instructions.
@
type table: gluon.dal.Table
@
param table:
:
type table: gluon.dal.Table
:
param table:
@
keyword kwargs: any of the Ext JS configuration parameters of the
:
keyword kwargs: any of the Ext JS configuration parameters of the
C{App.data.DirectStore} class. They are applied in the following order:
constructor, modifiers, keyword arguments.
@rtype
: DirectStore
:returns
: DirectStore
"""
db
=
table
.
_db
...
...
@@ -711,10 +709,10 @@ def to_jsonstore(table, **kwargs):
def
to_model
(
table
):
"""Build the L{Ext.data.Model} configuration for the database C{table}.
@
type table: gluon.dal.Table
@
param table:
:
type table: gluon.dal.Table
:
param table:
@rtype
: dict
:returns
: dict
"""
db
=
table
.
_db
...
...
@@ -759,24 +757,24 @@ def to_panelWithUrlSelector(table, selectorTitle='Select', **kwargs):
"""Build the L{PanelWithUrlSelector} configuration
where the selector is a form derived from the database C{table}.
@
type table: gluon.dal.Table
@
param table:
:
type table: gluon.dal.Table
:
param table:
@
type selectorTitle: str
@
param selectorTitle: the title of the FieldSet encapsulating
:
type selectorTitle: str
:
param selectorTitle: the title of the FieldSet encapsulating
the selector fields.
@
keyword baseUrl: The selected values are send to a controller
:
keyword baseUrl: The selected values are send to a controller
defined by the baseUrl.
Values are processed and results will be published in the panel.
It is mandatory to specified the baseUrl.
@
keyword kwargs: any of the Ext JS configuration parameters of the
:
keyword kwargs: any of the Ext JS configuration parameters of the
C{App.panel.WithUrlSelector} class.
@rtype
: PanelWithUrlSelector
:returns
: PanelWithUrlSelector
@
raise BaseException: when baseUrl is not defined.
:
raise BaseException: when baseUrl is not defined.
"""
if
'baseUrl'
not
in
kwargs
:
...
...
@@ -802,7 +800,7 @@ def to_treeNodes():
The Node structure is defined in the application model using
L{ViewportModifier}.
@
rtype: list
:
rtype: list
"""
cfg
=
[]
...
...
@@ -821,10 +819,10 @@ def to_viewport(**kwargs):
"""Build the C{Ext.Viewport} configuration.
The conversion takes into account the L{ViewportModifier} instructions.
@
keyword kwargs: any of the Ext JS configuration parameters of the
:
keyword kwargs: any of the Ext JS configuration parameters of the
C{App.viewport.Viewport} class.
@rtype
: dict
:returns
: dict
"""
cfg
=
{}
...
...
modules/plugin_dbui/dbsvc.py
View file @
85e0cb0d
""" the database service.
@author: R. Le Gac
"""
import
re
...
...
@@ -112,8 +110,8 @@ class DbSvc(BaseSvc):
"""Check that the transaction data dictionary C{arg}
contains the C{keywords}.
@
type arg: dict
@
param arg: transaction data
:
type arg: dict
:
param arg: transaction data
- C{tableName}
the name of the table in the database
...
...
@@ -143,10 +141,10 @@ class DbSvc(BaseSvc):
records to be deleted.
@
type keywords: dict
@
param keywords: list of keys which have to be in C{arg}
:
type keywords: dict
:
param keywords: list of keys which have to be in C{arg}
@
raise DbSvcException: when a keyword is missing or when the table
:
raise DbSvcException: when a keyword is missing or when the table
does not exist in the database.
"""
...
...
@@ -162,8 +160,8 @@ class DbSvc(BaseSvc):
def
_encode_query
(
self
,
li
):
"""Encode the query send by the client to a web2py C{Query}.
@
type li: list
@
param li: the query send by the client as a list of string.
:
type li: list
:
param li: the query send by the client as a list of string.
The following string are understood by the method::
"[table1.field1] == [table2.field2]" or "[table1, field1] == [table2, field2]"
...
...
@@ -175,17 +173,17 @@ class DbSvc(BaseSvc):
"[table1.field1] belongs (1, 2, 3)"
"([table1.field1] == [table2.field2]) | ([table1.field2] == [table2.field1])"
@
rtype: tuple of gluon.dal.Query
@
return:
:
rtype: tuple of gluon.dal.Query
:
return:
- the first element is the full query with all conditions or an empty string.
- the second element contains only the left join conditions or an empty string.
- the third element contains only the filter conditions or an empty string.
@
note: All elements of the list are ANDED in the web2py query
:
note: All elements of the list are ANDED in the web2py query
@
note: comparison operators are C{==, !=, <, >, <=, >=}
:
note: comparison operators are C{==, !=, <, >, <=, >=}
@
note: Boolean operators are C{&, |}
:
note: Boolean operators are C{&, |}
"""
query
,
join
,
filter
=
""
,
""
,
""
...
...
@@ -230,14 +228,14 @@ class DbSvc(BaseSvc):
def
_get_record
(
self
,
table
,
id
):
"""Get the record C{id} located in the database C{table}.
@
type table: gluon.dal.Table
@
param table:
:
type table: gluon.dal.Table
:
param table:
@
type id: int
@
param id:
:
type id: int
:
param id:
@
rtype: dict
@
return: key, value pairs where each key corresponds
:
rtype: dict
:
return: key, value pairs where each key corresponds
to a field of the table. Foreign keys are resolved.
The key are encoded as C{Table1Field1}.
...
...
@@ -262,13 +260,13 @@ class DbSvc(BaseSvc):
def
_is_field_in_table
(
self
,
table
,
field
):
"""Check that the C{field} belongs to the C{table}.
@
type table: gluon.dal.Table
@
param table:
:
type table: gluon.dal.Table
:
param table:
@
type field: gluon.dal.Field
@
param field:
:
type field: gluon.dal.Field
:
param field:
@
rtype: bool
:
rtype: bool
"""
return
field
in
current
.
globalenv
[
'db'
][
table
].
fields
...
...
@@ -278,15 +276,15 @@ class DbSvc(BaseSvc):
"""Check each C{field} value against its C{validators}.
@
type table: gluon.dal.Table
@
param table:
:
type table: gluon.dal.Table
:
param table:
@
type fields: dict
@
param fields: key, value pairs where each key corresponds
:
type fields: dict
:
param fields: key, value pairs where each key corresponds
to a C{gluon.dal.Field}
@
rtype: dict
@
return: key, value pairs for each field with errors.
:
rtype: dict
:
return: key, value pairs for each field with errors.
The key is encoded as C{Table1Field1} and the value is a string
describing the error message.
...
...
@@ -313,12 +311,12 @@ class DbSvc(BaseSvc):
def
_is_table_in_db
(
self
,
tablename
):
"""Check that the table exists in the database.
@
type tablename: str
@
param tablename: name of the table
:
type tablename: str
:
param tablename: name of the table
@
raise DbSvcException: when the table does not exists
:
raise DbSvcException: when the table does not exists
@
note: The method works with regular and alias tables.
:
note: The method works with regular and alias tables.
"""
db
=
current
.
globalenv
[
'db'
]
...
...
@@ -338,8 +336,8 @@ class DbSvc(BaseSvc):
The method also validates each value.
@
type arg: dict
@
param arg: transaction data
:
type arg: dict
:
param arg: transaction data
- C{tableName}
the name of the table in the database
...
...
@@ -365,8 +363,8 @@ class DbSvc(BaseSvc):
- The keys are encoded as C{Table1Field1}.
@
rtype: gluon.storage.Storage
@
return:
:
rtype: gluon.storage.Storage
:
return:
- C{Storage(errors=[], records=[])}
...
...
@@ -414,8 +412,8 @@ class DbSvc(BaseSvc):
def
count
(
self
,
tablename
):
"""Count the total number of records in the table
@
type tablename: string
@
param tablename: name of the table
:
type tablename: string
:
param tablename: name of the table
"""
db
=
current
.
globalenv
[
'db'
]
...
...
@@ -426,8 +424,8 @@ class DbSvc(BaseSvc):
"""Create new records defined by the transaction data C{arg}.
Several transactions of the same type are processed together.
@
type arg: dict
@
param arg: transaction data
:
type arg: dict
:
param arg: transaction data
- C{tableName}
the name of the tablename in the database
...
...
@@ -451,8 +449,8 @@ class DbSvc(BaseSvc):
- The keys are encoded as C{Table1Field1}.
@
rtype: dict
@
return:
:
rtype: dict
:
return:
- C{{success: True, records:[{Table1Field1: val, ... }, ... ],
msg: 'blalbla'}}
...
...
@@ -522,8 +520,8 @@ class DbSvc(BaseSvc):
"""Delete existing records defined by the transaction data C{arg}.
Several transactions of the same type are processed together.
@
type arg: dict
@
param arg: transaction data
:
type arg: dict
:
param arg: transaction data
- C{tableName}
the name of the tablename in the database
...
...
@@ -539,8 +537,8 @@ class DbSvc(BaseSvc):
- C{records} the list of C{id} for the records
to be deleted, C{[id1, id2, ... ]}.
@
rtype: dict
@
return:
:
rtype: dict
:
return:
- C{{success: True, records:[{Table1Id1: id}, ...], msg: 'blalbla'}}
...
...
@@ -601,8 +599,8 @@ class DbSvc(BaseSvc):
"""Read the content of a table as specified in the transaction data C{arg}.
The C{arg} dictionary contains the following keys:
@
type arg: dict
@
param arg: transaction data
:
type arg: dict
:
param arg: transaction data
- C{tableName}
the name of the table in the database
...
...
@@ -644,8 +642,8 @@ class DbSvc(BaseSvc):
- sort
- dir
@
rtype: dict
@
return:
:
rtype: dict
:
return:
- C{{success: True, records: [{TableField: value, ...}, ...]}}
...
...
@@ -729,8 +727,8 @@ class DbSvc(BaseSvc):
"""Update records defined by the transaction data C{arg}.
Several transactions of the same type are processed together.
@
type arg: dict
@
param arg: transaction data
:
type arg: dict
:
param arg: transaction data
- C{tableName}
the name of the tablename in the database
...
...
@@ -756,8 +754,8 @@ class DbSvc(BaseSvc):
- The keys are encoded as C{Table1Field1}.
@
rtype: dict
@
return:
:
rtype: dict
:
return:
- C{{success: True, records:[{Table1Field1: val, ... }, ... ],
msg: 'blalbla'}}
...
...
modules/plugin_dbui/directsvc.py
View file @
85e0cb0d
""" implementation of the C{Ext.Direct} protocol on the server-side.
@author: R. Le Gac
"""
import
datetime
...
...
@@ -82,13 +80,13 @@ class DirectSvc(BaseSvc):