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
f3f5a923
Commit
f3f5a923
authored
14 years ago
by
Renaud Le Gac
Browse files
Options
Downloads
Patches
Plain Diff
The CfgSvc understands composite_fields.
parent
2a65858f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
models/db_widgets.py
+8
-2
8 additions, 2 deletions
models/db_widgets.py
modules/plugin_dbui/cfgsvc.py
+48
-5
48 additions, 5 deletions
modules/plugin_dbui/cfgsvc.py
modules/plugin_dbui/fieldmodifier.py
+16
-2
16 additions, 2 deletions
modules/plugin_dbui/fieldmodifier.py
with
72 additions
and
9 deletions
models/db_widgets.py
+
8
−
2
View file @
f3f5a923
...
...
@@ -39,6 +39,14 @@ dbui.configure_grids(db, plugins=['pGridRowEditorContextMenu',
m
=
dbui
.
FieldModifier
(
'
publications
'
)
m
.
configure_field
(
'
year
'
,
maxValue
=
datetime
.
now
().
year
)
m
.
merge_fields
(
'
first_page
'
,
'
last_page
'
,
extjs
=
{
'
fieldLabel
'
:
T
(
'
Pages
'
),
'
defaults
'
:
{
'
flex
'
:
1
}})
m
.
merge_fields
(
'
conference_start
'
,
'
conference_end
'
,
extjs
=
{
'
fieldLabel
'
:
T
(
'
Dates
'
),
'
defaults
'
:
{
'
flex
'
:
1
}})
fm
=
dbui
.
FormModifier
(
'
publications
'
)
fm
.
merge_fields
(
'
title
'
,
'
authors
'
,
...
...
@@ -48,14 +56,12 @@ fm.merge_fields('title',
'
doi
'
,
'
volume
'
,
'
first_page
'
,
'
last_page
'
,
'
e_print
'
,
extjs
=
{
'
title
'
:
T
(
'
General
'
),
'
collapsible
'
:
True
,
'
flex
'
:
1
})
fm
.
merge_fields
(
'
conference_title
'
,
'
conference_url
'
,
'
conference_start
'
,
'
conference_end
'
,
'
conference_town
'
,
'
id_countries
'
,
'
conference_speaker
'
,
...
...
This diff is collapsed.
Click to expand it.
modules/plugin_dbui/cfgsvc.py
+
48
−
5
View file @
f3f5a923
...
...
@@ -42,6 +42,30 @@ class CfgSvc(object):
setattr
(
self
,
'
_%s
'
%
key
,
pluginManager
.
dbui
[
key
])
def
_append_form_field
(
self
,
tablename
,
fieldname
,
li
):
"""
Append the field configuration dictionary to the list li.
The field is identify by its database tablename and fieldname.
This method handle single and composite fields.
A composite field is a set of field display in a row.
Only the label of the first field is shown.
See the documentation of the Ext.form.Compositefield class for details.
"""
if
tablename
in
self
.
_field_modifiers
:
fieldmodifier
=
self
.
_field_modifiers
[
tablename
]
if
fieldname
in
fieldmodifier
.
composite_fields
.
main
:
li
.
append
(
self
.
_get_form_composite_field
(
tablename
,
fieldname
))
elif
fieldname
not
in
fieldmodifier
.
composite_fields
.
others
:
li
.
append
(
self
.
_get_form_field
(
tablename
,
fieldname
))
else
:
li
.
append
(
self
.
_get_form_field
(
tablename
,
fieldname
))
def
_get_column
(
self
,
tablename
,
fieldname
):
"""
Build the column model required by the Ext.grid.GridPanel widget
for the database field tablename.fieldname.
...
...
@@ -126,6 +150,22 @@ class CfgSvc(object):
"""
return
self
.
_set
.
get_set_data
(
tablename
,
fieldname
)
def
_get_form_composite_field
(
self
,
tablename
,
fieldname
):
"""
Build the configuration dictionary for a composite field.
"""
cfg
=
{
'
xtype
'
:
'
compositefield
'
,
'
items
'
:[]}
fieldmodifier
=
self
.
_field_modifiers
[
tablename
]
compositefield
=
fieldmodifier
.
composite_fields
[
fieldname
]
for
field
in
compositefield
.
fields
:
cfg
[
'
items
'
].
append
(
self
.
_get_form_field
(
tablename
,
field
))
cfg
.
update
(
compositefield
.
extjs
)
return
cfg
def
_get_form_field
(
self
,
tablename
,
fieldname
):
...
...
@@ -209,11 +249,14 @@ class CfgSvc(object):
def
_get_form_model_items
(
self
,
tablename
):
"""
Build the list of items appearing in a Form model.
The method return a list of configuration dictionary for fields
or a list of configuration dictionary for fieldsets.
"""
li
,
id_is_not_used
,
formmodifiers
=
[],
True
,
self
.
_form_modifiers
#
f
orm with field sets
#
F
orm with field sets
# NOTE: the field id is add in order to run this form
# in all context, create, update, destroy.
# It is add to the latest fieldset.
...
...
@@ -224,7 +267,7 @@ class CfgSvc(object):
cfg
=
{
'
xtype
'
:
'
fieldset
'
,
'
items
'
:
[]}
for
fieldname
in
fieldset
.
fields
:
cfg
[
'
items
'
].
append
(
self
.
_get
_form_field
(
tablename
,
fieldname
)
)
self
.
_append
_form_field
(
tablename
,
fieldname
,
cfg
[
'
items
'
]
)
if
fieldname
==
'
id
'
:
id_is_not_used
=
False
...
...
@@ -245,10 +288,10 @@ class CfgSvc(object):
if
id_is_not_used
:
li
[
-
1
][
'
items
'
].
append
(
self
.
_get_form_field
(
tablename
,
'
id
'
))
#
the default form
#
Form with fields
else
:
for
fieldname
in
self
.
_db
[
tablename
].
fields
:
li
.
append
(
self
.
_get
_form_field
(
tablename
,
fieldname
)
)
self
.
_append
_form_field
(
tablename
,
fieldname
,
li
)
return
li
...
...
This diff is collapsed.
Click to expand it.
modules/plugin_dbui/fieldmodifier.py
+
16
−
2
View file @
f3f5a923
...
...
@@ -24,8 +24,11 @@ class FieldModifier(Modifier):
"""
Modifier
.
__init__
(
self
,
FIELD_MODIFIERS
,
tablename
)
self
.
data
.
composite_fields
=
[]
self
.
data
.
extjs_fields
=
{}
self
.
data
.
composite_fields
=
Storage
()
self
.
data
.
composite_fields
.
main
=
[]
self
.
data
.
composite_fields
.
others
=
[]
def
append_plugins
(
self
,
*
plugins
):
...
...
@@ -67,5 +70,16 @@ class FieldModifier(Modifier):
if
'
extjs
'
in
kwargs
:
extjs
.
update
(
kwargs
[
'
extjs
'
])
main_field
=
fields
[
0
]
other_fields
=
fields
[
1
:]
# NOTE
# In order to simplify the processing keep a list of
# the main field, the first field appearing in the composite field,
# and a list of the other fields.
self
.
data
.
composite_fields
.
main
.
append
(
main_field
)
self
.
data
.
composite_fields
.
others
.
extend
(
other_fields
)
di
=
Storage
(
fields
=
fields
,
extjs
=
extjs
)
self
.
data
.
composite_fields
.
append
(
di
)
self
.
data
.
composite_fields
[
main_field
]
=
di
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