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
1d3d08fe
Commit
1d3d08fe
authored
12 years ago
by
LE GAC Renaud
Browse files
Options
Downloads
Patches
Plain Diff
More syntax for foreign field.
parent
8483a9b9
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_tools.py
+7
-6
7 additions, 6 deletions
models/db_tools.py
modules/plugin_dbui/helper.py
+40
-6
40 additions, 6 deletions
modules/plugin_dbui/helper.py
static/plugin_dbui/CHANGELOG
+1
-0
1 addition, 0 deletions
static/plugin_dbui/CHANGELOG
with
48 additions
and
12 deletions
models/db_tools.py
+
7
−
6
View file @
1d3d08fe
...
...
@@ -23,26 +23,27 @@ tp_ratio = \
"
Parameter for fuzzy string search.
"
db
.
define_table
(
"
harvesters
"
,
Field
(
"
id_teams
"
,
db
.
teams
,
default
=
undef_id
,
label
=
'
Team
'
),
Field
(
"
id_projects
"
,
db
.
projects
,
default
=
undef_id
,
label
=
'
Project
'
),
Field
(
"
id_teams
"
,
"
reference
teams
"
,
default
=
undef_id
,
label
=
'
Team
'
),
Field
(
"
id_projects
"
,
"
reference
projects
"
,
default
=
undef_id
,
label
=
'
Project
'
),
Field
(
"
controller
"
,
"
string
"
,
notnull
=
True
,
comment
=
tp_controller
),
Field
(
"
host
"
,
"
string
"
,
notnull
=
True
,
default
=
'
cdsweb.cern.ch
'
,
label
=
'
Store
'
,
comment
=
tp_host
),
Field
(
"
collections
"
,
"
string
"
,
comment
=
tp_collections
),
Field
(
"
ratio
"
,
"
double
"
,
notnull
=
True
,
default
=
1.0
,
comment
=
tp_ratio
),
Field
(
"
id_categories
"
,
db
.
categories
,
default
=
1
,
label
=
'
Category
'
,
comment
=
tp_category
),
Field
(
"
id_categories
"
,
"
reference
categories
"
,
default
=
1
,
label
=
'
Category
'
,
comment
=
tp_category
),
migrate
=
"
harvesters.table
"
)
db
.
harvesters
.
controller
.
requires
=
\
IS_IN_SET
([
'
articles
'
,
'
notes
'
,
'
preprints
'
,
'
proceedings
'
,
'
reports
'
,
'
talks
'
,
'
theses
'
])
# TEST THE DIFFERENT SYNTAX DEFINING FOREIGN KEY
db
.
harvesters
.
id_categories
.
requires
=
\
IS_IN_DB
(
db
,
'
categories.id
'
,
'
categories.code
'
)
db
.
harvesters
.
id_projects
.
requires
=
\
IS_IN_DB
(
db
,
'
projects.id
'
,
'
projects.project
'
)
IS_IN_DB
(
db
,
'
projects.project
'
)
db
.
harvesters
.
id_teams
.
requires
=
\
IS_IN_DB
(
db
,
'
teams.id
'
,
'
teams.team
'
)
#
db.harvesters.id_teams.requires = \
#
IS_IN_DB(db, 'teams.id', 'teams.team')
db
.
harvesters
.
ratio
.
requires
=
\
IS_FLOAT_IN_RANGE
(
0.
,
1.0
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
modules/plugin_dbui/helper.py
+
40
−
6
View file @
1d3d08fe
...
...
@@ -202,20 +202,54 @@ def get_file_paths(path, ext=None, alpha=True):
def
get_foreign_field
(
field
):
"""
Helper function returning a tuple containing the parent tablename,
the parent fieldname and the primary key name of the parent table.
table.field --> k_table.k_field
table.field == k_table.k_key
"""
Helper function returning a tuple (k_tablename, k_fieldname, k_keyname)
where:
k_tablename is the name of the parent table
k_fieldname is the name of the parent field
table.field --> k_table.k_field
k_keyname is the name of the primary key of the parent table
requires by the left join. In most of the case it is id
table.field == k_table.k_key
Otherwise return None.
"""
if
not
is_foreign_field
(
field
):
return
None
# foreign field validators IS_IN_BD contains all information
# on the parent key for the left join and on the parent field
validators
=
as_list
(
field
.
requires
)
# Several syntax are allowed
# IS_IN_DB is use.
for
vdt
in
validators
:
if
isinstance
(
vdt
,
IS_IN_DB
):
return
(
vdt
.
ktable
,
vdt
.
ks
[
0
],
vdt
.
ks
[
1
])
# IS_IN_DB contains only the parent field.
# The key for the left join is the id key of the parent table
if
len
(
vdt
.
ks
)
==
1
:
return
(
vdt
.
ktable
,
vdt
.
ks
[
0
],
'
id
'
)
# IS_IN_DB contains the key for the join and the parent field
else
:
return
(
vdt
.
ktable
,
vdt
.
ks
[
0
],
vdt
.
ks
[
1
])
# IS_IN_DB is not use.
# The parent key for the left join is the id key of the parent table
# the parent field is the first field of the parent table which differs id
if
not
validators
:
i
=
field
.
type
.
index
(
'
'
)
ktablename
=
field
.
type
[
i
:].
strip
()
for
kfield
in
field
.
_db
[
ktablename
]:
if
kfield
.
name
!=
'
id
'
:
return
(
ktablename
,
kfield
.
name
,
'
id
'
)
return
None
...
...
This diff is collapsed.
Click to expand it.
static/plugin_dbui/CHANGELOG
+
1
−
0
View file @
1d3d08fe
...
...
@@ -2,6 +2,7 @@
HEAD
- Upgrade to run with alias table.
- More syntax to define foreign key.
0.4.10.3 (Mar 2013)
- Fix a bug in App.BasePanelWithSelector for IE.
...
...
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