Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
3pia
VISPA
VISPA web
Commits
69f4efda
Commit
69f4efda
authored
Mar 27, 2013
by
Marcel
Browse files
Fix json encoding, change $.getJSON to $.ajax, introduce encode_json in remote filesystem.
parent
8186bdf9
Changes
3
Hide whitespace changes
Inline
Side-by-side
vispa/controller/filesystem.py
View file @
69f4efda
...
@@ -71,26 +71,21 @@ class FSAjaxController(AbstractController):
...
@@ -71,26 +71,21 @@ class FSAjaxController(AbstractController):
@
cherrypy
.
expose
@
cherrypy
.
expose
@
cherrypy
.
tools
.
allow
(
methods
=
[
'POST'
,
'GET'
])
@
cherrypy
.
tools
.
allow
(
methods
=
[
'POST'
,
'GET'
])
@
cherrypy
.
tools
.
json_out
()
def
filelist
(
self
,
path
,
deep
=
False
,
filter
=
[],
reverse
=
False
):
def
filelist
(
self
,
path
,
deep
=
False
,
filter
=
[],
reverse
=
False
):
try
:
try
:
fs
=
self
.
get
(
'fs'
)
fs
=
self
.
get
(
'fs'
)
cherrypy
.
session
.
save
()
cherrypy
.
session
.
save
()
cherrypy
.
session
.
loaded
=
False
cherrypy
.
session
.
loaded
=
False
path
=
self
.
convert
(
path
,
'string'
)
deep
=
self
.
convert
(
deep
,
'boolean'
)
deep
=
self
.
convert
(
deep
,
'boolean'
)
filter
=
self
.
convert
(
filter
,
'string'
)
reverse
=
self
.
convert
(
reverse
,
'boolean'
)
reverse
=
self
.
convert
(
reverse
,
'boolean'
)
# get the files with the filter
# get the files with the filter
files
=
fs
.
get_file_list
(
files
=
fs
.
get_file_list
(
path
,
deep
=
deep
,
filter
=
filter
,
reverse
=
reverse
,
encode_json
=
True
)
path
,
deep
=
deep
,
filter
=
filter
,
reverse
=
reverse
)
rjson
=
vispa
.
rpc
.
get
(
cherrypy
.
request
.
user
,
cherrypy
.
request
.
workspace
).
getmodule
(
"json"
)
return
self
.
success
({
'data'
:
json
.
loads
(
files
)})
cherrypy
.
response
.
headers
[
'Content-Type'
]
=
"application/json"
return
rjson
.
dumps
(
files
)
except
Exception
,
e
:
except
Exception
,
e
:
vispa
.
log_exception
()
vispa
.
log_exception
()
return
self
.
fail
(
msg
=
'Couldn
\'
t load files: %s'
%
str
(
e
))
return
self
.
fail
(
msg
=
'Couldn
\'
t load files: %s'
%
str
(
e
))
...
...
vispa/remote/filesystem.py
View file @
69f4efda
...
@@ -8,6 +8,7 @@ import locale
...
@@ -8,6 +8,7 @@ import locale
import
shutil
import
shutil
from
mimetypes
import
guess_type
from
mimetypes
import
guess_type
from
zipfile
import
ZipFile
from
zipfile
import
ZipFile
import
json
class
FileSystem
(
object
):
class
FileSystem
(
object
):
...
@@ -68,7 +69,7 @@ class FileSystem(object):
...
@@ -68,7 +69,7 @@ class FileSystem(object):
return
None
return
None
return
target_type
if
target_type
==
type
else
None
return
target_type
if
target_type
==
type
else
None
def
get_file_list
(
self
,
path
,
deep
=
False
,
filter
=
[],
reverse
=
False
,
hide_hidden
=
True
):
def
get_file_list
(
self
,
path
,
deep
=
False
,
filter
=
[],
reverse
=
False
,
hide_hidden
=
True
,
encode_json
=
False
):
filelist
=
[]
filelist
=
[]
path_expand
=
os
.
path
.
expanduser
(
os
.
path
.
expandvars
(
path
))
path_expand
=
os
.
path
.
expanduser
(
os
.
path
.
expandvars
(
path
))
for
elem
in
os
.
listdir
(
path_expand
):
for
elem
in
os
.
listdir
(
path_expand
):
...
@@ -103,7 +104,11 @@ class FileSystem(object):
...
@@ -103,7 +104,11 @@ class FileSystem(object):
# Determine the parent
# Determine the parent
parentpath
=
path_expand
[:
-
1
]
if
path_expand
.
endswith
(
os
.
sep
)
and
path_expand
!=
os
.
sep
else
path_expand
parentpath
=
path_expand
[:
-
1
]
if
path_expand
.
endswith
(
os
.
sep
)
and
path_expand
!=
os
.
sep
else
path_expand
parentpath
=
os
.
path
.
dirname
(
path_expand
)
parentpath
=
os
.
path
.
dirname
(
path_expand
)
return
{
'filelist'
:
filelist
,
'parentpath'
:
parentpath
}
data
=
{
'filelist'
:
filelist
,
'parentpath'
:
parentpath
}
if
encode_json
:
return
json
.
dumps
(
data
)
return
data
def
get_suggestions
(
self
,
path
,
length
=
1
,
append_hidden
=
True
):
def
get_suggestions
(
self
,
path
,
length
=
1
,
append_hidden
=
True
):
suggestions
=
[]
suggestions
=
[]
...
...
vispa/static/js/base/file/filebase/base.js
View file @
69f4efda
...
@@ -51,16 +51,22 @@ var FileBase = Class.extend({
...
@@ -51,16 +51,22 @@ var FileBase = Class.extend({
},
},
updateView
:
function
()
{
updateView
:
function
()
{
// this.workflow.data = this.ajax.fileList(this.workflow.path);
// this.currentView.setContent(this.workflow.data);
var
_this
=
this
;
var
_this
=
this
;
$
.
getJSON
(
this
.
urlFormatter
(
'
ajax/fs/filelist
'
+
"
?path=
"
+
this
.
workflow
.
path
),
$
.
ajax
({
function
(
data
)
{
url
:
this
.
urlFormatter
(
'
ajax/fs/filelist
'
),
_this
.
workflow
.
data
=
data
;
type
:
'
POST
'
,
_this
.
currentView
.
setContent
(
data
);
data
:
{
console
.
log
(
data
);
path
:
this
.
workflow
.
path
});
},
success
:
function
(
response
)
{
if
(
response
.
success
)
{
_this
.
workflow
.
data
=
response
.
data
;
_this
.
currentView
.
setContent
(
response
.
data
);
}
else
{
$
.
Topic
(
'
msg.error
'
).
publish
(
response
.
msg
);
}
}
});
}
}
});
});
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment