[hg] galaxy 3046: Adding grids to forms, requests & request type...
details: http://www.bx.psu.edu/hg/galaxy/rev/ed8972386675 changeset: 3046:ed8972386675 user: rc date: Tue Nov 17 14:28:34 2009 -0500 description: Adding grids to forms, requests & request types pages. Resolves issue #231. diffstat: lib/galaxy/web/controllers/forms.py | 252 ++++++--- lib/galaxy/web/controllers/requests.py | 302 ++++++----- lib/galaxy/web/controllers/requests_admin.py | 663 ++++++++++++++++--------- templates/admin/forms/edit_form.mako | 2 +- templates/admin/forms/grid.mako | 1 + templates/admin/forms/manage_forms.mako | 76 --- templates/admin/forms/show_form_read_only.mako | 4 +- templates/admin/requests/create_request_type.mako | 92 +- templates/admin/requests/grid.mako | 218 +-------- templates/admin/requests/manage_request_types.mako | 69 +-- templates/admin/requests/show_request.mako | 2 +- templates/admin/requests/view_request_type.mako | 70 +- templates/requests/grid.mako | 218 +-------- templates/requests/show_request.mako | 2 +- test/base/twilltestcase.py | 34 +- test/functional/test_forms_and_requests.py | 44 +- test/functional/test_user_info.py | 9 +- 17 files changed, 879 insertions(+), 1179 deletions(-) diffs (2629 lines): diff -r 56bb85457bc1 -r ed8972386675 lib/galaxy/web/controllers/forms.py --- a/lib/galaxy/web/controllers/forms.py Tue Nov 17 13:43:34 2009 -0500 +++ b/lib/galaxy/web/controllers/forms.py Tue Nov 17 14:28:34 2009 -0500 @@ -8,9 +8,71 @@ from elementtree.ElementTree import XML, Element from galaxy.util.odict import odict import copy +from galaxy.web.framework.helpers import time_ago, iff, grids log = logging.getLogger( __name__ ) +class FormsGrid( grids.Grid ): + # Custom column types + class NameColumn( grids.TextColumn ): + def get_value(self, trans, grid, form): + return form.latest_form.name + class DescriptionColumn( grids.TextColumn ): + def get_value(self, trans, grid, form): + return form.latest_form.desc + class TypeColumn( grids.TextColumn ): + def get_value(self, trans, grid, form): + return form.latest_form.type + class DeletedColumn( grids.GridColumn ): + def get_accepted_filters( self ): + """ Returns a list of accepted filters for this column. """ + accepted_filter_labels_and_vals = { "active" : "False", "deleted" : "True", "all": "All" } + accepted_filters = [] + for label, val in accepted_filter_labels_and_vals.items(): + args = { self.key: val } + accepted_filters.append( grids.GridColumnFilter( label, args) ) + return accepted_filters + # Grid definition + title = "Forms" + template = "admin/forms/grid.mako" + model_class = model.FormDefinitionCurrent + default_sort_key = "-create_time" + num_rows_per_page = 50 + preserve_state = True + use_paging = True + default_filter = dict( deleted="False" ) + columns = [ + NameColumn( "Name", + key="name", + model_class=model.FormDefinition, + link=( lambda item: iff( item.deleted, None, dict( operation="view", id=item.id ) ) ), + attach_popup=True, + filterable="advanced" ), + DescriptionColumn( "Description", + key='desc', + model_class=model.FormDefinition, + filterable="advanced" ), + TypeColumn( "Type" ), + DeletedColumn( "Deleted", + key="deleted", + visible=False, + filterable="advanced" ) + ] + columns.append( grids.MulticolFilterColumn( "Search", + cols_to_filter=[ columns[0], columns[1] ], + key="free-text-search", + visible=False, + filterable="standard" ) ) + operations = [ + grids.GridOperation( "Edit", allow_multiple=False, condition=( lambda item: not item.deleted ) ), + grids.GridOperation( "Delete", allow_multiple=True, condition=( lambda item: not item.deleted ) ), + grids.GridOperation( "Undelete", condition=( lambda item: item.deleted ) ), + ] + global_actions = [ + grids.GridAction( "Create new form", dict( controller='forms', + action='new' ) ) + ] + class Forms( BaseController ): # Empty form field empty_field = { 'label': '', @@ -20,38 +82,38 @@ 'type': BaseField.form_field_types()[0], 'selectlist': [], 'layout': 'none' } + forms_grid = FormsGrid() + @web.expose @web.require_admin - def index( self, trans, **kwd ): - params = util.Params( kwd ) - msg = util.restore_text( params.get( 'msg', '' ) ) - messagetype = params.get( 'messagetype', 'done' ) - return trans.fill_template( "/sample/index.mako", - default_action=params.get( 'default_action', None ), - msg=msg, - messagetype=messagetype ) - @web.expose - @web.require_admin - def manage( self, trans, **kwd ): - params = util.Params( kwd ) - msg = util.restore_text( params.get( 'msg', '' ) ) - messagetype = params.get( 'messagetype', 'done' ) - show_filter = params.get( 'show_filter', 'Active' ) - return self._show_forms_list(trans, msg, messagetype, show_filter) - def _show_forms_list(self, trans, msg, messagetype, show_filter='Active'): - all_forms = trans.sa_session.query( trans.app.model.FormDefinitionCurrent ) - if show_filter == 'All': - forms_list = all_forms - elif show_filter == 'Deleted': - forms_list = [form for form in all_forms if form.deleted] - else: - forms_list = [form for form in all_forms if not form.deleted] - return trans.fill_template( '/admin/forms/manage_forms.mako', - fdc_list=forms_list, - all_forms=all_forms, - show_filter=show_filter, - msg=msg, - messagetype=messagetype ) + def manage( self, trans, **kwd ): + if 'operation' in kwd: + operation = kwd['operation'].lower() + if not kwd.get( 'id', None ): + return trans.response.send_redirect( web.url_for( controller='forms', + action='manage', + status='error', + message="Invalid form ID") ) + if operation == "view": + return self.__view( trans, **kwd ) + elif operation == "delete": + return self.__delete( trans, **kwd ) + elif operation == "undelete": + return self.__undelete( trans, **kwd ) + elif operation == "edit": + return self.__edit( trans, **kwd ) + return self.forms_grid( trans, **kwd ) + def __view(self, trans, **kwd): + try: + fdc = trans.sa_session.query( trans.app.model.FormDefinitionCurrent )\ + .get( trans.security.decode_id(kwd['id']) ) + except: + return trans.response.send_redirect( web.url_for( controller='forms', + action='manage', + msg='Invalid form', + messagetype='error' ) ) + return trans.fill_template( '/admin/forms/show_form_read_only.mako', + form=fdc.latest_form ) def __form_types_widget(self, trans, selected='none'): form_type_selectbox = SelectField( 'form_type_selectbox', refresh_on_change=True, @@ -86,13 +148,14 @@ self.__get_saved_form( fd ) if self.__imported_from_file: return trans.response.send_redirect( web.url_for( controller='forms', - action='edit', - show_form=True, - form_id=fd.id) ) + action='manage', + operation='edit', + id=trans.security.encode_id(fd.current.id)) ) else: return trans.response.send_redirect( web.url_for( controller='forms', - action='edit', - form_id=fd.id, + action='manage', + operation='edit', + id=trans.security.encode_id(fd.current.id), add_field_button='Add field', name=fd.name, description=fd.desc, @@ -105,35 +168,43 @@ inputs=inputs, msg=msg, messagetype=messagetype ) - @web.expose - @web.require_admin - def delete( self, trans, **kwd ): - params = util.Params( kwd ) - msg = util.restore_text( params.get( 'msg', '' ) ) - messagetype = params.get( 'messagetype', 'done' ) - fd = trans.sa_session.query( trans.app.model.FormDefinition ).get( int( util.restore_text( params.form_id ) ) ) - fd.form_definition_current.deleted = True - trans.sa_session.add( fd.form_definition_current ) - trans.sa_session.flush() - return self._show_forms_list(trans, - msg='The form definition named %s is deleted.' % fd.name, - messagetype='done') - @web.expose - @web.require_admin - def undelete( self, trans, **kwd ): - params = util.Params( kwd ) - msg = util.restore_text( params.get( 'msg', '' ) ) - messagetype = params.get( 'messagetype', 'done' ) - fd = trans.sa_session.query( trans.app.model.FormDefinition ).get( int( util.restore_text( params.form_id ) ) ) - fd.form_definition_current.deleted = False - trans.sa_session.add( fd.form_definition_current ) - trans.sa_session.flush() - return self._show_forms_list(trans, - msg='The form definition named %s is undeleted.' % fd.name, - messagetype='done') - @web.expose - @web.require_admin - def edit( self, trans, **kwd ): + def __delete( self, trans, **kwd ): + id_list = util.listify( kwd['id'] ) + delete_failed = [] + for id in id_list: + try: + fdc = trans.sa_session.query( trans.app.model.FormDefinitionCurrent ).get( trans.security.decode_id(id) ) + except: + return trans.response.send_redirect( web.url_for( controller='forms', + action='manage', + message='Invalid form', + status='error' ) ) + fdc.deleted = True + trans.sa_session.add( fdc ) + trans.sa_session.flush() + return trans.response.send_redirect( web.url_for( controller='forms', + action='manage', + message='%i form(s) is deleted.' % len(id_list), + status='done') ) + def __undelete( self, trans, **kwd ): + id_list = util.listify( kwd['id'] ) + delete_failed = [] + for id in id_list: + try: + fdc = trans.sa_session.query( trans.app.model.FormDefinitionCurrent ).get( trans.security.decode_id(id) ) + except: + return trans.response.send_redirect( web.url_for( controller='forms', + action='manage', + message='Invalid form', + status='error' ) ) + fdc.deleted = False + trans.sa_session.add( fdc ) + trans.sa_session.flush() + return trans.response.send_redirect( web.url_for( controller='forms', + action='manage', + message='%i form(s) is undeleted.' % len(id_list), + status='done') ) + def __edit( self, trans, **kwd ): ''' This callback method is for handling all the editing functions like renaming fields, adding/deleting fields, changing fields attributes. @@ -142,17 +213,28 @@ msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) try: - fd = trans.sa_session.query( trans.app.model.FormDefinition ).get( int( params.get( 'form_id', None ) ) ) + fdc = trans.sa_session.query( trans.app.model.FormDefinitionCurrent ).get( trans.security.decode_id(kwd['id']) ) except: return trans.response.send_redirect( web.url_for( controller='forms', action='manage', - msg='Invalid form', - messagetype='error' ) ) + message='Invalid form', + status='error' ) ) + fd = fdc.latest_form # - # Show the form for editing + # Save changes # - if params.get( 'show_form', False ): + if params.get( 'save_changes_button', False ): + fd_new, msg = self.__save_form( trans, fdc_id=fd.form_definition_current.id, **kwd ) + # if validation error encountered while saving the form, show the + # unsaved form, with the error message + if not fd_new: + current_form = self.__get_form( trans, **kwd ) + return self.__show( trans=trans, form=fd, current_form=current_form, + msg=msg, messagetype='error', **kwd ) + # everything went fine. form saved successfully. Show the saved form + fd = fd_new current_form = self.__get_saved_form( fd ) + msg = "The form '%s' has been updated with the changes." % fd.name return self.__show( trans=trans, form=fd, current_form=current_form, msg=msg, messagetype=messagetype, **kwd ) # @@ -193,31 +275,6 @@ return self.__show( trans=trans, form=fd, current_form=current_form, msg=msg, messagetype=messagetype, **kwd ) # - # Save changes - # - elif params.get( 'save_changes_button', False ): - fd_new, msg = self.__save_form( trans, fdc_id=fd.form_definition_current.id, **kwd ) - # if validation error encountered while saving the form, show the - # unsaved form, with the error message - if not fd_new: - current_form = self.__get_form( trans, **kwd ) - return self.__show( trans=trans, form=fd, current_form=current_form, - msg=msg, messagetype='error', **kwd ) - # everything went fine. form saved successfully. Show the saved form - fd = fd_new - current_form = self.__get_saved_form( fd ) - msg = "The form '%s' has been updated with the changes." % fd.name - return self.__show( trans=trans, form=fd, current_form=current_form, - msg=msg, messagetype=messagetype, **kwd ) - # - # Show form read-only - # - elif params.get( 'read_only', False ): - return trans.fill_template( '/admin/forms/show_form_read_only.mako', - form=fd, - msg=msg, - messagetype=messagetype ) - # # Add SelectField option # elif 'Add' in kwd.values(): @@ -234,6 +291,13 @@ current_form = self.__get_form( trans, **kwd ) return self.__show( trans=trans, form=fd, current_form=current_form, msg=msg, messagetype=messagetype, **kwd ) + # + # Show the form for editing + # + else: + current_form = self.__get_saved_form( fd ) + return self.__show( trans=trans, form=fd, current_form=current_form, + msg=msg, messagetype=messagetype, **kwd ) def __add_selectbox_option( self, trans, fd, msg, messagetype, **kwd ): ''' diff -r 56bb85457bc1 -r ed8972386675 lib/galaxy/web/controllers/requests.py --- a/lib/galaxy/web/controllers/requests.py Tue Nov 17 13:43:34 2009 -0500 +++ b/lib/galaxy/web/controllers/requests.py Tue Nov 17 14:28:34 2009 -0500 @@ -12,57 +12,109 @@ log = logging.getLogger( __name__ ) -class RequestsListGrid( grids.Grid ): +class RequestsGrid( grids.Grid ): + # Custom column types + class NameColumn( grids.TextColumn ): + def get_value(self, trans, grid, request): + return request.name + class DescriptionColumn( grids.TextColumn ): + def get_value(self, trans, grid, request): + return request.desc + class SamplesColumn( grids.GridColumn ): + def get_value(self, trans, grid, request): + return str(len(request.samples)) + class TypeColumn( grids.TextColumn ): + def get_value(self, trans, grid, request): + return request.type.name + class LastUpdateColumn( grids.TextColumn ): + def get_value(self, trans, grid, request): + return request.update_time + class StateColumn( grids.GridColumn ): + def filter( self, db_session, query, column_filter ): + """ Modify query to filter request by state. """ + if column_filter == "All": + return query + if column_filter: + query = query.filter( model.Request.state == column_filter ) + return query + def get_accepted_filters( self ): + """ Returns a list of accepted filters for this column. """ + accepted_filter_labels_and_vals = [ model.Request.states.UNSUBMITTED, + model.Request.states.SUBMITTED, + model.Request.states.COMPLETE, + "All"] + accepted_filters = [] + for val in accepted_filter_labels_and_vals: + label = val.lower() + args = { self.key: val } + accepted_filters.append( grids.GridColumnFilter( label, args) ) + return accepted_filters + class DeletedColumn( grids.GridColumn ): + def get_accepted_filters( self ): + """ Returns a list of accepted filters for this column. """ + accepted_filter_labels_and_vals = { "active" : "False", "deleted" : "True", "all": "All" } + accepted_filters = [] + for label, val in accepted_filter_labels_and_vals.items(): + args = { self.key: val } + accepted_filters.append( grids.GridColumnFilter( label, args) ) + return accepted_filters + # Grid definition title = "Sequencing Requests" - template = '/requests/grid.mako' + template = 'requests/grid.mako' model_class = model.Request default_sort_key = "-create_time" - show_filter = model.Request.states.UNSUBMITTED + num_rows_per_page = 50 + preserve_state = True + use_paging = True + default_filter = dict( deleted="False", state=model.Request.states.UNSUBMITTED) columns = [ - grids.GridColumn( "Name", key="name", - link=( lambda item: iff( item.deleted, None, dict( operation="show_request", id=item.id ) ) ), - attach_popup=True ), - grids.GridColumn( "Description", key='desc'), - grids.GridColumn( "Sample(s)", method='number_of_samples', - link=( lambda item: iff( item.deleted, None, dict( operation="show_request", id=item.id ) ) ), ), - grids.GridColumn( "Type", key="request_type_id", method='get_request_type'), - grids.GridColumn( "Last update", key="update_time", format=time_ago ), - grids.GridColumn( "State", key='state'), + NameColumn( "Name", + key="name", + model_class=model.Request, + link=( lambda item: iff( item.deleted, None, dict( operation="show_request", id=item.id ) ) ), + attach_popup=True, + filterable="advanced" ), + DescriptionColumn( "Description", + key='desc', + model_class=model.Request, + filterable="advanced" ), + SamplesColumn( "Sample(s)", + link=( lambda item: iff( item.deleted, None, dict( operation="show_request", id=item.id ) ) ), ), + TypeColumn( "Type" ), + LastUpdateColumn( "Last update", + format=time_ago ), + StateColumn( "State", + key='state', + filterable="advanced"), + DeletedColumn( "Deleted", + key="deleted", + visible=True, + filterable="advanced" ) ] + columns.append( grids.MulticolFilterColumn( "Search", + cols_to_filter=[ columns[0], columns[1] ], + key="free-text-search", + visible=False, + filterable="standard" ) ) operations = [ grids.GridOperation( "Submit", allow_multiple=False, condition=( lambda item: not item.deleted and item.unsubmitted() and item.samples ) ), grids.GridOperation( "Edit", allow_multiple=False, condition=( lambda item: not item.deleted and item.unsubmitted() ) ), - grids.GridOperation( "Delete", allow_multiple=False, condition=( lambda item: not item.deleted and item.unsubmitted() ) ), - grids.GridOperation( "Undelete", allow_multiple=False, condition=( lambda item: item.deleted ) ) + grids.GridOperation( "Delete", allow_multiple=True, condition=( lambda item: not item.deleted and item.unsubmitted() ) ), + grids.GridOperation( "Undelete", allow_multiple=True, condition=( lambda item: item.deleted ) ) ] - standard_filters = [ - grids.GridColumnFilter( model.Request.states.UNSUBMITTED, - args=dict( state=model.Request.states.UNSUBMITTED, deleted=False ) ), - grids.GridColumnFilter( model.Request.states.SUBMITTED, - args=dict( state=model.Request.states.SUBMITTED, deleted=False ) ), - grids.GridColumnFilter( model.Request.states.COMPLETE, args=dict( state=model.Request.states.COMPLETE, deleted=False ) ), - grids.GridColumnFilter( "Deleted", args=dict( deleted=True ) ), - grids.GridColumnFilter( "All", args={} ) + global_actions = [ + grids.GridAction( "Create new request", dict( controller='requests', + action='new', + select_request_type='True' ) ) ] - #default_filter = dict( deleted=False ) - def get_current_item( self, trans ): - return None - def get_request_type(self, trans, request): - return request.type.name - def apply_default_filter( self, trans, query, **kwargs ): - query = query.filter_by( user=trans.user ) - if self.default_filter: - return query.filter_by( **self.default_filter ) - else: - return query - def number_of_samples(self, trans, request): - return str(len(request.samples)) - def get_state(self, trans, request): - return request.state + def apply_default_filter( self, trans, query, **kwd ): + return query.filter_by( user=trans.user ) + def build_initial_query( self, session ): + return session.query( self.model_class ) class Requests( BaseController ): - request_grid = RequestsListGrid() + request_grid = RequestsGrid() @web.expose @web.require_login( "create/submit sequencing requests" ) @@ -71,50 +123,43 @@ @web.expose @web.require_login( "create/submit sequencing requests" ) - def list( self, trans, **kwargs ): + def list( self, trans, **kwd ): ''' List all request made by the current user ''' - status = message = None - self.request_grid.default_filter = dict(state=trans.app.model.Request.states.UNSUBMITTED, - deleted=False) - if 'operation' in kwargs: - operation = kwargs['operation'].lower() + + if 'operation' in kwd: + operation = kwd['operation'].lower() + if not kwd.get( 'id', None ): + return trans.response.send_redirect( web.url_for( controller='requests', + action='list', + status='error', + message="Invalid request ID") ) if operation == "show_request": - id = trans.security.decode_id(kwargs['id']) - return self.__show_request(trans, id, kwargs.get('add_sample', False)) + return self.__show_request( trans, **kwd ) elif operation == "submit": - id = trans.security.decode_id(kwargs['id']) - return self.__submit_request(trans, id) + return self.__submit_request( trans, **kwd ) elif operation == "delete": - id = trans.security.decode_id(kwargs['id']) - return self.__delete_request(trans, id) + return self.__delete_request( trans, **kwd ) elif operation == "undelete": - id = trans.security.decode_id(kwargs['id']) - return self.__undelete_request(trans, id) + return self.__undelete_request( trans, **kwd ) elif operation == "edit": - id = trans.security.decode_id(kwargs['id']) - return self.__edit_request(trans, id) - if 'show_filter' in kwargs.keys(): - if kwargs['show_filter'] == 'All': - self.request_grid.default_filter = {} - elif kwargs['show_filter'] == 'Deleted': - self.request_grid.default_filter = dict(deleted=True) - else: - self.request_grid.default_filter = dict(state=kwargs['show_filter'], deleted=False) - self.request_grid.show_filter = kwargs.get('show_filter', trans.app.model.Request.states.UNSUBMITTED) + return self.__edit_request( trans, **kwd ) # Render the list view - return self.request_grid( trans, **kwargs ) + return self.request_grid( trans, **kwd ) - def __show_request(self, trans, id, add_sample=False): + def __show_request(self, trans, **kwd): + params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) + add_sample = params.get('add_sample', False) try: - request = trans.sa_session.query( trans.app.model.Request ).get( id ) + request = trans.sa_session.query( trans.app.model.Request ).get( trans.security.decode_id(kwd['id']) ) except: return trans.response.send_redirect( web.url_for( controller='requests', action='list', status='error', - message="Invalid request ID", - **kwd) ) + message="Invalid request ID" ) ) current_samples = [] for s in request.samples: current_samples.append([s.name, s.values.content]) @@ -122,10 +167,11 @@ current_samples.append(['Sample_%i' % (len(current_samples)+1),['' for field in request.type.sample_form.fields]]) return trans.fill_template( '/requests/show_request.mako', request=request, - request_details=self.request_details(trans, id), + request_details=self.request_details(trans, request.id), current_samples = current_samples, sample_copy=self.__copy_sample(current_samples), - details='hide', edit_mode='False') + details='hide', edit_mode='False', + msg=msg, messagetype=messagetype ) def request_details(self, trans, id): ''' Shows the request details @@ -685,7 +731,7 @@ message="Invalid request ID", **kwd) ) if params.get('show', False) == 'True': - return self.__edit_request(trans, request.id, **kwd) + return self.__edit_request(trans, **kwd) elif params.get('save_changes_request_button', False) == 'Save changes' \ or params.get('edit_samples_button', False) == 'Edit samples': request_type = trans.sa_session.query( trans.app.model.RequestType ).get( int( params.select_request_type ) ) @@ -714,11 +760,11 @@ messagetype='done', **new_kwd) ) elif params.get('refresh', False) == 'true': - return self.__edit_request(trans, request.id, **kwd) + return self.__edit_request(trans, **kwd) - def __edit_request(self, trans, id, **kwd): + def __edit_request(self, trans, **kwd): try: - request = trans.sa_session.query( trans.app.model.Request ).get( id ) + request = trans.sa_session.query( trans.app.model.Request ).get( trans.security.decode_id(kwd['id']) ) except: msg = "Invalid request ID" log.warn( msg ) @@ -758,59 +804,61 @@ msg=msg, messagetype=messagetype) return self.__show_request_form(trans) - def __delete_request(self, trans, id): - try: - request = trans.sa_session.query( trans.app.model.Request ).get( id ) - except: - msg = "Invalid request ID" - log.warn( msg ) - return trans.response.send_redirect( web.url_for( controller='requests', - action='list', - status='error', - message=msg, - **kwd) ) - # change request's submitted field - if not request.unsubmitted(): - return trans.response.send_redirect( web.url_for( controller='requests', - action='list', - status='error', - message='This request cannot be deleted as it is already been submitted', - **kwd) ) - request.deleted = True - trans.sa_session.add( request ) - trans.sa_session.flush() - kwd = {} - kwd['id'] = trans.security.encode_id(request.id) + def __delete_request(self, trans, **kwd): + id_list = util.listify( kwd['id'] ) + delete_failed = [] + for id in id_list: + try: + request = trans.sa_session.query( trans.app.model.Request ).get( trans.security.decode_id(id) ) + except: + msg = "Invalid request ID" + log.warn( msg ) + return trans.response.send_redirect( web.url_for( controller='requests', + action='list', + status='error', + message=msg, + **kwd) ) + # a request cannot be deleted once its submitted + if not request.unsubmitted(): + delete_failed.append(request.name) + else: + request.deleted = True + trans.sa_session.add( request ) + trans.sa_session.flush() + if not len(delete_failed): + msg = '%i request(s) has been deleted.' % len(id_list) + status = 'done' + else: + msg = '%i request(s) has been deleted. %i request %s could not be deleted as they have been submitted.' % (len(id_list)-len(delete_failed), + len(delete_failed), str(delete_failed)) + status = 'warning' + return trans.response.send_redirect( web.url_for( controller='requests', + action='list', + status=status, + message=msg) ) + def __undelete_request(self, trans, **kwd): + id_list = util.listify( kwd['id'] ) + for id in id_list: + try: + request = trans.sa_session.query( trans.app.model.Request ).get( trans.security.decode_id(id) ) + except: + msg = "Invalid request ID" + log.warn( msg ) + return trans.response.send_redirect( web.url_for( controller='requests', + action='list', + status='error', + message=msg, + **kwd) ) + request.deleted = False + trans.sa_session.add( request ) + trans.sa_session.flush() return trans.response.send_redirect( web.url_for( controller='requests', action='list', status='done', - message='The request <b>%s</b> has been deleted.' % request.name, - **kwd) ) - def __undelete_request(self, trans, id): + message='%i request(s) has been undeleted.' % len(id_list) ) ) + def __submit_request(self, trans, **kwd): try: - request = trans.sa_session.query( trans.app.model.Request ).get( id ) - except: - msg = "Invalid request ID" - log.warn( msg ) - return trans.response.send_redirect( web.url_for( controller='requests', - action='list', - status='error', - message=msg, - **kwd) ) - # change request's submitted field - request.deleted = False - trans.sa_session.add( request ) - trans.sa_session.flush() - kwd = {} - kwd['id'] = trans.security.encode_id(request.id) - return trans.response.send_redirect( web.url_for( controller='requests', - action='list', - status='done', - message='The request <b>%s</b> has been undeleted.' % request.name, - **kwd) ) - def __submit_request(self, trans, id): - try: - request = trans.sa_session.query( trans.app.model.Request ).get( id ) + request = trans.sa_session.query( trans.app.model.Request ).get( trans.security.decode_id(kwd['id']) ) except: msg = "Invalid request ID" log.warn( msg ) @@ -837,14 +885,12 @@ request.state = request.states.SUBMITTED trans.sa_session.add( request ) trans.sa_session.flush() - kwd = {} - kwd['id'] = trans.security.encode_id(request.id) - kwd['status'] = 'done' - kwd['message'] = 'The request <b>%s</b> has been submitted.' % request.name return trans.response.send_redirect( web.url_for( controller='requests', action='list', - show_filter=trans.app.model.Request.states.SUBMITTED, - **kwd) ) + id=trans.security.encode_id(request.id), + status='done', + message='The request <b>%s</b> has been submitted.' % request.name + ) ) @web.expose @web.require_login( "create/submit sequencing requests" ) def show_events(self, trans, **kwd): diff -r 56bb85457bc1 -r ed8972386675 lib/galaxy/web/controllers/requests_admin.py --- a/lib/galaxy/web/controllers/requests_admin.py Tue Nov 17 13:43:34 2009 -0500 +++ b/lib/galaxy/web/controllers/requests_admin.py Tue Nov 17 14:28:34 2009 -0500 @@ -15,63 +15,187 @@ # ---- Request Grid ------------------------------------------------------------ # -class RequestsListGrid( grids.Grid ): +class RequestsGrid( grids.Grid ): + # Custom column types + class NameColumn( grids.TextColumn ): + def get_value(self, trans, grid, request): + return request.name + class DescriptionColumn( grids.TextColumn ): + def get_value(self, trans, grid, request): + return request.desc + class SamplesColumn( grids.GridColumn ): + def get_value(self, trans, grid, request): + return str(len(request.samples)) + class TypeColumn( grids.TextColumn ): + def get_value(self, trans, grid, request): + return request.type.name + class LastUpdateColumn( grids.TextColumn ): + def get_value(self, trans, grid, request): + return request.update_time + class StateColumn( grids.GridColumn ): + def filter( self, db_session, query, column_filter ): + """ Modify query to filter request by state. """ + if column_filter == "All": + return query + if column_filter: + query = query.filter( model.Request.state == column_filter ) + return query + def get_accepted_filters( self ): + """ Returns a list of accepted filters for this column. """ + accepted_filter_labels_and_vals = [ model.Request.states.UNSUBMITTED, + model.Request.states.SUBMITTED, + model.Request.states.COMPLETE, + "All"] + accepted_filters = [] + for val in accepted_filter_labels_and_vals: + label = val.lower() + args = { self.key: val } + accepted_filters.append( grids.GridColumnFilter( label, args) ) + return accepted_filters + class UserColumn( grids.TextColumn ): + def get_value(self, trans, grid, request): + return request.user.email + class DeletedColumn( grids.GridColumn ): + def get_accepted_filters( self ): + """ Returns a list of accepted filters for this column. """ + accepted_filter_labels_and_vals = { "active" : "False", "deleted" : "True", "all": "All" } + accepted_filters = [] + for label, val in accepted_filter_labels_and_vals.items(): + args = { self.key: val } + accepted_filters.append( grids.GridColumnFilter( label, args) ) + return accepted_filters + # Grid definition title = "Sequencing Requests" template = "admin/requests/grid.mako" model_class = model.Request default_sort_key = "-create_time" - show_filter = model.Request.states.SUBMITTED + num_rows_per_page = 50 + preserve_state = True + use_paging = True + default_filter = dict( deleted="False", state=model.Request.states.SUBMITTED) columns = [ - grids.GridColumn( "Name", key="name", - link=( lambda item: iff( item.deleted, None, dict( operation="show_request", id=item.id ) ) ), - attach_popup=True ), - grids.GridColumn( "Description", key="desc"), - grids.GridColumn( "Sample(s)", method='number_of_samples', - link=( lambda item: iff( item.deleted, None, dict( operation="show_request", id=item.id ) ) ), ), - grids.GridColumn( "Type", key="request_type_id", method='get_request_type'), - grids.GridColumn( "Last update", key="update_time", format=time_ago ), - grids.GridColumn( "State", key='state'), - grids.GridColumn( "User", key="user_id", method='get_user') - + NameColumn( "Name", + key="name", + model_class=model.Request, + link=( lambda item: iff( item.deleted, None, dict( operation="show_request", id=item.id ) ) ), + attach_popup=True, + filterable="advanced" ), + DescriptionColumn( "Description", + key='desc', + model_class=model.Request, + filterable="advanced" ), + SamplesColumn( "Sample(s)", + link=( lambda item: iff( item.deleted, None, dict( operation="show_request", id=item.id ) ) ), ), + TypeColumn( "Type" ), + LastUpdateColumn( "Last update", + format=time_ago ), + StateColumn( "State", + key='state', + filterable="advanced"), + UserColumn( "User", + key='user.email', + model_class=model.Request, + filterable="advanced" ), + DeletedColumn( "Deleted", + key="deleted", + visible=True, + filterable="advanced" ) ] + columns.append( grids.MulticolFilterColumn( "Search", + cols_to_filter=[ columns[0], columns[1], columns[6] ], + key="free-text-search", + visible=False, + filterable="standard" ) ) operations = [ grids.GridOperation( "Submit", allow_multiple=False, condition=( lambda item: not item.deleted and item.unsubmitted() and item.samples ) ), grids.GridOperation( "Edit", allow_multiple=False, condition=( lambda item: not item.deleted ) ), grids.GridOperation( "Reject", allow_multiple=False, condition=( lambda item: not item.deleted and item.submitted() ) ), - grids.GridOperation( "Delete", allow_multiple=False, condition=( lambda item: not item.deleted and item.unsubmitted() ) ), + grids.GridOperation( "Delete", allow_multiple=True, condition=( lambda item: not item.deleted and item.unsubmitted() ) ), grids.GridOperation( "Undelete", condition=( lambda item: item.deleted ) ), ] - standard_filters = [ - grids.GridColumnFilter( model.Request.states.UNSUBMITTED, - args=dict( state=model.Request.states.UNSUBMITTED, deleted=False ) ), - grids.GridColumnFilter( model.Request.states.SUBMITTED, - args=dict( state=model.Request.states.SUBMITTED, deleted=False ) ), - grids.GridColumnFilter( model.Request.states.COMPLETE, args=dict( state=model.Request.states.COMPLETE, deleted=False ) ), - grids.GridColumnFilter( "Deleted", args=dict( deleted=True ) ), - grids.GridColumnFilter( "All", args=dict( deleted=False ) ) + global_actions = [ + grids.GridAction( "Create new request", dict( controller='requests_admin', + action='new', + select_request_type='True' ) ) ] - def get_user(self, trans, request): - return trans.sa_session.query( trans.app.model.User ).get( request.user_id ).email - def get_current_item( self, trans ): - return None - def get_request_type(self, trans, request): - request_type = trans.sa_session.query( trans.app.model.RequestType ).get( request.request_type_id ) - return request_type.name - def number_of_samples(self, trans, request): - return str(len(request.samples)) - def apply_default_filter( self, trans, query, **kwargs ): - if self.default_filter: - return query.filter_by( **self.default_filter ) - else: - return query - + +# +# ---- Request Type Gridr ------------------------------------------------------ +# +class RequestTypeGrid( grids.Grid ): + # Custom column types + class NameColumn( grids.TextColumn ): + def get_value(self, trans, grid, request_type): + return request_type.name + class DescriptionColumn( grids.TextColumn ): + def get_value(self, trans, grid, request_type): + return request_type.desc + class RequestFormColumn( grids.TextColumn ): + def get_value(self, trans, grid, request_type): + return request_type.request_form.name + class SampleFormColumn( grids.TextColumn ): + def get_value(self, trans, grid, request_type): + return request_type.sample_form.name + class DeletedColumn( grids.GridColumn ): + def get_accepted_filters( self ): + """ Returns a list of accepted filters for this column. """ + accepted_filter_labels_and_vals = { "active" : "False", "deleted" : "True", "all": "All" } + accepted_filters = [] + for label, val in accepted_filter_labels_and_vals.items(): + args = { self.key: val } + accepted_filters.append( grids.GridColumnFilter( label, args) ) + return accepted_filters + # Grid definition + title = "Requests Types" + template = "admin/requests/manage_request_types.mako" + model_class = model.RequestType + default_sort_key = "-create_time" + num_rows_per_page = 50 + preserve_state = True + use_paging = True + default_filter = dict( deleted="False" ) + columns = [ + NameColumn( "Name", + key="name", + model_class=model.RequestType, + link=( lambda item: iff( item.deleted, None, dict( operation="view", id=item.id ) ) ), + attach_popup=True, + filterable="advanced" ), + DescriptionColumn( "Description", + key='desc', + model_class=model.Request, + filterable="advanced" ), + RequestFormColumn( "Request Form", + link=( lambda item: iff( item.deleted, None, dict( operation="view_form", id=item.request_form.id ) ) ), ), + SampleFormColumn( "Sample Form", + link=( lambda item: iff( item.deleted, None, dict( operation="view_form", id=item.sample_form.id ) ) ), ), + DeletedColumn( "Deleted", + key="deleted", + visible=False, + filterable="advanced" ) + ] + columns.append( grids.MulticolFilterColumn( "Search", + cols_to_filter=[ columns[0], columns[1] ], + key="free-text-search", + visible=False, + filterable="standard" ) ) + operations = [ + #grids.GridOperation( "Update", allow_multiple=False, condition=( lambda item: not item.deleted ) ), + grids.GridOperation( "Delete", allow_multiple=True, condition=( lambda item: not item.deleted ) ), + grids.GridOperation( "Undelete", condition=( lambda item: item.deleted ) ), + ] + global_actions = [ + grids.GridAction( "Create new request type", dict( controller='requests_admin', + action='create_request_type' ) ) + ] # # ---- Request Controller ------------------------------------------------------ # class Requests( BaseController ): - request_grid = RequestsListGrid() + request_grid = RequestsGrid() + requesttype_grid = RequestTypeGrid() @web.expose @web.require_admin @@ -80,67 +204,59 @@ @web.expose @web.require_admin - def list( self, trans, **kwargs ): + def list( self, trans, **kwd ): ''' List all request made by the current user ''' - message = util.restore_text( kwargs.get( 'message', '' ) ) - status = kwargs.get( 'status', 'done' ) - self.request_grid.default_filter = dict(state=trans.app.model.Request.states.SUBMITTED, - deleted=False) - if 'operation' in kwargs: - operation = kwargs['operation'].lower() + if 'operation' in kwd: + operation = kwd['operation'].lower() + if not kwd.get( 'id', None ): + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='list', + status='error', + message="Invalid request ID") ) if operation == "show_request": - id = trans.security.decode_id(kwargs['id']) - return self.__show_request(trans, id, status, message) + return self.__show_request( trans, **kwd ) elif operation == "submit": - id = trans.security.decode_id(kwargs['id']) - return self.__submit_request(trans, id) + return self.__submit_request( trans, **kwd ) + elif operation == "delete": + return self.__delete_request( trans, **kwd ) + elif operation == "undelete": + return self.__undelete_request( trans, **kwd ) elif operation == "edit": - id = trans.security.decode_id(kwargs['id']) - return self.__edit_request(trans, id) - elif operation == "delete": - id = trans.security.decode_id(kwargs['id']) - return self.__delete_request(trans, id) - elif operation == "undelete": - id = trans.security.decode_id(kwargs['id']) - return self.__undelete_request(trans, id) + return self.__edit_request( trans, **kwd ) elif operation == "reject": - id = trans.security.decode_id(kwargs['id']) - return self.__reject_request(trans, id) - if 'show_filter' in kwargs.keys(): - if kwargs['show_filter'] == 'All': - self.request_grid.default_filter = {} - elif kwargs['show_filter'] == 'Deleted': - self.request_grid.default_filter = dict(deleted=True) - else: - self.request_grid.default_filter = dict(state=kwargs['show_filter'], deleted=False) - self.request_grid.show_filter = kwargs.get('show_filter', trans.app.model.Request.states.SUBMITTED) - # Render the list view - return self.request_grid( trans, **kwargs ) - def __show_request(self, trans, id, messagetype, msg): + return self.__reject_request( trans, **kwd ) + # Render the grid view + return self.request_grid( trans, **kwd ) + def __show_request(self, trans, **kwd): + params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) + add_sample = params.get('add_sample', False) try: - request = trans.sa_session.query( trans.app.model.Request ).get( id ) + request = trans.sa_session.query( trans.app.model.Request ).get( trans.security.decode_id(kwd['id']) ) except: return trans.response.send_redirect( web.url_for( controller='requests_admin', action='list', status='error', - message="Invalid request ID", - **kwd) ) + message="Invalid request ID") ) current_samples = [] for s in request.samples: current_samples.append([s.name, s.values.content]) + if add_sample: + current_samples.append(['Sample_%i' % (len(current_samples)+1),['' for field in request.type.sample_form.fields]]) return trans.fill_template( '/admin/requests/show_request.mako', request=request, - request_details=self.request_details(trans, id), + request_details=self.request_details(trans, request.id), current_samples = current_samples, sample_copy=self.__copy_sample(current_samples), details='hide', edit_mode='False', - msg=msg, messagetype=messagetype) + msg=msg, messagetype=messagetype ) - def __edit_request(self, trans, id, **kwd): + def __edit_request(self, trans, **kwd): try: - request = trans.sa_session.query( trans.app.model.Request ).get( id ) + request = trans.sa_session.query( trans.app.model.Request ).get( trans.security.decode_id(kwd['id']) ) except: msg = "Invalid request ID" log.warn( msg ) @@ -180,61 +296,61 @@ msg=msg, messagetype=messagetype) return self.__show_request_form(trans) - def __delete_request(self, trans, id): - try: - request = trans.sa_session.query( trans.app.model.Request ).get( id ) - except: - msg = "Invalid request ID" - log.warn( msg ) - return trans.response.send_redirect( web.url_for( controller='requests_admin', - action='list', - status='error', - message=msg, - **kwd) ) - # change request's submitted field - if not request.unsubmitted(): - return trans.response.send_redirect( web.url_for( controller='requests_admin', - action='list', - status='error', - message='This request cannot be deleted as it is already been submitted', - **kwd) ) - request.deleted = True - trans.sa_session.add( request ) - trans.sa_session.flush() - kwd = {} - kwd['id'] = trans.security.encode_id(request.id) + def __delete_request(self, trans, **kwd): + id_list = util.listify( kwd['id'] ) + delete_failed = [] + for id in id_list: + try: + request = trans.sa_session.query( trans.app.model.Request ).get( trans.security.decode_id(id) ) + except: + msg = "Invalid request ID" + log.warn( msg ) + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='list', + status='error', + message=msg, + **kwd) ) + # a request cannot be deleted once its submitted + if not request.unsubmitted(): + delete_failed.append(request.name) + else: + request.deleted = True + trans.sa_session.add( request ) + trans.sa_session.flush() + if not len(delete_failed): + msg = '%i request(s) has been deleted.' % len(id_list) + status = 'done' + else: + msg = '%i request(s) has been deleted. %i request %s could not be deleted as they have been submitted.' % (len(id_list)-len(delete_failed), + len(delete_failed), str(delete_failed)) + status = 'warning' return trans.response.send_redirect( web.url_for( controller='requests_admin', action='list', - show_filter=trans.app.model.Request.states.UNSUBMITTED, - status='done', - message='The request <b>%s</b> has been deleted.' % request.name, - **kwd) ) - def __undelete_request(self, trans, id): - try: - request = trans.sa_session.query( trans.app.model.Request ).get( id ) - except: - msg = "Invalid request ID" - log.warn( msg ) - return trans.response.send_redirect( web.url_for( controller='requests_admin', - action='list', - status='error', - message=msg, - **kwd) ) - # change request's submitted field - request.deleted = False - trans.sa_session.add( request ) - trans.sa_session.flush() - kwd = {} - kwd['id'] = trans.security.encode_id(request.id) + status=status, + message=msg) ) + def __undelete_request(self, trans, **kwd): + id_list = util.listify( kwd['id'] ) + for id in id_list: + try: + request = trans.sa_session.query( trans.app.model.Request ).get( trans.security.decode_id(id) ) + except: + msg = "Invalid request ID" + log.warn( msg ) + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='list', + status='error', + message=msg, + **kwd) ) + request.deleted = False + trans.sa_session.add( request ) + trans.sa_session.flush() return trans.response.send_redirect( web.url_for( controller='requests_admin', action='list', - show_filter=trans.app.model.Request.states.UNSUBMITTED, status='done', - message='The request <b>%s</b> has been undeleted.' % request.name, - **kwd) ) - def __submit_request(self, trans, id): + message='%i request(s) has been undeleted.' % len(id_list) ) ) + def __submit_request(self, trans, **kwd): try: - request = trans.sa_session.query( trans.app.model.Request ).get( id ) + request = trans.sa_session.query( trans.app.model.Request ).get( trans.security.decode_id(kwd['id']) ) except: msg = "Invalid request ID" log.warn( msg ) @@ -260,15 +376,32 @@ request.state = request.states.SUBMITTED trans.sa_session.add( request ) trans.sa_session.flush() - kwd = {} - kwd['id'] = trans.security.encode_id(request.id) - kwd['status'] = 'done' - kwd['message'] = 'The request <b>%s</b> has been submitted.' % request.name return trans.response.send_redirect( web.url_for( controller='requests_admin', action='list', - show_filter=trans.app.model.Request.states.SUBMITTED, - **kwd) ) - + id=trans.security.encode_id(request.id), + status='done', + message='The request <b>%s</b> has been submitted.' % request.name + ) ) + def __reject_request(self, trans, **kwd): + try: + request = trans.sa_session.query( trans.app.model.Request ).get( trans.security.decode_id(kwd['id']) ) + except: + msg = "Invalid request ID" + log.warn( msg ) + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='list', + status='error', + message=msg, + **kwd) ) + # change request's submitted field + request.state = request.states.UNSUBMITTED + trans.sa_session.add( request ) + trans.sa_session.flush() + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='list', + status='done', + message='The request <b>%s</b> is now unsubmitted.' % request.name + ) ) # #---- Request Creation ---------------------------------------------------------- # @@ -325,7 +458,6 @@ if params.get('create_request_button', False) == 'Save': return trans.response.send_redirect( web.url_for( controller='requests_admin', action='list', - show_filter=trans.app.model.Request.states.UNSUBMITTED, message=msg , status='done') ) elif params.get('create_request_samples_button', False) == 'Add samples': @@ -664,29 +796,6 @@ **new_kwd) ) elif params.get('refresh', False) == 'true': return self.__edit_request(trans, request.id, **kwd) - def __reject_request(self, trans, id): - try: - request = trans.sa_session.query( trans.app.model.Request ).get( id ) - except: - msg = "Invalid request ID" - log.warn( msg ) - return trans.response.send_redirect( web.url_for( controller='requests_admin', - action='list', - status='error', - message=msg, - **kwd) ) - # change request's submitted field - request.state = request.states.UNSUBMITTED - trans.sa_session.add( request ) - trans.sa_session.flush() - kwd = {} - kwd['id'] = trans.security.encode_id(request.id) - kwd['status'] = 'done' - kwd['message'] = 'The request <b>%s</b> is now unsubmitted.' % request.name - return trans.response.send_redirect( web.url_for( controller='requests_admin', - action='list', - show_filter=trans.app.model.Request.states.UNSUBMITTED, - **kwd) ) def __update_samples(self, request, **kwd): ''' This method retrieves all the user entered sample information and @@ -1049,8 +1158,8 @@ action='list', operation='show_request', id=trans.security.encode_id(request.id), - message='Bar codes have been saved for this request', - status='done')) + msg='Bar codes have been saved for this request', + messagetype='done')) def __set_request_state( self, trans, request ): # check if all the samples of the current request are in the final state complete = True @@ -1138,50 +1247,72 @@ ## @web.expose @web.require_admin - def manage_request_types( self, trans, **kwd ): - params = util.Params( kwd ) - msg = util.restore_text( params.get( 'msg', '' ) ) - messagetype = params.get( 'messagetype', 'done' ) - show_filter = util.restore_text( params.get( 'show_filter', 'Active' ) ) - forms = get_all_forms(trans, all_versions=True) - request_types_list = trans.sa_session.query( trans.app.model.RequestType ) - if show_filter == 'All': - request_types = request_types_list - elif show_filter == 'Deleted': - request_types = [rt for rt in request_types_list if rt.deleted] - else: - request_types = [rt for rt in request_types_list if not rt.deleted] - return trans.fill_template( '/admin/requests/manage_request_types.mako', - request_types=request_types, - forms=forms, - show_filter=show_filter, - msg=msg, - messagetype=messagetype ) + def manage_request_types( self, trans, **kwd ): + if 'operation' in kwd: + operation = kwd['operation'].lower() + if not kwd.get( 'id', None ): + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='manage_request_types', + status='error', + message="Invalid requesttype ID") ) + if operation == "view": + return self.__view_request_type( trans, **kwd ) + elif operation == "view_form": + return self.__view_form( trans, **kwd ) + elif operation == "delete": + return self.__delete_request_type( trans, **kwd ) + elif operation == "undelete": + return self.__undelete_request_type( trans, **kwd ) +# elif operation == "update": +# return self.__edit_request( trans, **kwd ) + # Render the grid view + return self.requesttype_grid( trans, **kwd ) + def __view_request_type(self, trans, **kwd): + try: + rt = trans.sa_session.query( trans.app.model.RequestType ).get( trans.security.decode_id(kwd['id']) ) + except: + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='manage_request_types', + status='error', + message="Invalid requesttype ID") ) + return trans.fill_template( '/admin/requests/view_request_type.mako', + request_type=rt, + forms=get_all_forms( trans ), + states_list=rt.states ) + def __view_form(self, trans, **kwd): + try: + fd = trans.sa_session.query( trans.app.model.FormDefinition ).get( trans.security.decode_id(kwd['id']) ) + except: + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='manage_request_types', + status='error', + message="Invalid form ID") ) + return trans.fill_template( '/admin/forms/show_form_read_only.mako', + form=fd ) + @web.expose @web.require_admin - def request_type( self, trans, **kwd ): + def create_request_type( self, trans, **kwd ): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) - if params.get( 'create', False ): + if params.get( 'add_state_button', False ): + rt_info, rt_states = self.__create_request_type_form(trans, **kwd) + rt_states.append(("", "")) return trans.fill_template( '/admin/requests/create_request_type.mako', - request_forms=get_all_forms( trans, - filter=dict(deleted=False), - form_type=trans.app.model.FormDefinition.types.REQUEST ), - sample_forms=get_all_forms( trans, - filter=dict(deleted=False), - form_type=trans.app.model.FormDefinition.types.SAMPLE ), + rt_info_widgets=rt_info, + rt_states_widgets=rt_states, msg=msg, messagetype=messagetype) - elif params.get( 'define_states_button', False ): - return trans.fill_template( '/admin/requests/add_states.mako', - request_type_name=util.restore_text( params.name ), - desc=util.restore_text( params.description ), - num_states=int(util.restore_text( params.num_states )), - request_form_id=int(util.restore_text( params.request_form_id )), - sample_form_id=int(util.restore_text( params.sample_form_id )), + elif params.get( 'remove_state_button', False ): + rt_info, rt_states = self.__create_request_type_form(trans, **kwd) + index = int(params.get( 'remove_state_button', '' ).split(" ")[2]) + del rt_states[index-1] + return trans.fill_template( '/admin/requests/create_request_type.mako', + rt_info_widgets=rt_info, + rt_states_widgets=rt_states, msg=msg, - messagetype=messagetype) + messagetype=messagetype) elif params.get( 'save_request_type', False ): st, msg = self.__save_request_type(trans, **kwd) if not st: @@ -1191,32 +1322,65 @@ messagetype='error') return trans.response.send_redirect( web.url_for( controller='requests_admin', action='manage_request_types', - msg='Request type <b>%s</b> has been created' % st.name, - messagetype='done') ) - elif params.get('view', False): - rt = trans.sa_session.query( trans.app.model.RequestType ).get( int( util.restore_text( params.id ) ) ) - return trans.fill_template( '/admin/requests/view_request_type.mako', - request_type=rt, - forms=get_all_forms( trans ), - states_list=rt.states, - deleted=False, - show_deleted=False, + message='Request type <b>%s</b> has been created' % st.name, + status='done') ) + else: + rt_info, rt_states = self.__create_request_type_form(trans, **kwd) + return trans.fill_template( '/admin/requests/create_request_type.mako', + rt_info_widgets=rt_info, + rt_states_widgets=rt_states, msg=msg, - messagetype=messagetype ) + messagetype=messagetype) + def __create_request_type_form(self, trans, **kwd): + request_forms=get_all_forms( trans, + filter=dict(deleted=False), + form_type=trans.app.model.FormDefinition.types.REQUEST ) + sample_forms=get_all_forms( trans, + filter=dict(deleted=False), + form_type=trans.app.model.FormDefinition.types.SAMPLE ) + if not len(request_forms) or not len(sample_forms): + return [],[] + params = util.Params( kwd ) + rt_info = [] + rt_info.append(dict(label='Name', + widget=TextField('name', 40, util.restore_text( params.get( 'name', '' ) ) ) )) + rt_info.append(dict(label='Description', + widget=TextField('desc', 40, util.restore_text( params.get( 'desc', '' ) ) ) )) + + rf_selectbox = SelectField('request_form_id') + for fd in request_forms: + if str(fd.id) == params.get( 'request_form_id', '' ): + rf_selectbox.add_option(fd.name, fd.id, selected=True) + else: + rf_selectbox.add_option(fd.name, fd.id) + rt_info.append(dict(label='Request form', + widget=rf_selectbox )) + + sf_selectbox = SelectField('sample_form_id') + for fd in sample_forms: + if str(fd.id) == params.get( 'sample_form_id', '' ): + sf_selectbox.add_option(fd.name, fd.id, selected=True) + else: + sf_selectbox.add_option(fd.name, fd.id) + rt_info.append(dict(label='Sample form', + widget=sf_selectbox )) + # possible sample states + rt_states = [] + i=0 + while True: + if kwd.has_key( 'state_name_%i' % i ): + rt_states.append((params.get( 'state_name_%i' % i, '' ), + params.get( 'state_desc_%i' % i, '' ))) + i=i+1 + else: + break + return rt_info, rt_states + def __save_request_type(self, trans, **kwd): params = util.Params( kwd ) - num_states = int( util.restore_text( params.get( 'num_states', 0 ) )) - proceed = True - for i in range( num_states ): - if not util.restore_text( params.get( 'state_name_%i' % i, None ) ): - proceed = False - break - if not proceed: - msg = "All the state name(s) must be completed." - return None, msg rt = trans.app.model.RequestType() - rt.name = util.restore_text( params.name ) - rt.desc = util.restore_text( params.description ) or "" + rt.name = util.restore_text( params.get( 'name', '' ) ) + rt.desc = util.restore_text( params.get( 'desc', '' ) ) rt.request_form = trans.sa_session.query( trans.app.model.FormDefinition ).get( int( params.request_form_id ) ) rt.sample_form = trans.sa_session.query( trans.app.model.FormDefinition ).get( int( params.sample_form_id ) ) trans.sa_session.add( rt ) @@ -1226,37 +1390,50 @@ for ss in ss_list: trans.sa_session.delete( ss ) trans.sa_session.flush() - for i in range( num_states ): - name = util.restore_text( params.get( 'state_name_%i' % i, None )) - desc = util.restore_text( params.get( 'state_desc_%i' % i, None )) - ss = trans.app.model.SampleState(name, desc, rt) - trans.sa_session.add( ss ) + i=0 + while True: + if kwd.has_key( 'state_name_%i' % i ): + name = util.restore_text( params.get( 'state_name_%i' % i, None )) + desc = util.restore_text( params.get( 'state_desc_%i' % i, None )) + ss = trans.app.model.SampleState(name, desc, rt) + trans.sa_session.add( ss ) + trans.sa_session.flush() + i = i + 1 + else: + break + msg = "The new request type named '%s' with %s state(s) has been created" % (rt.name, i) + return rt, msg + def __delete_request_type( self, trans, **kwd ): + id_list = util.listify( kwd['id'] ) + for id in id_list: + try: + rt = trans.sa_session.query( trans.app.model.RequestType ).get( trans.security.decode_id(id) ) + except: + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='manage_request_types', + msg='Invalid request type ID', + messagetype='error') ) + rt.deleted = True + trans.sa_session.add( rt ) trans.sa_session.flush() - msg = "The new request type named '%s' with %s state(s) has been created" % (rt.name, num_states) - return rt, msg - @web.expose - @web.require_admin - def delete_request_type( self, trans, **kwd ): - params = util.Params( kwd ) - msg = util.restore_text( params.get( 'msg', '' ) ) - messagetype = params.get( 'messagetype', 'done' ) - rt = trans.sa_session.query( trans.app.model.RequestType ).get( int( util.restore_text( params.request_type_id ) ) ) - rt.deleted = True - trans.sa_session.flush() return trans.response.send_redirect( web.url_for( controller='requests_admin', action='manage_request_types', - msg='Request type <b>%s</b> has been deleted' % rt.name, + msg='%i request type(s) has been deleted' % len(id_list), messagetype='done') ) - @web.expose - @web.require_admin - def undelete_request_type( self, trans, **kwd ): - params = util.Params( kwd ) - msg = util.restore_text( params.get( 'msg', '' ) ) - messagetype = params.get( 'messagetype', 'done' ) - rt = trans.sa_session.query( trans.app.model.RequestType ).get( int( util.restore_text( params.request_type_id ) ) ) - rt.deleted = False - trans.sa_session.flush() + def __undelete_request_type( self, trans, **kwd ): + id_list = util.listify( kwd['id'] ) + for id in id_list: + try: + rt = trans.sa_session.query( trans.app.model.RequestType ).get( trans.security.decode_id(id) ) + except: + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='manage_request_types', + msg='Invalid request type ID', + messagetype='error') ) + rt.deleted = False + trans.sa_session.add( rt ) + trans.sa_session.flush() return trans.response.send_redirect( web.url_for( controller='requests_admin', action='manage_request_types', - msg='Request type <b>%s</b> has been undeleted' % rt.name, + msg='%i request type(s) has been undeleted' % len(id_list), messagetype='done') ) diff -r 56bb85457bc1 -r ed8972386675 templates/admin/forms/edit_form.mako --- a/templates/admin/forms/edit_form.mako Tue Nov 17 13:43:34 2009 -0500 +++ b/templates/admin/forms/edit_form.mako Tue Nov 17 14:28:34 2009 -0500 @@ -85,7 +85,7 @@ <div class="toolForm"> <div class="toolFormTitle">Edit form definition "${form.name}"</div> - <form id="edit_form" name="edit_form" action="${h.url_for( controller='forms', action='edit', form_id=form.id )}" method="post" > + <form id="edit_form" name="edit_form" action="${h.url_for( controller='forms', action='manage', operation="Edit", id=trans.security.encode_id(form.current.id) )}" method="post" > %for label, input in form_details: <div class="form-row"> <label>${label}</label> diff -r 56bb85457bc1 -r ed8972386675 templates/admin/forms/grid.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/admin/forms/grid.mako Tue Nov 17 14:28:34 2009 -0500 @@ -0,0 +1,1 @@ +<%inherit file="/grid_base.mako"/> diff -r 56bb85457bc1 -r ed8972386675 templates/admin/forms/manage_forms.mako --- a/templates/admin/forms/manage_forms.mako Tue Nov 17 13:43:34 2009 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -<%inherit file="/base.mako"/> -<%namespace file="/message.mako" import="render_msg" /> - -<%def name="title()">Manage Form Definitions</%def> - -%if msg: - ${render_msg( msg, messagetype )} -%endif - -## Render a row -<%def name="render_row( form, ctr )"> - %if ctr % 2 == 1: - <tr class="odd_row"> - %else: - <tr> - %endif - <td> - <a href="${h.url_for( controller='forms', action='edit', form_id=form.id, read_only=True )}">${form.name}</a> - <a id="form-${form.id}-popup" class="popup-arrow" style="display: none;">▼</a> - %if form.form_definition_current.deleted: - <div popupmenu="form-${form.id}-popup"> - <a class="action-button" href="${h.url_for( action='undelete', form_id=form.id )}">Undelete</a> - </div> - %else: - <div popupmenu="form-${form.id}-popup"> - <a class="action-button" href="${h.url_for( action='edit', form_id=form.id, show_form=True )}">Edit</a> - <a class="action-button" confirm="Click OK to delete the form ${form.name}." href="${h.url_for( action='delete', form_id=form.id )}">Delete</a> - </div> - %endif - </td> - <td><i>${form.desc}</i></td> - <td>${form.type}</td> - </tr> -</%def> - -<h2>Forms</h2> - -<ul class="manage-table-actions"> - <li> - <a class="action-button" href="${h.url_for( controller='forms', action='new' )}"> - <span>Create a new form</span></a> - </li> -</ul> - -%if not all_forms: - There are no forms. -%else: - <div class="grid-header"> - %for i, filter in enumerate( ['Active', 'Deleted', 'All'] ): - %if i > 0: - <span>|</span> - %endif - %if show_filter == filter: - <span class="filter"><a href="${h.url_for( controller='forms', action='manage', show_filter=filter )}"><b>${filter}</b></a></span> - %else: - <span class="filter"><a href="${h.url_for( controller='forms', action='manage', show_filter=filter )}">${filter}</a></span> - %endif - %endfor - </div> - <table class="grid"> - <thead> - <tr> - <th>Name</th> - <th>Description</th> - <th>Type</th> - </tr> - </thead> - <tbody> - %for ctr, fdc in enumerate( fdc_list ): - <tr> - ${render_row( fdc.latest_form, ctr )} - </tr> - %endfor - </tbody> - </table> -%endif diff -r 56bb85457bc1 -r ed8972386675 templates/admin/forms/show_form_read_only.mako --- a/templates/admin/forms/show_form_read_only.mako Tue Nov 17 13:43:34 2009 -0500 +++ b/templates/admin/forms/show_form_read_only.mako Tue Nov 17 14:28:34 2009 -0500 @@ -66,14 +66,14 @@ <div class="toolFormTitle">${form.name} - <i> ${form.desc}</i> (${form.type}) <a id="form-${form.id}-popup" class="popup-arrow" style="display: none;">▼</a> <div popupmenu="form-${form.id}-popup"> - <a class="action-button" href="${h.url_for( action='edit', form_id=form.id, show_form=True )}">Edit</a> + <a class="action-button" href="${h.url_for( controller='forms', action='manage', operation='Edit', id=trans.security.encode_id(form.current.id) )}">Edit</a> </div> </div> %else: <div class="toolFormTitle">${form.name} (${form.type}) <a id="form-${form.id}-popup" class="popup-arrow" style="display: none;">▼</a> <div popupmenu="form-${form.id}-popup"> - <a class="action-button" href="${h.url_for( action='edit', form_id=form.id, show_form=True )}">Edit</a> + <a class="action-button" href="${h.url_for( controller='forms', action='manage', operation='Edit', id=trans.security.encode_id(form.current.id) )}">Edit</a> </div> </div> %endif diff -r 56bb85457bc1 -r ed8972386675 templates/admin/requests/create_request_type.mako --- a/templates/admin/requests/create_request_type.mako Tue Nov 17 13:43:34 2009 -0500 +++ b/templates/admin/requests/create_request_type.mako Tue Nov 17 14:28:34 2009 -0500 @@ -6,63 +6,59 @@ ${render_msg( msg, messagetype )} %endif +<%def name="render_state( element_count, state_name, state_desc )"> + <div class="repeat-group-item"> + <div class="form-row"> + <label>${1+element_count}. State name:</label> + <input type="text" name="state_name_${element_count}" value="${state_name}" size="40"/> + <input type="submit" name="remove_state_button" value="Remove state ${1+element_count}"/> + </div> + <div class="form-row"> + <label>Description:</label> + <input type="text" name="state_desc_${element_count}" value="${state_desc}" size="40"/> + <div class="toolParamHelp" style="clear: both;"> + optional + </div> + + </div> + <div style="clear: both"></div> + </div> +</%def> + <div class="toolForm"> <div class="toolFormTitle">Create a new request type</div> - %if not request_forms or not sample_forms: + %if not rt_info_widgets: Create a request & sample form definition first to create a new request type. %else: - <div class="toolFormBody"> - <form name="create_request_type" action="${h.url_for( controller='requests_admin', action='request_type')}" method="post" > + <form name="create_request_type" action="${h.url_for( controller='requests_admin', action='create_request_type')}" method="post" > + %for rt_info in rt_info_widgets: <div class="form-row"> - <label>Name:</label> + <label>${rt_info['label']}</label> <div style="float: left; width: 250px; margin-right: 10px;"> - <input type="text" name="name" value="New Request Type" size="40"/> + ${rt_info['widget'].get_html()} </div> <div style="clear: both"></div> </div> - <div class="form-row"> - <label>Description:</label> - <div style="float: left; width: 250px; margin-right: 10px;"> - <input type="text" name="description" value="" size="40"/> - </div> - <div style="clear: both"></div> + %endfor + <div class="toolFormTitle">Possible sample states</div> + %if len(rt_states_widgets): + %for index, info in enumerate(rt_states_widgets): + ${render_state( index, info[0], info[1] )} + %endfor + %endif + <div class="form-row"> + <input type="submit" name="add_state_button" value="Add state"/> + </div> + <div class="form-row"> + <div style="float: left; width: 250px; margin-right: 10px;"> + <input type="hidden" name="new" value="submitted" size="40"/> </div> - <div class="form-row"> - <label> - Request Form definition: - </label> - <select name="request_form_id"> - %for form in request_forms: - <option value="${form.id}">${form.name}</option> - %endfor - </select> - </div> - <div class="form-row"> - <label> - Sample Form definition: - </label> - <select name="sample_form_id"> - %for form in sample_forms: - <option value="${form.id}">${form.name}</option> - %endfor - </select> - </div> - <div class="form-row"> - <label>Number of sample states:</label> - <div style="float: left; width: 250px; margin-right: 10px;"> - <input type="text" size="3" name="num_states" value="1"/> - </div> - </div> - <div class="form-row"> - <div style="float: left; width: 250px; margin-right: 10px;"> - <input type="hidden" name="new" value="submitted" size="40"/> - </div> - <div style="clear: both"></div> - </div> - <div class="form-row"> - <input type="submit" name="define_states_button" value="Define states"/> - </div> - </form> - </div> + <div style="clear: both"></div> + </div> + <div class="form-row"> + <input type="submit" name="save_request_type" value="Save"/> + </div> + </form> + %endif </div> \ No newline at end of file diff -r 56bb85457bc1 -r ed8972386675 templates/admin/requests/grid.mako --- a/templates/admin/requests/grid.mako Tue Nov 17 13:43:34 2009 -0500 +++ b/templates/admin/requests/grid.mako Tue Nov 17 14:28:34 2009 -0500 @@ -1,217 +1,1 @@ -<%inherit file="/base.mako"/> -<%namespace file="/message.mako" import="render_msg" /> - -<%def name="title()">Browse Requests</%def> - -%if message: - <p> - <div class="${message_type}message transient-message">${message}</div> - <div style="clear: both"></div> - </p> -%endif - -<%def name="javascripts()"> - ${parent.javascripts()} - <script type="text/javascript"> - ## TODO: generalize and move into galaxy.base.js - $(document).ready(function() { - $(".grid").each( function() { - var grid = this; - var checkboxes = $(this).find("input.grid-row-select-checkbox"); - var update = $(this).find( "span.grid-selected-count" ); - $(checkboxes).each( function() { - $(this).change( function() { - var n = $(checkboxes).filter("[checked]").size(); - update.text( n ); - }); - }) - }); - }); - ## Can this be moved into base.mako? - %if refresh_frames: - %if 'masthead' in refresh_frames: - ## Refresh masthead == user changes (backward compatibility) - if ( parent.user_changed ) { - %if trans.user: - parent.user_changed( "${trans.user.email}", ${int( app.config.is_admin_user( trans.user ) )} ); - %else: - parent.user_changed( null, false ); - %endif - } - %endif - %if 'history' in refresh_frames: - if ( parent.frames && parent.frames.galaxy_history ) { - parent.frames.galaxy_history.location.href="${h.url_for( controller='root', action='history')}"; - if ( parent.force_right_panel ) { - parent.force_right_panel( 'show' ); - } - } - %endif - %if 'tools' in refresh_frames: - if ( parent.frames && parent.frames.galaxy_tools ) { - parent.frames.galaxy_tools.location.href="${h.url_for( controller='root', action='tool_menu')}"; - if ( parent.force_left_panel ) { - parent.force_left_panel( 'show' ); - } - } - %endif - %endif - </script> -</%def> - -<%def name="stylesheets()"> - <link href="${h.url_for('/static/style/base.css')}" rel="stylesheet" type="text/css" /> - <style> - ## Not generic to all grids -- move to base? - .count-box { - min-width: 1.1em; - padding: 5px; - border-width: 1px; - border-style: solid; - text-align: center; - display: inline-block; - } - </style> -</%def> - -<div class="grid-header"> - <h2>${grid.title}</h2> - %if trans.sa_session.query( trans.app.model.Request ).count(): - ##<span class="title">Filter:</span> - %for i, filter in enumerate( grid.standard_filters ): - %if i > 0: - <span>|</span> - %endif - %if grid.show_filter == filter.label: - <span class="filter"><a href="${h.url_for( controller='requests_admin', action='list', show_filter=filter.label )}"><b>${filter.label}</b></a></span> - %else: - <span class="filter"><a href="${h.url_for( controller='requests_admin', action='list', show_filter=filter.label )}">${filter.label}</a></span> - %endif - %endfor - %endif -</div> - -<ul class="manage-table-actions"> - <li> - <a class="action-button" href="${h.url_for( controller='requests_admin', action='new', select_request_type=True )}"> - <img src="${h.url_for('/static/images/silk/add.png')}" /> - <span>Create a new request</span></a> - </li> -</ul> - -%if not len(query.all()): - There are no requests. -%else: -<form name="history_actions" action="${url()}" method="post" > - <table class="grid"> - <thead> - <tr> - ##<th></th> - %for column in grid.columns: - %if column.visible: - <% - href = "" - extra = "" - if column.sortable: - if sort_key == column.key: - if sort_order == "asc": - href = url( sort=( "-" + column.key ) ) - extra = "↓" - else: - href = url( sort=( column.key ) ) - extra = "↑" - else: - href = url( sort=column.key ) - %> - <th\ - %if column.ncells > 1: - colspan="${column.ncells}" - %endif - > - %if href: - <a href="${href}">${column.label}</a> - %else: - ${column.label} - %endif - <span>${extra}</span> - </th> - %endif - %endfor - <th></th> - </tr> - </thead> - <tbody> - %for i, item in enumerate( query ): - <tr \ - %if current_item == item: - class="current" \ - %endif - > - ## Item selection column - ##<td style="width: 1.5em;"> - ## <input type="checkbox" name="id" value=${trans.security.encode_id( item.id )} class="grid-row-select-checkbox" /> - ##</td> - ## Data columns - %for column in grid.columns: - %if column.visible: - <% - # Link - if column.link and column.link( item ): - href = url( **column.link( item ) ) - else: - href = None - # Value (coerced to list so we can loop) - value = column.get_value( trans, grid, item ) - if column.ncells == 1: - value = [ value ] - %> - %for cellnum, v in enumerate( value ): - <% - # Attach popup menu? - if column.attach_popup and cellnum == 0: - extra = '<a id="grid-%d-popup" class="popup-arrow" style="display: none;">▼</a>' % i - else: - extra = "" - %> - %if href: - <td><a href="${href}">${v}</a> ${extra}</td> - %else: - <td >${v}${extra}</td> - %endif - </td> - %endfor - %endif - %endfor - ## Actions column - <td> - <div popupmenu="grid-${i}-popup"> - %for operation in grid.operations: - %if operation.allowed( item ): - %if operation.label == 'Submit': - <a class="action-button" confirm="More samples cannot be added to this request once it is submitted. Click OK to submit." href="${url( operation=operation.label, id=item.id )}">${operation.label}</a> - %else: - <a class="action-button" href="${url( operation=operation.label, id=item.id )}">${operation.label}</a> - %endif - %endif - %endfor - </div> - </td> - </tr> - %endfor - </tbody> -## <tfoot> -## <tr> -## <td></td> -## <td colspan="100"> -## For <span class="grid-selected-count"></span> selected requests: -## %for operation in grid.operations: -## %if operation.allow_multiple: -## <input type="submit" name="operation" value="${operation.label}" class="action-button"> -## %endif -## %endfor -## </td> -## </tr> -## </tfoot> - </table> -</form> -%endif \ No newline at end of file +<%inherit file="/grid_base.mako"/> \ No newline at end of file diff -r 56bb85457bc1 -r ed8972386675 templates/admin/requests/manage_request_types.mako --- a/templates/admin/requests/manage_request_types.mako Tue Nov 17 13:43:34 2009 -0500 +++ b/templates/admin/requests/manage_request_types.mako Tue Nov 17 14:28:34 2009 -0500 @@ -1,68 +1,1 @@ -<%inherit file="/base.mako"/> -<%namespace file="/message.mako" import="render_msg" /> - -<%def name="title()">request Types</%def> - -%if msg: - ${render_msg( msg, messagetype )} -%endif - -<h2> - Request Types -</h2> - -<ul class="manage-table-actions"> - <li> - <a class="action-button" href="${h.url_for( controller='requests_admin', action='request_type', create=True )}"><span>Create a new request type</span></a> - </li> -</ul> - -<div class="grid-header"> - ##<span class="title">Filter:</span> - %for i, filter in enumerate( ['Active', 'Deleted', 'All'] ): - %if i > 0: - <span>|</span> - %endif - %if show_filter == filter: - <span class="filter"><a href="${h.url_for( controller='requests_admin', action='manage_request_types', show_filter=filter )}"><b>${filter}</b></a></span> - %else: - <span class="filter"><a href="${h.url_for( controller='requests_admin', action='manage_request_types', show_filter=filter )}">${filter}</a></span> - %endif - %endfor -</div> -%if not request_types: - There are no request types. -%else: - <table class="grid"> - <thead> - <tr> - <th>Name</th> - <th>Description</th> - <th>Request Form</th> - <th>Sample Form</th> - </tr> - </thead> - <tbody> - %for request_type in request_types: - <tr> - <td> - <a href="${h.url_for( controller='requests_admin', action='request_type', view='True', id=request_type.id)}">${request_type.name}</a> - <a id="request_type-${request_type.id}-popup" class="popup-arrow" style="display: none;">▼</a> - %if request_type.deleted: - <div popupmenu="request_type-${request_type.id}-popup"> - <a class="action-button" href="${h.url_for( action='undelete_request_type', request_type_id=request_type.id )}">Undelete</a> - </div> - %else: - <div popupmenu="request_type-${request_type.id}-popup"> - <a class="action-button" confirm="Click OK to delete the request type ${request_type.name}." href="${h.url_for( action='delete_request_type', request_type_id=request_type.id )}">Delete</a> - </div> - %endif - </td> - <td><i>${request_type.desc}</i></td> - <td><a href="${h.url_for( controller='forms', action='edit', form_id=request_type.request_form.id, read_only=True)}">${request_type.request_form.name}</a></td> - <td><a href="${h.url_for( controller='forms', action='edit', form_id=request_type.sample_form.id, read_only=True)}">${request_type.sample_form.name}</a></td> - </tr> - %endfor - </tbody> - </table> -%endif \ No newline at end of file +<%inherit file="/grid_base.mako"/> \ No newline at end of file diff -r 56bb85457bc1 -r ed8972386675 templates/admin/requests/show_request.mako --- a/templates/admin/requests/show_request.mako Tue Nov 17 13:43:34 2009 -0500 +++ b/templates/admin/requests/show_request.mako Tue Nov 17 14:28:34 2009 -0500 @@ -127,7 +127,7 @@ <div class="form-row"> <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='requests_admin', action='edit', show=True, request_id=request.id)}"> + <a class="action-button" href="${h.url_for( controller='requests_admin', action='list', operation='Edit', id=trans.security.encode_id(request.id))}"> <span>Edit request details</span></a> </li> </ul> diff -r 56bb85457bc1 -r ed8972386675 templates/admin/requests/view_request_type.mako --- a/templates/admin/requests/view_request_type.mako Tue Nov 17 13:43:34 2009 -0500 +++ b/templates/admin/requests/view_request_type.mako Tue Nov 17 14:28:34 2009 -0500 @@ -7,43 +7,37 @@ %endif <div class="toolForm"> - <div class="toolFormTitle">View request type details</div> - <div class="toolFormBody"> - <form name="library"> - <div class="form-row"> - <label>Name</label> - ${request_type.name} + <div class="toolFormTitle">Request type information</div> + <form name="library"> + <div class="form-row"> + <label>Name</label> + ${request_type.name} + <div style="clear: both"></div> + </div> + <div class="form-row"> + <label>Description</label> + ${request_type.desc} + <div style="clear: both"></div> + </div> + <div class="form-row"> + <label> + Request Form definition + </label> + ${request_type.request_form.name} + </div> + <div class="form-row"> + <label> + Sample Form definition + </label> + ${request_type.sample_form.name} + </div> + <div class="toolFormTitle">Possible sample states</div> + %for element_count, state in enumerate(states_list): + <div class="form-row"> + <label>${1+element_count}. ${state.name}</label> + ${state.desc} + </div> <div style="clear: both"></div> - </div> - <div class="form-row"> - <label>Description</label> - ${request_type.desc} - <div style="clear: both"></div> - </div> - <div class="form-row"> - <label> - Request Form definition - </label> - ${request_type.request_form.name} - </div> - <div class="form-row"> - <label> - Sample Form definition - </label> - ${request_type.sample_form.name} - </div> - <div class="form-row"> - <label> - Possible states - </label> - %for element_count, state in enumerate(states_list): - <div class="form-row"> - <label>${1+element_count}. ${state.name}</label> - ${state.desc} - </div> - <div style="clear: both"></div> - %endfor - </div> - </form> - </div> + %endfor + </form> </div> \ No newline at end of file diff -r 56bb85457bc1 -r ed8972386675 templates/requests/grid.mako --- a/templates/requests/grid.mako Tue Nov 17 13:43:34 2009 -0500 +++ b/templates/requests/grid.mako Tue Nov 17 14:28:34 2009 -0500 @@ -1,217 +1,1 @@ -<%inherit file="/base.mako"/> -<%namespace file="/message.mako" import="render_msg" /> - -<%def name="title()">Browse Samples</%def> - -%if message: - <p> - <div class="${message_type}message transient-message">${message}</div> - <div style="clear: both"></div> - </p> -%endif - -<%def name="javascripts()"> - ${parent.javascripts()} - <script type="text/javascript"> - ## TODO: generalize and move into galaxy.base.js - $(document).ready(function() { - $(".grid").each( function() { - var grid = this; - var checkboxes = $(this).find("input.grid-row-select-checkbox"); - var update = $(this).find( "span.grid-selected-count" ); - $(checkboxes).each( function() { - $(this).change( function() { - var n = $(checkboxes).filter("[checked]").size(); - update.text( n ); - }); - }) - }); - }); - ## Can this be moved into base.mako? - %if refresh_frames: - %if 'masthead' in refresh_frames: - ## Refresh masthead == user changes (backward compatibility) - if ( parent.user_changed ) { - %if trans.user: - parent.user_changed( "${trans.user.email}", ${int( app.config.is_admin_user( trans.user ) )} ); - %else: - parent.user_changed( null, false ); - %endif - } - %endif - %if 'history' in refresh_frames: - if ( parent.frames && parent.frames.galaxy_history ) { - parent.frames.galaxy_history.location.href="${h.url_for( controller='root', action='history')}"; - if ( parent.force_right_panel ) { - parent.force_right_panel( 'show' ); - } - } - %endif - %if 'tools' in refresh_frames: - if ( parent.frames && parent.frames.galaxy_tools ) { - parent.frames.galaxy_tools.location.href="${h.url_for( controller='root', action='tool_menu')}"; - if ( parent.force_left_panel ) { - parent.force_left_panel( 'show' ); - } - } - %endif - %endif - </script> -</%def> - -<%def name="stylesheets()"> - <link href="${h.url_for('/static/style/base.css')}" rel="stylesheet" type="text/css" /> - <style> - ## Not generic to all grids -- move to base? - .count-box { - min-width: 1.1em; - padding: 5px; - border-width: 1px; - border-style: solid; - text-align: center; - display: inline-block; - } - </style> -</%def> - -<div class="grid-header"> - <h2>${grid.title}</h2> - %if len(trans.user.requests): - ##<span class="title">Filter:</span> - %for i, filter in enumerate( grid.standard_filters ): - %if i > 0: - <span>|</span> - %endif - %if grid.show_filter == filter.label: - <span class="filter"><a href="${h.url_for( controller='requests', action='list', show_filter=filter.label )}"><b>${filter.label}</b></a></span> - %else: - <span class="filter"><a href="${h.url_for( controller='requests', action='list', show_filter=filter.label )}">${filter.label}</a></span> - %endif - %endfor - %endif -</div> - -<ul class="manage-table-actions"> - <li> - <a class="action-button" href="${h.url_for( controller='requests', action='new', select_request_type=True )}"> - <img src="${h.url_for('/static/images/silk/add.png')}" /> - <span>Create a new request</span></a> - </li> -</ul> - -%if not len(query.all()): - There are no request(s). -%else: -<form name="history_actions" action="${url()}" method="post" > - <table class="grid"> - <thead> - <tr> - ##<th></th> - %for column in grid.columns: - %if column.visible: - <% - href = "" - extra = "" - if column.sortable: - if sort_key == column.key: - if sort_order == "asc": - href = url( sort=( "-" + column.key ) ) - extra = "↓" - else: - href = url( sort=( column.key ) ) - extra = "↑" - else: - href = url( sort=column.key ) - %> - <th\ - %if column.ncells > 1: - colspan="${column.ncells}" - %endif - > - %if href: - <a href="${href}">${column.label}</a> - %else: - ${column.label} - %endif - <span>${extra}</span> - </th> - %endif - %endfor - <th></th> - </tr> - </thead> - <tbody> - %for i, item in enumerate( query ): - <tr \ - %if current_item == item: - class="current" \ - %endif - > - ## Item selection column - ##<td style="width: 1.5em;"> - ## <input type="checkbox" name="id" value=${trans.security.encode_id( item.id )} class="grid-row-select-checkbox" /> - ##</td> - ## Data columns - %for column in grid.columns: - %if column.visible: - <% - # Link - if column.link and column.link( item ): - href = url( **column.link( item ) ) - else: - href = None - # Value (coerced to list so we can loop) - value = column.get_value( trans, grid, item ) - if column.ncells == 1: - value = [ value ] - %> - %for cellnum, v in enumerate( value ): - <% - # Attach popup menu? - if column.attach_popup and cellnum == 0: - extra = '<a id="grid-%d-popup" class="popup-arrow" style="display: none;">▼</a>' % i - else: - extra = "" - %> - %if href: - <td><a href="${href}">${v}</a> ${extra}</td> - %else: - <td >${v}${extra}</td> - %endif - </td> - %endfor - %endif - %endfor - ## Actions column - <td> - <div popupmenu="grid-${i}-popup"> - %for operation in grid.operations: - %if operation.allowed( item ): - %if operation.label == 'Submit': - <a class="action-button" confirm="More samples cannot be added to this request once it is submitted. Click OK to submit." href="${url( operation=operation.label, id=item.id)}">${operation.label}</a> - %else: - <a class="action-button" href="${url( operation=operation.label, id=item.id )}">${operation.label}</a> - %endif - %endif - %endfor - </div> - </td> - </tr> - %endfor - </tbody> - <tfoot> -## <tr> -## <td></td> -## <td colspan="100"> -## For <span class="grid-selected-count"></span> selected requests: -## %for operation in grid.operations: -## %if operation.allow_multiple: -## <input type="submit" name="operation" value="${operation.label}" class="action-button"> -## %endif -## %endfor -## </td> -## </tr> - </tfoot> - </table> -</form> -%endif +<%inherit file="/grid_base.mako"/> \ No newline at end of file diff -r 56bb85457bc1 -r ed8972386675 templates/requests/show_request.mako --- a/templates/requests/show_request.mako Tue Nov 17 13:43:34 2009 -0500 +++ b/templates/requests/show_request.mako Tue Nov 17 14:28:34 2009 -0500 @@ -119,7 +119,7 @@ <div class="form-row"> <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='requests', action='edit', show=True, request_id=request.id)}"> + <a class="action-button" href="${h.url_for( controller='requests', action='list', operation='Edit', id=trans.security.encode_id(request.id) )}"> <span>Edit request details</span></a> </li> </ul> diff -r 56bb85457bc1 -r ed8972386675 test/base/twilltestcase.py --- a/test/base/twilltestcase.py Tue Nov 17 13:43:34 2009 -0500 +++ b/test/base/twilltestcase.py Tue Nov 17 14:28:34 2009 -0500 @@ -1169,24 +1169,24 @@ self.check_page_for_string( desc ) self.check_page_for_string( formtype ) self.home() - def edit_form( self, form_id, form_name, new_form_name="Form One's Name (Renamed)", new_form_desc="This is Form One's description (Re-described)"): + def edit_form( self, form_current_id, form_name, new_form_name="Form One's Name (Renamed)", new_form_desc="This is Form One's description (Re-described)"): """ Edit form details; name & description """ self.home() - self.visit_url( "%s/forms/edit?form_id=%i&show_form=True" % (self.url, form_id) ) + self.visit_url( "%s/forms/manage?sort=create_time&f-name=All&f-desc=All&f-deleted=False&operation=Edit&id=%s" % ( self.url, self.security.encode_id(form_current_id) ) ) self.check_page_for_string( 'Edit form definition "%s"' % form_name ) tc.fv( "1", "name", new_form_name ) tc.fv( "1", "description", new_form_desc ) tc.submit( "save_changes_button" ) self.check_page_for_string( "The form '%s' has been updated with the changes." % new_form_name ) self.home() - def form_add_field( self, form_id, form_name, form_desc, form_type, field_index, fields): + def form_add_field( self, form_current_id, form_name, form_desc, form_type, field_index, fields): """ Add a new fields to the form definition """ self.home() - self.visit_url( "%s/forms/edit?form_id=%i&show_form=True" % (self.url, form_id) ) + self.visit_url( "%s/forms/manage?sort=create_time&f-name=All&f-desc=All&f-deleted=False&operation=Edit&id=%s" % ( self.url, self.security.encode_id(form_current_id) ) ) self.check_page_for_string( 'Edit form definition "%s"' % form_name) for i, field in enumerate(fields): index = i+field_index @@ -1198,8 +1198,8 @@ if field['type'] == 'SelectField': options = '' for option_index, option in enumerate(field['selectlist']): - url_str = "%s/forms/edit?description=%s&form_id=%i&form_type_selectbox=%s&addoption_%i=Add&name=%s&field_name_%i=%s&field_helptext_%i=%s&field_type_%i=%s" % \ - (self.url, form_desc.replace(" ", "+"), form_id, form_type.replace(" ", "+"), + url_str = "%s/forms/manage?operation=Edit&description=%s&id=%s&form_type_selectbox=%s&addoption_%i=Add&name=%s&field_name_%i=%s&field_helptext_%i=%s&field_type_%i=%s" % \ + (self.url, form_desc.replace(" ", "+"), self.security.encode_id(form_current_id), form_type.replace(" ", "+"), index, form_name.replace(" ", "+"), index, field['name'].replace(" ", "+"), index, field['desc'].replace(" ", "+"), index, field['type']) self.visit_url( url_str + options ) @@ -1214,7 +1214,7 @@ Remove a field from the form definition """ self.home() - self.visit_url( "%s/forms/edit?form_id=%i&show_form=True" % (self.url, form_id) ) + self.visit_url( "%s/forms/manage?operation=Edit&form_id=%i&show_form=True" % (self.url, form_id) ) self.check_page_for_string( 'Edit form definition "%s"' % form_name) tc.submit( "remove_button" ) tc.submit( "save_changes_button" ) @@ -1222,18 +1222,26 @@ self.check_page_for_string( check_str ) self.home() # Requests stuff + def check_request_grid(self, state, request_name, deleted=False): + self.home() + self.visit_url('%s/requests/list?sort=create_time&f-state=%s&f-deleted=%s' \ + % (self.url, state, str(deleted))) + self.check_page_for_string( request_name ) + def check_request_admin_grid(self, state, request_name, deleted=False): + self.home() + self.visit_url('%s/requests_admin/list?sort=create_time&f-state=%s&f-deleted=%s' \ + % (self.url, state, str(deleted))) + self.check_page_for_string( request_name ) def create_request_type( self, name, desc, request_form_id, sample_form_id, states ): self.home() - self.visit_url( "%s/requests_admin/request_type?create=True" % self.url ) + self.visit_url( "%s/requests_admin/create_request_type" % self.url ) self.check_page_for_string( 'Create a new request type' ) tc.fv( "1", "name", name ) - tc.fv( "1", "description", desc ) + tc.fv( "1", "desc", desc ) tc.fv( "1", "request_form_id", request_form_id ) tc.fv( "1", "sample_form_id", sample_form_id ) - tc.fv( "1", "num_states", str( len( states ) ) ) - tc.submit( "define_states_button" ) - self.check_page_for_string( "Create %i states for the '%s' request type" % ( len(states), name )) for index, state in enumerate(states): + tc.submit( "add_state_button" ) tc.fv("1", "state_name_%i" % index, state[0]) tc.fv("1", "state_desc_%i" % index, state[1]) tc.submit( "save_request_type" ) @@ -1255,7 +1263,7 @@ self.check_page_for_string( desc ) def edit_request( self, request_id, name, new_name, new_desc, new_library_id, new_folder_id, new_fields): self.home() - self.visit_url( "%s/requests/edit?request_id=%i&show=True" % (self.url, request_id) ) + self.visit_url( "%s/requests/list?operation=Edit&id=%s" % (self.url, self.security.encode_id(request_id) ) ) self.check_page_for_string( 'Edit request "%s"' % name ) tc.fv( "1", "name", new_name ) tc.fv( "1", "desc", new_desc ) diff -r 56bb85457bc1 -r ed8972386675 test/functional/test_forms_and_requests.py --- a/test/functional/test_forms_and_requests.py Tue Nov 17 13:43:34 2009 -0500 +++ b/test/functional/test_forms_and_requests.py Tue Nov 17 14:28:34 2009 -0500 @@ -29,6 +29,7 @@ .filter( galaxy.model.FormDefinitionCurrent.table.c.deleted==False ) \ .order_by( galaxy.model.FormDefinitionCurrent.table.c.create_time.desc() ) for fdc in fdc_list: + sa_session.refresh( fdc ) sa_session.refresh( fdc.latest_form ) if form_name == fdc.latest_form.name: return fdc.latest_form @@ -51,7 +52,7 @@ # edit form & add few more fields new_name = "Request Form (Renamed)" new_desc = "This is Form One's Re-described" - self.edit_form( form_one.id, form_one.name, new_form_name=new_name, new_form_desc=new_desc ) + self.edit_form( form_one.current.id, form_one.name, new_form_name=new_name, new_form_desc=new_desc ) self.home() self.visit_page( 'forms/manage' ) self.check_page_for_string( new_name ) @@ -73,13 +74,13 @@ type='TextField', required='required')] form_one = get_latest_form(form_one_name) - self.form_add_field(form_one.id, form_one.name, form_one.desc, form_one.type, field_index=len(form_one.fields), fields=fields) - form_one_latest = get_latest_form(form_one_name) + self.form_add_field(form_one.current.id, form_one.name, form_one.desc, form_one.type, field_index=len(form_one.fields), fields=fields) + form_one_latest = get_latest_form(form_one_name) assert len(form_one_latest.fields) == len(form_one.fields)+len(fields) def test_015_create_sample_form( self ): """Testing creating another form (for samples)""" global form_two_name - desc = "This is Form One's description" + desc = "This is Form Two's description" formtype = 'Sequencing Sample Form' self.create_form( name=form_two_name, desc=desc, formtype=formtype ) self.home() @@ -207,16 +208,12 @@ request_one.desc+' (Re-described)', library_one.id, folder_one.id, fields) sa_session.refresh( request_one ) # check if the request is showing in the 'unsubmitted' filter - self.home() - self.visit_url( '%s/requests/list?show_filter=Unsubmitted' % self.url ) - self.check_page_for_string( request_one.name ) + self.check_request_grid(state='Unsubmitted', request_name=request_one.name) # submit the request self.submit_request( request_one.id, request_one.name ) sa_session.refresh( request_one ) # check if the request is showing in the 'submitted' filter - self.home() - self.visit_url( '%s/requests/list?show_filter=Submitted' % self.url ) - self.check_page_for_string( request_one.name ) + self.check_request_grid(state='Submitted', request_name=request_one.name) # check if the request's state is now set to 'submitted' assert request_one.state is not request_one.states.SUBMITTED, "The state of the request '%s' should be set to '%s'" \ % ( request_one.name, request_one.states.SUBMITTED ) @@ -225,9 +222,7 @@ # goto admin manage requests page self.logout() self.login( email='test@bx.psu.edu' ) - self.home() - self.visit_page( 'requests_admin/list' ) - self.check_page_for_string( request_one.name ) + self.check_request_admin_grid(state='Submitted', request_name=request_one.name) self.visit_url( "%s/requests_admin/list?sort=-create_time&operation=show_request&id=%s" \ % ( self.url, self.security.encode_id( request_one.id ) )) self.check_page_for_string( 'Sequencing Request "%s"' % request_one.name ) @@ -240,9 +235,10 @@ self.change_sample_state( sample.name, sample.id, request_type.states[2].id, request_type.states[2].name ) self.home() sa_session.refresh( request_one ) + self.logout() + self.login( email='test1@bx.psu.edu' ) # check if the request's state is now set to 'complete' - self.visit_url('%s/requests_admin/list?show_filter=Complete' % self.url) - self.check_page_for_string( request_one.name ) + self.check_request_grid(state='Complete', request_name=request_one.name) assert request_one.state is not request_one.states.COMPLETE, "The state of the request '%s' should be set to '%s'" \ % ( request_one.name, request_one.states.COMPLETE ) def test_040_admin_create_request_on_behalf_of_regular_user( self ): @@ -262,9 +258,7 @@ galaxy.model.Request.table.c.deleted==False ) ) \ .first() # check if the request is showing in the 'unsubmitted' filter - self.home() - self.visit_url( '%s/requests_admin/list?show_filter=Unsubmitted' % self.url ) - self.check_page_for_string( request_two.name ) + self.check_request_admin_grid(state='Unsubmitted', request_name=request_two.name) # check if the request's state is now set to 'unsubmitted' assert request_two.state is not request_two.states.UNSUBMITTED, "The state of the request '%s' should be set to '%s'" \ % ( request_two.name, request_two.states.UNSUBMITTED ) @@ -277,17 +271,13 @@ self.submit_request_as_admin( request_two.id, request_two.name ) sa_session.refresh( request_two ) # check if the request is showing in the 'submitted' filter - self.home() - self.visit_url( '%s/requests_admin/list?show_filter=Submitted' % self.url ) - self.check_page_for_string( request_two.name ) + self.check_request_admin_grid(state='Submitted', request_name=request_two.name) # check if the request's state is now set to 'submitted' assert request_two.state is not request_two.states.SUBMITTED, "The state of the request '%s' should be set to '%s'" \ % ( request_two.name, request_two.states.SUBMITTED ) # check if both the requests is showing in the 'All' filter - self.home() - self.visit_url( '%s/requests_admin/list?show_filter=All' % self.url ) - self.check_page_for_string( request_one.name ) - self.check_page_for_string( request_two.name ) + self.check_request_admin_grid(state='All', request_name=request_one.name) + self.check_request_admin_grid(state='All', request_name=request_two.name) def test_045_reject_request( self ): '''Testing rejecting a request''' self.logout() @@ -295,9 +285,7 @@ self.reject_request( request_two.id, request_two.name ) sa_session.refresh( request_two ) # check if the request is showing in the 'unsubmitted' filter - self.home() - self.visit_url( '%s/requests_admin/list?show_filter=Unsubmitted' % self.url ) - self.check_page_for_string( request_two.name ) + self.check_request_admin_grid(state='Unsubmitted', request_name=request_two.name) # check if the request's state is now set to 'submitted' assert request_two.state is not request_two.states.UNSUBMITTED, "The state of the request '%s' should be set to '%s'" \ % ( request_two.name, request_two.states.UNSUBMITTED ) diff -r 56bb85457bc1 -r ed8972386675 test/functional/test_user_info.py --- a/test/functional/test_user_info.py Tue Nov 17 13:43:34 2009 -0500 +++ b/test/functional/test_user_info.py Tue Nov 17 14:28:34 2009 -0500 @@ -14,6 +14,7 @@ .filter( galaxy.model.FormDefinitionCurrent.table.c.deleted==False ) \ .order_by( galaxy.model.FormDefinitionCurrent.table.c.create_time.desc() ) for fdc in fdc_list: + sa_session.refresh( fdc ) sa_session.refresh( fdc.latest_form ) if form_name == fdc.latest_form.name: return fdc.latest_form @@ -49,7 +50,7 @@ type='CheckboxField', required='optional')] form_one = get_latest_form(form_one_name) - self.form_add_field(form_one.id, form_one.name, form_one.desc, form_one.type, field_index=len(form_one.fields), fields=fields) + self.form_add_field(form_one.current.id, form_one.name, form_one.desc, form_one.type, field_index=len(form_one.fields), fields=fields) form_one_latest = get_latest_form(form_one_name) assert len(form_one_latest.fields) == len(form_one.fields)+len(fields) # create the second form @@ -75,7 +76,7 @@ type='CheckboxField', required='optional')] form_two = get_latest_form(form_two_name) - self.form_add_field(form_two.id, form_two.name, form_two.desc, form_two.type, field_index=len(form_one.fields), fields=fields) + self.form_add_field(form_two.current.id, form_two.name, form_two.desc, form_two.type, field_index=len(form_one.fields), fields=fields) form_two_latest = get_latest_form(form_two_name) assert len(form_two_latest.fields) == len(form_two.fields)+len(fields) def test_005_user_reqistration_multiple_user_info_forms( self ): @@ -103,7 +104,7 @@ sa_session.add( form_two_latest.current ) sa_session.flush() self.home() - self.visit_page('forms/manage?show_filter=Deleted') + self.visit_page('forms/manage?sort=create_time&f-deleted=True') self.check_page_for_string(form_two_latest.name) self.logout() # user a new user with 'Student' user info form @@ -157,7 +158,7 @@ sa_session.add( form_one_latest.current ) sa_session.flush() self.home() - self.visit_page('forms/manage?show_filter=Deleted') + self.visit_page('forms/manage?sort=create_time&f-deleted=True') self.check_page_for_string(form_one_latest.name) self.logout()
participants (1)
-
Greg Von Kuster