details: http://www.bx.psu.edu/hg/galaxy/rev/55b0c25aa164 changeset: 2594:55b0c25aa164 user: rc date: Fri Aug 21 15:17:26 2009 -0400 description: Added request editing functional test Fixed a few bugs on the admin side request error handling and editing 6 file(s) affected in this change: lib/galaxy/web/controllers/requests.py lib/galaxy/web/controllers/requests_admin.py templates/admin/requests/show_request.mako templates/user/address.mako test/base/twilltestcase.py test/functional/test_forms_and_requests.py diffs (353 lines): diff -r fc4c0c7e5da9 -r 55b0c25aa164 lib/galaxy/web/controllers/requests.py --- a/lib/galaxy/web/controllers/requests.py Thu Aug 20 16:54:44 2009 -0400 +++ b/lib/galaxy/web/controllers/requests.py Fri Aug 21 15:17:26 2009 -0400 @@ -141,6 +141,9 @@ helptext='')) request_details.append(dict(label='Type', value=request.type.name, + helptext='')) + request_details.append(dict(label='State', + value=request.state, helptext='')) request_details.append(dict(label='Date created', value=request.create_time, diff -r fc4c0c7e5da9 -r 55b0c25aa164 lib/galaxy/web/controllers/requests_admin.py --- a/lib/galaxy/web/controllers/requests_admin.py Thu Aug 20 16:54:44 2009 -0400 +++ b/lib/galaxy/web/controllers/requests_admin.py Fri Aug 21 15:17:26 2009 -0400 @@ -32,7 +32,7 @@ ] 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( "Edit", allow_multiple=False, condition=( lambda item: not item.deleted ) ), grids.GridOperation( "Delete", allow_multiple=False, condition=( lambda item: not item.deleted and item.unsubmitted() ) ), grids.GridOperation( "Undelete", condition=( lambda item: item.deleted ) ), ] @@ -71,14 +71,15 @@ ''' List all request made by the current user ''' - status = message = None + 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 == "show_request": id = trans.security.decode_id(kwargs['id']) - return self.__show_request(trans, id) + return self.__show_request(trans, id, status, message) elif operation == "submit": id = trans.security.decode_id(kwargs['id']) return self.__submit(trans, id) @@ -110,7 +111,7 @@ try: request = trans.app.model.Request.get(int(params.get('request_id', None))) except: - return trans.response.send_redirect( web.url_for( controller='requests', + return trans.response.send_redirect( web.url_for( controller='requests_admin', action='list', status='error', message="Invalid request ID", @@ -125,13 +126,13 @@ kwd['messagetype'] = 'error' kwd['msg'] = msg kwd['show'] = 'True' - return trans.response.send_redirect( web.url_for( controller='requests', + return trans.response.send_redirect( web.url_for( controller='requests_admin', action='edit', **kwd) ) request = self.__save_request(trans, request, **kwd) msg = 'The changes made to the request named %s has been saved' % request.name if params.get('save_changes_request_button', False) == 'Save changes': - return trans.response.send_redirect( web.url_for( controller='requests', + return trans.response.send_redirect( web.url_for( controller='requests_admin', action='list', message=msg , status='done') ) @@ -139,7 +140,7 @@ new_kwd = {} new_kwd['request_id'] = request.id new_kwd['edit_samples_button'] = 'Edit samples' - return trans.response.send_redirect( web.url_for( controller='requests', + return trans.response.send_redirect( web.url_for( controller='requests_admin', action='show_request', msg=msg , messagetype='done', @@ -177,7 +178,7 @@ widget=TextField('desc', 40, desc), helptext='(Optional)')) # libraries selectbox - libui = self.__library_ui(trans, trans.user, request, **kwd) + libui = self.__library_ui(trans, request.user, request, **kwd) widgets = widgets + libui widgets = widgets + get_form_widgets(trans, request.type.request_form, request.values.content, request.user, **kwd) return trans.fill_template( '/admin/requests/edit_request.mako', @@ -212,6 +213,7 @@ kwd['id'] = trans.security.encode_id(request.id) 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) ) @@ -233,6 +235,7 @@ kwd['id'] = trans.security.encode_id(request.id) 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) ) @@ -290,7 +293,7 @@ if msg: return trans.response.send_redirect( web.url_for( controller='requests_admin', action='edit', - messagetype = 'error', + messagetype='error', msg=msg, request_id=request.id, show='True') ) @@ -328,11 +331,11 @@ for field_index in range(len(request.type.sample_form.fields)): sample_values.append(util.restore_text( params.get( 'sample_%i_field_%i' % (sample_index, field_index), '' ) )) self.current_samples.append([sample_name, sample_values]) - def __show_request(self, trans, id): + def __show_request(self, trans, id, messagetype, msg): try: request = trans.app.model.Request.get(id) except: - return trans.response.send_redirect( web.url_for( controller='requests', + return trans.response.send_redirect( web.url_for( controller='requests_admin', action='list', status='error', message="Invalid request ID", @@ -348,7 +351,8 @@ current_samples = self.current_samples, sample_copy=self.__copy_sample(), details_state=self.details_state, - edit_mode=self.edit_mode) + edit_mode=self.edit_mode, + msg=msg, messagetype=messagetype) @web.expose @web.require_admin def show_request(self, trans, **kwd): @@ -381,7 +385,9 @@ return trans.response.send_redirect( web.url_for( controller='requests_admin', action='list', status='error', - message='Error in importing <b>%s</b> samples file' % file_obj.file, + operation='show_request', + id=trans.security.encode_id(request.id), + message='Error in importing samples from the given file.', **kwd)) elif params.get('add_sample_button', False) == 'Add New': # save the all (saved+unsaved) sample info in 'current_samples' @@ -526,20 +532,20 @@ # list of widgets to be rendered on the request form request_details = [] # main details + request_details.append(dict(label='User', + value=str(request.user.email), + helptext='')) request_details.append(dict(label='Description', value=request.desc, helptext='')) request_details.append(dict(label='Type', value=request.type.name, helptext='')) + request_details.append(dict(label='State', + value=request.state, + helptext='')) request_details.append(dict(label='Date created', value=request.create_time, - helptext='')) - request_details.append(dict(label='Date updated', - value=request.create_time, - helptext='')) - request_details.append(dict(label='User', - value=str(request.user.email), helptext='')) # library associated if request.library: @@ -778,7 +784,7 @@ value = util.restore_text(params.get('field_%i' % index, '')) if value == 'new': # save this new address in the list of this user's addresses - user_address = trans.app.model.UserAddress( user=trans.user ) + user_address = trans.app.model.UserAddress( user=user ) user_address.desc = util.restore_text(params.get('field_%i_short_desc' % index, '')) user_address.name = util.restore_text(params.get('field_%i_name' % index, '')) user_address.institution = util.restore_text(params.get('field_%i_institution' % index, '')) @@ -812,7 +818,6 @@ request.user = user request.values = form_values request.library = library - request.state = trans.app.model.Request.states.UNSUBMITTED request.flush() return request @web.expose diff -r fc4c0c7e5da9 -r 55b0c25aa164 templates/admin/requests/show_request.mako --- a/templates/admin/requests/show_request.mako Thu Aug 20 16:54:44 2009 -0400 +++ b/templates/admin/requests/show_request.mako Fri Aug 21 15:17:26 2009 -0400 @@ -162,7 +162,7 @@ <tr> <div class="form-row"> <td> - %if current_samples: + %if current_samples and not request.complete(): <input type="submit" name="edit_samples_button" value="Edit samples"/> %endif </td> diff -r fc4c0c7e5da9 -r 55b0c25aa164 templates/user/address.mako --- a/templates/user/address.mako Thu Aug 20 16:54:44 2009 -0400 +++ b/templates/user/address.mako Fri Aug 21 15:17:26 2009 -0400 @@ -33,51 +33,48 @@ </div> - -<div class="toolForm"> - ##<div class="toolFormTitle">Addresses</div> - <div class="toolFormBody"> - <% trans.user.refresh() %> - %if not trans.user.addresses: - <label>There are no addresses</label> - %else: - <table class="grid"> - <tbody> - %for index, address in enumerate(addresses): - <tr class="libraryRow libraryOrFolderRow" id="libraryRow"> - - <td> - <div class="form-row"> - <label>${address.desc}</label> - ${address.display()} - </div> - <div class="form-row"> - <ul class="manage-table-actions"> - <li> - %if not address.deleted: - <a class="action-button" href="${h.url_for( controller='user', action='edit_address', address_id=address.id, - short_desc=address.desc, - name=address.name, institution=address.institution, - address1=address.address, city=address.city, - state=address.state, postal_code=address.postal_code, - country=address.country, phone=address.phone)}"> - <span>Edit</span></a> - <a class="action-button" href="${h.url_for( controller='user', action='delete_address', address_id=address.id)}"> - <span>Delete address</span></a> - %else: - <a class="action-button" href="${h.url_for( controller='user', action='undelete_address', address_id=address.id)}"> - <span>Undelete address</span></a> - %endif - - </li> - </ul> - </div> - </td> - </tr> - %endfor - </tbody> - </table> - %endif +%if not addresses: + <label>There are no addresses</label> +%else: + <div class="toolForm"> + <div class="toolFormBody"> + <% trans.user.refresh() %> + <table class="grid"> + <tbody> + %for index, address in enumerate(addresses): + <tr class="libraryRow libraryOrFolderRow" id="libraryRow"> + <td> + <div class="form-row"> + <label>${address.desc}</label> + ${address.display()} + </div> + <div class="form-row"> + <ul class="manage-table-actions"> + <li> + %if not address.deleted: + <a class="action-button" href="${h.url_for( controller='user', action='edit_address', address_id=address.id, + short_desc=address.desc, + name=address.name, institution=address.institution, + address1=address.address, city=address.city, + state=address.state, postal_code=address.postal_code, + country=address.country, phone=address.phone)}"> + <span>Edit</span></a> + <a class="action-button" href="${h.url_for( controller='user', action='delete_address', address_id=address.id)}"> + <span>Delete</span></a> + %else: + <a class="action-button" href="${h.url_for( controller='user', action='undelete_address', address_id=address.id)}"> + <span>Undelete</span></a> + %endif + + </li> + </ul> + </div> + </td> + </tr> + %endfor + </tbody> + </table> + %endif + </div> </div> -</div> %endif \ No newline at end of file diff -r fc4c0c7e5da9 -r 55b0c25aa164 test/base/twilltestcase.py --- a/test/base/twilltestcase.py Thu Aug 20 16:54:44 2009 -0400 +++ b/test/base/twilltestcase.py Fri Aug 21 15:17:26 2009 -0400 @@ -1088,6 +1088,16 @@ for index, field_value in enumerate(fields): tc.fv( "1", "field_%i" % index, field_value ) tc.submit( "create_request_button" ) + def edit_request( self, request_id, name, new_name, new_desc, new_library_id, new_fields): + self.home() + self.visit_url( "%s/requests/edit?request_id=%i&show=True" % (self.url, request_id) ) + self.check_page_for_string( 'Edit request "%s"' % name ) + tc.fv( "1", "name", new_name ) + tc.fv( "1", "desc", new_desc ) + tc.fv( "1", "library_id", str(new_library_id) ) + for index, field_value in enumerate(new_fields): + tc.fv( "1", "field_%i" % index, field_value ) + tc.submit( "save_changes_request_button" ) def add_samples( self, request_id, request_name, samples ): self.home() self.visit_url( "%s/requests/list?sort=-create_time&operation=show_request&id=%s" % ( self.url, self.security.encode_id( request_id ) )) diff -r fc4c0c7e5da9 -r 55b0c25aa164 test/functional/test_forms_and_requests.py --- a/test/functional/test_forms_and_requests.py Thu Aug 20 16:54:44 2009 -0400 +++ b/test/functional/test_forms_and_requests.py Fri Aug 21 15:17:26 2009 -0400 @@ -167,7 +167,7 @@ user_address.flush() user_address.user.refresh() def test_030_create_request( self ): - """Testing creating and submitting a request as a regular user""" + """Testing creating, editing and submitting a request as a regular user""" # login as a regular user self.logout() self.login( email='test1@bx.psu.edu' ) @@ -193,6 +193,12 @@ self.check_page_for_string( 'Unsubmitted' ) for field_value in fields: self.check_page_for_string( field_value ) + # edit this request + fields = ['field one value (editted)', 'field two value (editted)', str(user_address.id)] + self.edit_request(request_one.id, request_one.name, request_one.name+' (Renamed)', request_one.desc+' (Re-described)', library_one.id, fields) + request_one.refresh() + self.check_page_for_string( request_name+' (Renamed)' ) + self.check_page_for_string( request_desc+' (Re-described)' ) # submit the request self.submit_request( request_one.id, request_one.name ) request_one.refresh() @@ -264,4 +270,5 @@ + \ No newline at end of file