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
9612b618
Commit
9612b618
authored
14 years ago
by
Renaud Le Gac
Browse files
Options
Downloads
Patches
Plain Diff
complete version debug with simple table.
parent
4f5eacf8
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/dbsvc2.py
+20
-11
20 additions, 11 deletions
modules/plugin_dbui/dbsvc2.py
with
20 additions
and
11 deletions
modules/plugin_dbui/dbsvc2.py
+
20
−
11
View file @
9612b618
...
...
@@ -8,7 +8,7 @@ __version__ = "$Revision$"
from
basesvc
import
BaseSvc
from
cfgsvc2
import
ROOT
,
SUCCESS
,
TOTAL
from
gluon.contrib
import
simplejson
as
json
from
helper
import
decode_field
,
rows_serializer
from
helper
import
encode_field
,
decode_field
,
rows_serializer
FIELD_NOT_IN_DB
=
"
the field
'
%s.%s
'
doesn
'
t exist in the database.
"
...
...
@@ -57,7 +57,7 @@ class DbSvc2(BaseSvc):
"""
def
_check_request
(
self
,
arg
):
def
_check_request
(
self
,
arg
,
keywords
=
(
'
tableName
'
,
'
records
'
)
):
"""
Helper function to check that the request arg is well formed.
The dictionary arg contains the following keys:
...
...
@@ -67,7 +67,7 @@ class DbSvc2(BaseSvc):
dbFields
The list of table fields.
records (
ROOT
)
records (
optional
)
A dictionary containing the new / update values for field
as well as the identifier of the record to be create, updated
or delete.
...
...
@@ -77,9 +77,9 @@ class DbSvc2(BaseSvc):
"""
# check that the request is well formed
for
kword
in
(
'
tableName
'
,
'
dbFields
'
,
ROOT
)
:
for
kword
in
keywords
:
if
kword
not
in
arg
:
raise
DbSvcException
(
KEYWORD_MISSING
%
kw
)
raise
DbSvcException
(
KEYWORD_MISSING
%
kw
ord
)
table
=
arg
[
'
tableName
'
]
self
.
_is_table_in_db
(
table
)
...
...
@@ -142,6 +142,7 @@ class DbSvc2(BaseSvc):
"""
fields
=
{}
table
=
arg
[
'
tableName
'
]
# Remove fields in the record which do not belong to the table.
# The JsonStore send the foreign key and the the pointing field
...
...
@@ -211,7 +212,7 @@ class DbSvc2(BaseSvc):
as well as the identifier of the record to be updated (id)
Return a dictionary with status, message and id of the update row:
{success: True, msg:
'
blalbla
'
,
records:{i
d:xx}}
{success: True, msg:
'
blalbla
'
,
data:{TableI
d:xx}}
"""
self
.
dbg
(
"
Start DbSvc.create
"
)
...
...
@@ -221,11 +222,15 @@ class DbSvc2(BaseSvc):
if
SUCCESS
in
fields
and
fields
[
SUCCESS
]
==
False
:
return
fields
table
=
arg
[
'
tableName
'
]
id
=
self
.
environment
[
'
db
'
][
table
].
insert
(
**
fields
)
table_id
=
encode_field
(
table
,
'
id
'
)
self
.
dbg
(
"
End DbSvc.create.
"
,
RECORD_INSERTED
%
id
)
return
{
SUCCESS
:
True
,
"
msg
"
:
RECORD_INSERTED
%
id
,
ROOT
:
{
"
id
"
:
id
}}
# NOTE Ext JS 3.3.2 request explicitly the word 'data'
# if you use records (ROOT) javascript raise an exception !!!
return
{
SUCCESS
:
True
,
'
msg
'
:
RECORD_INSERTED
%
id
,
'
data
'
:
{
table_id
:
id
}}
def
destroy
(
self
,
arg
):
...
...
@@ -251,6 +256,7 @@ class DbSvc2(BaseSvc):
self
.
_check_request
(
arg
)
table
=
arg
[
'
tableName
'
]
for
id
in
arg
[
ROOT
]:
del
self
.
environment
[
'
db
'
][
table
][
id
]
...
...
@@ -290,7 +296,7 @@ class DbSvc2(BaseSvc):
"""
self
.
dbg
(
"
Start DbSvc.read
"
)
self
.
_check_request
(
arg
)
self
.
_check_request
(
arg
,
(
'
tableName
'
,
'
dbFields
'
)
)
db
=
self
.
environment
[
'
db
'
]
# build the list of SQLField object
...
...
@@ -315,6 +321,7 @@ class DbSvc2(BaseSvc):
# interrogate the database and serialize the records as a list:
# [{TableField: value, }, {...}, ...]
table
=
arg
[
'
tableName
'
]
rows
=
db
(
query
).
select
(
*
fields
,
**
kwargs
)
li
=
rows_serializer
(
rows
)
results
=
db
(
db
[
table
].
id
).
count
()
...
...
@@ -340,7 +347,7 @@ class DbSvc2(BaseSvc):
as well as the identifier of the record to be updated (id)
Return a dictionary with status, message and id of the update row:
{success: True, msg:
'
blalbla
'
, records:{
i
d:xx}}
{success: True, msg:
'
blalbla
'
, records:{
TableI
d:xx}}
"""
self
.
dbg
(
"
Start DbSvc.update.
"
)
...
...
@@ -352,7 +359,9 @@ class DbSvc2(BaseSvc):
return
fields
id
=
fields
[
'
id
'
]
table
=
arg
[
'
tableName
'
]
self
.
environment
[
'
db
'
][
table
][
id
]
=
fields
table_id
=
encode_field
(
table
,
'
id
'
)
self
.
dbg
(
"
End DbSvc.update.
"
)
return
{
SUCCESS
:
True
,
"
msg
"
:
RECORD_UPDATED
%
id
,
ROOT
:
{
"
id
"
:
id
}}
return
{
SUCCESS
:
True
,
"
msg
"
:
RECORD_UPDATED
%
id
,
ROOT
:
{
table_
id
:
id
}}
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