revert root.py (backward compatibility issue)

This commit is contained in:
Kanwei Li
2009-10-21 14:16:38 -04:00
parent 9b335bfaf2
commit 41c4eb5609
+41 -5
View File
@@ -139,13 +139,49 @@ class RootController( BaseController ):
@web.expose
def display( self, trans, id=None, hid=None, tofile=None, toext=".txt", **kwd ):
"""
Backward compatibility.
Returns data directly into the browser.
Sets the mime-type according to the extension
"""
if tofile:
to_ext = toext
if hid is not None:
try:
hid = int( hid )
except:
return "hid '%s' is invalid" %str( hid )
history = trans.get_history()
for dataset in history.datasets:
if dataset.hid == hid:
data = dataset
break
else:
raise Exception( "No dataset with hid '%d'" % hid )
else:
to_ext = None
return trans.webapp.controllers['dataset'].display( trans, encoded_id=id, to_ext=to_ext )
try:
data = self.app.model.HistoryDatasetAssociation.get( id )
except:
return "Dataset id '%s' is invalid" %str( id )
if data:
user, roles = trans.get_user_and_roles()
if trans.app.security_agent.can_access_dataset( roles, data.dataset ):
mime = trans.app.datatypes_registry.get_mimetype_by_extension( data.extension.lower() )
trans.response.set_content_type(mime)
if tofile:
fStat = os.stat(data.file_name)
trans.response.headers['Content-Length'] = int(fStat.st_size)
if toext[0:1] != ".":
toext = "." + toext
valid_chars = '.,^_-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
fname = data.name
fname = ''.join(c in valid_chars and c or '_' for c in fname)[0:150]
trans.response.headers["Content-Disposition"] = "attachment; filename=GalaxyHistoryItem-%s-[%s]%s" % (data.hid, fname, toext)
trans.log_event( "Display dataset id: %s" % str(id) )
try:
return open( data.file_name )
except:
return "This dataset contains no content"
else:
return "You are not allowed to access this dataset"
else:
return "No dataset with id '%s'" % str( id )
@web.expose
def display_child(self, trans, parent_id=None, designation=None, tofile=None, toext=".txt"):