PageRenderTime 63ms CodeModel.GetById 41ms app.highlight 17ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/galaxy/web/controllers/requests.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 91 lines | 82 code | 6 blank | 3 comment | 20 complexity | 12bb919a2afbaa68e72dd7254311a6f0 MD5 | raw file
 1from galaxy.web.base.controller import *
 2from galaxy.web.framework.helpers import grids
 3from galaxy.model.orm import *
 4from galaxy.web.form_builder import *
 5from galaxy.web.controllers.requests_common import RequestsGrid
 6import logging
 7
 8log = logging.getLogger( __name__ )
 9
10class UserRequestsGrid( RequestsGrid ):
11    operations = [ operation for operation in RequestsGrid.operations ]
12    operations.append( grids.GridOperation( "Edit", allow_multiple=False, condition=( lambda item: item.is_unsubmitted and not item.deleted ) ) )
13    operations.append( grids.GridOperation( "Delete", allow_multiple=True, condition=( lambda item: item.is_new and not item.deleted ) ) )
14    operations.append( grids.GridOperation( "Undelete", allow_multiple=True, condition=( lambda item: item.deleted ) ) )
15    def apply_query_filter( self, trans, query, **kwd ):
16        return query.filter_by( user=trans.user )
17
18class Requests( BaseUIController ):
19    request_grid = UserRequestsGrid()
20
21    @web.expose
22    @web.require_login( "view sequencing requests" )
23    def index( self, trans ):
24        return trans.fill_template( "requests/index.mako" )
25    @web.expose
26    @web.require_login( "create/submit sequencing requests" )
27    def find_samples_index( self, trans ):
28        return trans.fill_template( "requests/find_samples_index.mako" )
29    @web.expose
30    def browse_requests( self, trans, **kwd ):
31        if 'operation' in kwd:
32            operation = kwd['operation'].lower()
33            if operation == "edit":
34                return trans.response.send_redirect( web.url_for( controller='requests_common',
35                                                                  action='edit_basic_request_info',
36                                                                  cntrller='requests',
37                                                                  **kwd ) )
38            if operation == "add_samples":
39                return trans.response.send_redirect( web.url_for( controller='requests_common',
40                                                                  action='add_samples',
41                                                                  cntrller='requests',
42                                                                  **kwd ) )
43            if operation == "edit_samples":
44                return trans.response.send_redirect( web.url_for( controller='requests_common',
45                                                                  action='edit_samples',
46                                                                  cntrller='requests',
47                                                                  **kwd ) )
48            if operation == "view_request":
49                return trans.response.send_redirect( web.url_for( controller='requests_common',
50                                                                  action='view_request',
51                                                                  cntrller='requests',
52                                                                  **kwd ) )
53            if operation == "delete":
54                return trans.response.send_redirect( web.url_for( controller='requests_common',
55                                                                  action='delete_request',
56                                                                  cntrller='requests',
57                                                                  **kwd ) )
58            if operation == "undelete":
59                return trans.response.send_redirect( web.url_for( controller='requests_common',
60                                                                  action='undelete_request',
61                                                                  cntrller='requests',
62                                                                  **kwd ) )
63            if operation == "view_request_history":
64                return trans.response.send_redirect( web.url_for( controller='requests_common',
65                                                                  action='view_request_history',
66                                                                  cntrller='requests',
67                                                                  **kwd ) )
68
69        # If there are requests that have been rejected, show a message as a reminder to the user
70        rejected = 0
71        for request in trans.sa_session.query( trans.app.model.Request ) \
72                            .filter( trans.app.model.Request.table.c.deleted==False ) \
73                            .filter( trans.app.model.Request.table.c.user_id==trans.user.id ):
74            if request.is_rejected:
75                rejected = rejected + 1
76        if rejected:
77            status = 'warning'
78            message = "%d requests (highlighted in red) were rejected.  Click on the request name for details." % rejected
79            kwd[ 'status' ] = status
80            kwd[ 'message' ] = message
81        # Allow the user to create a new request only if they have permission to access a request type.
82        accessible_request_types = trans.app.security_agent.get_accessible_request_types( trans, trans.user )
83        if accessible_request_types:
84            self.request_grid.global_actions = [ grids.GridAction( "Create new request", dict( controller='requests_common',
85                                                                                               action='create_request',
86                                                                                               cntrller='requests' ) ) ]
87        else:
88            self.request_grid.global_actions = []
89        # Render the list view
90        return self.request_grid( trans, **kwd )
91