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
Admin message
Gitlab has been updated. More info
here
.
Show more breadcrumbs
w2pext
plugin_dbui
Commits
38aca9dd
Commit
38aca9dd
authored
14 years ago
by
Renaud Le Gac
Browse files
Options
Downloads
Patches
Plain Diff
Add the method _get_record and protection in the destroy method.
parent
e145e37a
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
+29
-14
29 additions, 14 deletions
modules/plugin_dbui/dbsvc.py
with
29 additions
and
14 deletions
modules/plugin_dbui/dbsvc.py
+
29
−
14
View file @
38aca9dd
...
@@ -15,6 +15,7 @@ FIELD_NOT_IN_DB = "the field '%s.%s' doesn't exist in the database."
...
@@ -15,6 +15,7 @@ FIELD_NOT_IN_DB = "the field '%s.%s' doesn't exist in the database."
KEYWORD_MISSING
=
"
The keyword
'
%s
'
is missing.
"
KEYWORD_MISSING
=
"
The keyword
'
%s
'
is missing.
"
RECORD_DELETED
=
"
Record %s is deleted.
"
RECORD_DELETED
=
"
Record %s is deleted.
"
RECORD_INSERTED
=
"
Record is inserted with id %i.
"
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.
"
RECORD_UPDATED
=
"
Record %s is updated.
"
TABLE_NOT_IN_DB
=
"
The table
'
%s
'
doesn
'
t exist in the database.
"
TABLE_NOT_IN_DB
=
"
The table
'
%s
'
doesn
'
t exist in the database.
"
...
@@ -163,6 +164,22 @@ class DbSvc(BaseSvc):
...
@@ -163,6 +164,22 @@ class DbSvc(BaseSvc):
return
fields
return
fields
def
_get_record
(
self
,
table
,
id
):
"""
Helper function to get the record id in a form which can be decoded
by the JsonReader. Foreign key are resolved.
Return a dictionary where key are the field encoded TableField.
"""
db
=
self
.
environment
[
'
db
'
]
record
=
{}
for
field
in
db
[
table
].
fields
:
key
=
encode_field
(
table
,
field
)
record
[
key
]
=
db
[
table
][
id
][
field
]
return
record
def
_is_field_in_table
(
self
,
table
,
field
):
def
_is_field_in_table
(
self
,
table
,
field
):
"""
Helper method to check that the field belongs to the table.
"""
Helper method to check that the field belongs to the table.
Return a boolean.
Return a boolean.
...
@@ -230,13 +247,9 @@ class DbSvc(BaseSvc):
...
@@ -230,13 +247,9 @@ class DbSvc(BaseSvc):
# return the complete record
# return the complete record
# mandatory, since this is the one which is display in the grid.
# mandatory, since this is the one which is display in the grid.
record
=
{}
record
=
self
.
_get_record
(
table
,
id
)
for
field
in
db
[
table
].
fields
:
key
=
encode_field
(
table
,
field
)
record
[
key
]
=
db
[
table
][
id
][
field
]
self
.
dbg
(
"
End DbSvc.create.
"
,
RECORD_INSERTED
%
id
)
self
.
dbg
(
"
End DbSvc.create.
"
,
RECORD_INSERTED
%
id
)
return
{
SUCCESS
:
True
,
'
msg
'
:
RECORD_INSERTED
%
id
,
ROOT
:
record
}
return
{
SUCCESS
:
True
,
'
msg
'
:
RECORD_INSERTED
%
id
,
ROOT
:
record
}
...
@@ -263,13 +276,19 @@ class DbSvc(BaseSvc):
...
@@ -263,13 +276,19 @@ class DbSvc(BaseSvc):
self
.
_check_request
(
arg
)
self
.
_check_request
(
arg
)
db
=
self
.
environment
[
'
db
'
]
table
=
arg
[
'
tableName
'
]
table
=
arg
[
'
tableName
'
]
table_id
=
encode_field
(
table
,
'
id
'
)
for
id
in
arg
[
ROOT
]:
for
id
in
arg
[
ROOT
]:
del
self
.
environment
[
'
db
'
][
table
][
id
]
if
not
db
[
table
][
id
]:
return
{
"
success
"
:
False
,
"
msg
"
:
RECORD_NOT_IN_DB
%
(
id
,
table
),
ROOT
:
{
table_id
:
id
}}
del
db
[
table
][
id
]
self
.
dbg
(
"
End DbSvc.destroy
"
)
self
.
dbg
(
"
End DbSvc.destroy
"
)
table_id
=
encode_field
(
table
,
'
id
'
)
return
{
"
success
"
:
True
,
"
msg
"
:
RECORD_DELETED
%
id
,
ROOT
:
{
table_id
:
id
}}
return
{
"
success
"
:
True
,
"
msg
"
:
RECORD_DELETED
%
id
,
ROOT
:
{
table_id
:
id
}}
...
@@ -369,17 +388,13 @@ class DbSvc(BaseSvc):
...
@@ -369,17 +388,13 @@ class DbSvc(BaseSvc):
# the client send modified fields only
# the client send modified fields only
# update the database accordingly
# update the database accordingly
db
=
self
.
environment
[
'
db
'
]
id
=
fields
[
'
id
'
]
id
=
fields
[
'
id
'
]
table
=
arg
[
'
tableName
'
]
table
=
arg
[
'
tableName
'
]
db
[
table
][
id
]
=
fields
self
.
environment
[
'
db
'
]
[
table
][
id
]
=
fields
# return the complete record
# return the complete record
# mandatory, since this is the one which is display in the grid.
# mandatory, since this is the one which is display in the grid.
record
=
{}
record
=
self
.
_get_record
(
table
,
id
)
for
field
in
db
[
table
].
fields
:
key
=
encode_field
(
table
,
field
)
record
[
key
]
=
db
[
table
][
id
][
field
]
self
.
dbg
(
"
End DbSvc.update.
"
)
self
.
dbg
(
"
End DbSvc.update.
"
)
return
{
SUCCESS
:
True
,
"
msg
"
:
RECORD_UPDATED
%
id
,
ROOT
:
record
}
return
{
SUCCESS
:
True
,
"
msg
"
:
RECORD_UPDATED
%
id
,
ROOT
:
record
}
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