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
705f25c4
Commit
705f25c4
authored
14 years ago
by
Renaud Le Gac
Browse files
Options
Downloads
Patches
Plain Diff
Add a new controller returning the content of a table as a CSV file.
parent
2aeddd82
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
controllers/plugin_dbui.py
+42
-8
42 additions, 8 deletions
controllers/plugin_dbui.py
with
42 additions
and
8 deletions
controllers/plugin_dbui.py
+
42
−
8
View file @
705f25c4
...
...
@@ -15,18 +15,11 @@ __version__ = "$Revision$"
import
os
import
traceback
import
sys
from
gluon.contrib
import
simplejson
as
json
from
gluon.http
import
HTTP
from
gluon.tools
import
PluginManager
from
pprint
import
pprint
SCRIPT
=
"""
Ext.namespace(
'
App
'
);
App.csvUrl =
'
/%s/plugin_dbui/csv
'
;
App.name =
'
%s
'
;
App.REMOTE_API = {
'
url
'
:
'
/%s/plugin_dbui/call
'
,
...
...
@@ -44,6 +37,44 @@ def call():
return
directSvc
()
def
csv
():
"""
Controller returning the content of a table as a CSV file.
Foreign keys are replaced by the parent column.
"""
import
gluon.contenttype
dbui
=
local_import
(
'
plugin_dbui
'
)
response
.
headers
[
'
Content-Type
'
]
=
gluon
.
contenttype
.
contenttype
(
'
.csv
'
)
response
.
headers
[
'
Content-Disposition
'
]
=
'
attachment; filename=foo.csv;
'
table
=
request
.
vars
[
'
tableName
'
]
query
=
db
[
table
].
id
>
0
# replace foreign key by parent fields
# and build the query to resolve foreign keys
svc
=
dbui
.
ForeignField
(
db
)
if
svc
.
is_table_with_foreign_fields
(
table
):
fields
=
[]
query
=
((
query
)
&
(
svc
.
get_where_query
(
table
)))
for
field
in
db
[
table
].
fields
:
if
svc
.
is_foreign_field
(
table
,
field
):
k_table
,
k_field
,
k_key
=
svc
.
get_foreign_data
(
table
,
field
)
fields
.
append
(
db
[
k_table
][
k_field
])
else
:
fields
.
append
(
db
[
table
][
field
])
else
:
fields
=
[
db
[
table
].
ALL
]
# interrogate the database
rows
=
db
(
query
).
select
(
*
fields
)
return
str
(
rows
)
def
debug
():
"""
Main Controller to run the plugin in debug mode
Load the javascript source code for all libraries.
...
...
@@ -112,6 +143,8 @@ def get_api():
"""
Controller returning the javascript API definition.
"""
from
gluon.contrib
import
simplejson
as
json
di
=
{}
dbui
=
local_import
(
'
plugin_dbui
'
)
...
...
@@ -143,6 +176,7 @@ def get_api():
# fill the javascript template
app
=
request
.
application
script
=
SCRIPT
%
(
app
,
app
,
app
,
json
.
dumps
(
di
),
json
.
dumps
(
storeCfgs
),
...
...
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