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
2a8ab861
Commit
2a8ab861
authored
14 years ago
by
Renaud Le Gac
Browse files
Options
Downloads
Patches
Plain Diff
Modify the return dictionary in _get_fields and add some protection.
parent
38aca9dd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/plugin_dbui/dbsvc.py
+13
-7
13 additions, 7 deletions
modules/plugin_dbui/dbsvc.py
with
13 additions
and
7 deletions
modules/plugin_dbui/dbsvc.py
+
13
−
7
View file @
2a8ab861
...
...
@@ -18,6 +18,7 @@ RECORD_INSERTED = "Record is inserted with id %i."
RECORD_NOT_IN_DB
=
"
The record
'
%s
'
doesn
'
t exist in the table %s.
"
RECORD_UPDATED
=
"
Record %s is updated.
"
TABLE_NOT_IN_DB
=
"
The table
'
%s
'
doesn
'
t exist in the database.
"
TO_MANY_RECORDS
=
"
To many records !!!
"
class
DbSvcException
(
BaseException
):
pass
...
...
@@ -135,7 +136,7 @@ class DbSvc(BaseSvc):
[(table1, field1), (table1, field2), (table2, field3), ...]
records (ROOT)
A
dictionary containing the new / update values for field
List of
dictionary containing the new / update values for field
as well as the identifier of the record to be updated (id)
Return a dictionary {fieldName: value, ...}
...
...
@@ -145,21 +146,26 @@ class DbSvc(BaseSvc):
fields
=
{}
table
=
arg
[
'
tableName
'
]
# protection
if
len
(
arg
[
ROOT
])
>
1
:
raise
DbSvcException
(
TO_MANY_RECORDS
)
# Remove fields in the record which do not belong to the table.
# The JsonStore send the foreign key and the the pointing field
# when manipulating table with foreign keys. the latter belongs
# to another table.
for
record
in
arg
[
ROOT
]
:
for
table_field
in
record
:
tablename
,
fieldname
=
decode_field
(
table_field
)
if
tablename
==
table
:
fields
[
fieldname
.
encode
(
'
utf8
'
)]
=
record
[
table_field
]
record
=
arg
[
ROOT
]
[
0
]
for
table_field
in
record
:
tablename
,
fieldname
=
decode_field
(
table_field
)
if
tablename
==
table
:
fields
[
fieldname
.
encode
(
'
utf8
'
)]
=
record
[
table_field
]
# Validate field contents
di
=
self
.
_is_fields_values_valid
(
table
,
fields
)
if
di
:
table_id
=
encode_field
(
table
,
'
id
'
)
return
{
SUCCESS
:
False
,
"
errors
"
:
di
,
ROOT
:
{
table_id
:
-
1
}}
record
[
table_id
]
=
""
return
{
SUCCESS
:
False
,
"
errors
"
:
di
,
ROOT
:
record
}
return
fields
...
...
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