PageRenderTime 56ms CodeModel.GetById 36ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/galaxy/external_services/result_handlers/basic.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 61 lines | 39 code | 15 blank | 7 comment | 2 complexity | 6acfba084b4fa62003e397fec1e8fc98 MD5 | raw file
 1from galaxy.util.json import to_json_string, from_json_string
 2from galaxy.util.template import fill_template
 3import logging
 4
 5log = logging.getLogger( __name__ )
 6
 7
 8class ExternalServiceActionResultHandler( object ):
 9    """ Basic Class for External Service Actions Result Handlers"""
10
11    type = 'display'
12
13    @classmethod
14    def from_elem( cls, elem, parent ):
15        result_type = elem.get( 'type', None )
16        assert result_type, 'ExternalServiceActionResultHandler requires a type'
17        return result_type_to_class[ result_type ]( elem, parent )
18    def __init__( self, elem, parent ):
19        self.parent = parent
20    def handle_result( self, result, param_dict, trans):
21        return result.content
22        #need to think about how to restore or set mime type:
23        #both as specified in xml and also as set by an action,
24        #    e.g. mimetype returned from web_api action should be reused here...
25
26class ExternalServiceActionURLRedirectResultHandler( ExternalServiceActionResultHandler ):
27    """ Basic Class for External Service Actions Result Handlers"""
28
29    type = 'web_redirect'
30
31    @classmethod
32    def from_elem( cls, elem, parent ):
33        result_type = elem.get( 'type', None )
34        assert result_type, 'ExternalServiceActionResultHandler requires a type'
35        return result_type_to_class[ result_type ]( elem, parent )
36    def __init__( self, elem, parent ):
37        self.parent = parent
38    def handle_result( self, result, param_dict, trans ):
39        return trans.response.send_redirect( result.content )
40
41class ExternalServiceActionJSONResultHandler( ExternalServiceActionResultHandler ):
42    """Class for External Service Actions JQuery Result Handler"""
43
44    type = 'json_display'
45
46    def handle_result( self, result, param_dict, trans ):
47        rval = from_json_string( result.content )
48        return trans.fill_template( '/external_services/generic_json.mako', result = rval, param_dict = param_dict, action=self.parent )
49
50class ExternalServiceActionJQueryGridResultHandler( ExternalServiceActionResultHandler ):
51    """Class for External Service Actions JQuery Result Handler"""
52
53    type = 'jquery_grid'
54
55    def handle_result( self, result, param_dict, trans ):
56        rval = from_json_string( result.content )
57        return trans.fill_template( '/external_services/generic_jquery_grid.mako', result = rval, param_dict = param_dict, action=self.parent )
58
59result_type_to_class = {}
60for handler_class in [ ExternalServiceActionResultHandler, ExternalServiceActionURLRedirectResultHandler, ExternalServiceActionJQueryGridResultHandler, ExternalServiceActionJSONResultHandler ]:
61    result_type_to_class[handler_class.type] = handler_class