mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Decorator for simplifying controller methods that return json (just return
and object that simplejson can understand and it will be jsonified)
This commit is contained in:
@@ -2,5 +2,5 @@
|
||||
The Galaxy web application.
|
||||
"""
|
||||
|
||||
from framework import expose, url_for, FormBuilder
|
||||
from framework import expose, json, url_for, FormBuilder
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ pkg_resources.require( "Mako" )
|
||||
import mako.template
|
||||
import mako.lookup
|
||||
|
||||
pkg_resources.require( "simplejson" )
|
||||
import simplejson
|
||||
|
||||
url_for = base.routes.url_for
|
||||
|
||||
def expose( func ):
|
||||
@@ -30,6 +33,15 @@ def expose( func ):
|
||||
func.exposed = True
|
||||
return func
|
||||
|
||||
def json( func ):
|
||||
def decorator( self, trans, *args, **kwargs ):
|
||||
trans.response.set_content_type( "text/javascript" )
|
||||
return simplejson.dumps( func( self, trans, *args, **kwargs ) )
|
||||
if not hasattr(func, '_orig'):
|
||||
decorator._orig = func
|
||||
decorator.exposed = True
|
||||
return decorator
|
||||
|
||||
NOT_SET = object()
|
||||
|
||||
class WebApplication( base.WebApplication ):
|
||||
|
||||
Reference in New Issue
Block a user