[2] | 1 | from galaxy.web.base.controller import * |
---|
| 2 | from galaxy.web.framework.helpers import grids |
---|
| 3 | from galaxy.model.orm import * |
---|
| 4 | from galaxy import model, util |
---|
| 5 | from galaxy.web.form_builder import * |
---|
| 6 | from galaxy.web.controllers.requests_common import RequestsGrid |
---|
| 7 | import logging |
---|
| 8 | |
---|
| 9 | log = logging.getLogger( __name__ ) |
---|
| 10 | |
---|
| 11 | class UserRequestsGrid( RequestsGrid ): |
---|
| 12 | operations = [ operation for operation in RequestsGrid.operations ] |
---|
| 13 | operations.append( grids.GridOperation( "Edit", allow_multiple=False, condition=( lambda item: not item.deleted and item.is_unsubmitted ) ) ) |
---|
| 14 | operations.append( grids.GridOperation( "Delete", allow_multiple=True, condition=( lambda item: not item.deleted and item.is_new ) ) ) |
---|
| 15 | operations.append( grids.GridOperation( "Undelete", allow_multiple=True, condition=( lambda item: item.deleted ) ) ) |
---|
| 16 | def apply_query_filter( self, trans, query, **kwd ): |
---|
| 17 | # gvk ( 9/28/10 ) TODO: is this method needed? |
---|
| 18 | return query.filter_by( user=trans.user ) |
---|
| 19 | |
---|
| 20 | class Requests( BaseController ): |
---|
| 21 | request_grid = UserRequestsGrid() |
---|
| 22 | |
---|
| 23 | @web.expose |
---|
| 24 | @web.require_login( "view sequencing requests" ) |
---|
| 25 | def index( self, trans ): |
---|
| 26 | return trans.fill_template( "requests/index.mako" ) |
---|
| 27 | @web.expose |
---|
| 28 | @web.require_login( "create/submit sequencing requests" ) |
---|
| 29 | def find_samples_index( self, trans ): |
---|
| 30 | return trans.fill_template( "requests/find_samples_index.mako" ) |
---|
| 31 | @web.expose |
---|
| 32 | def browse_requests( self, trans, **kwd ): |
---|
| 33 | if 'operation' in kwd: |
---|
| 34 | operation = kwd['operation'].lower() |
---|
| 35 | if operation == "edit": |
---|
| 36 | return trans.response.send_redirect( web.url_for( controller='requests_common', |
---|
| 37 | action='edit_basic_request_info', |
---|
| 38 | cntrller='requests', |
---|
| 39 | **kwd ) ) |
---|
| 40 | if operation == "manage_request": |
---|
| 41 | return trans.response.send_redirect( web.url_for( controller='requests_common', |
---|
| 42 | action='manage_request', |
---|
| 43 | cntrller='requests', |
---|
| 44 | **kwd ) ) |
---|
| 45 | if operation == "delete": |
---|
| 46 | return trans.response.send_redirect( web.url_for( controller='requests_common', |
---|
| 47 | action='delete_request', |
---|
| 48 | cntrller='requests', |
---|
| 49 | **kwd ) ) |
---|
| 50 | if operation == "undelete": |
---|
| 51 | return trans.response.send_redirect( web.url_for( controller='requests_common', |
---|
| 52 | action='undelete_request', |
---|
| 53 | cntrller='requests', |
---|
| 54 | **kwd ) ) |
---|
| 55 | if operation == "request_events": |
---|
| 56 | return trans.response.send_redirect( web.url_for( controller='requests_common', |
---|
| 57 | action='request_events', |
---|
| 58 | cntrller='requests', |
---|
| 59 | **kwd ) ) |
---|
| 60 | |
---|
| 61 | # If there are requests that have been rejected, show a message as a reminder to the user |
---|
| 62 | rejected = 0 |
---|
| 63 | for request in trans.sa_session.query( trans.app.model.Request ) \ |
---|
| 64 | .filter( trans.app.model.Request.table.c.deleted==False ) \ |
---|
| 65 | .filter( trans.app.model.Request.table.c.user_id==trans.user.id ): |
---|
| 66 | if request.is_rejected: |
---|
| 67 | rejected = rejected + 1 |
---|
| 68 | if rejected: |
---|
| 69 | status = 'warning' |
---|
| 70 | message = "%d requests (highlighted in red) were rejected. Click on the request name for details." % rejected |
---|
| 71 | kwd[ 'status' ] = status |
---|
| 72 | kwd[ 'message' ] = message |
---|
| 73 | # show the create request button to the user, only when the user has permissions |
---|
| 74 | # to at least one request_type (sequencer configuration) |
---|
| 75 | if len( trans.user.accessible_request_types( trans ) ): |
---|
| 76 | self.request_grid.global_actions = [ grids.GridAction( "Create new request", dict( controller='requests_common', |
---|
| 77 | action='create_request', |
---|
| 78 | cntrller='requests' ) ) ] |
---|
| 79 | else: |
---|
| 80 | self.request_grid.global_actions = [] |
---|
| 81 | # Render the list view |
---|
| 82 | return self.request_grid( trans, **kwd ) |
---|
| 83 | |
---|