[hg] galaxy 2606: Merge
details: http://www.bx.psu.edu/hg/galaxy/rev/e6dda627e6b0 changeset: 2606:e6dda627e6b0 user: James Taylor <james@jamestaylor.org> date: Sat Aug 22 23:20:09 2009 -0400 description: Merge 2 file(s) affected in this change: templates/base_panels.mako templates/history/grid.mako diffs (2711 lines): diff -r fbad627b45ac -r e6dda627e6b0 lib/galaxy/model/migrate/versions/0009_request_table.py --- a/lib/galaxy/model/migrate/versions/0009_request_table.py Sat Aug 22 23:18:47 2009 -0400 +++ b/lib/galaxy/model/migrate/versions/0009_request_table.py Sat Aug 22 23:20:09 2009 -0400 @@ -9,6 +9,7 @@ from migrate.changeset import * import sys, logging from galaxy.model.custom_types import * +from sqlalchemy.exceptions import * log = logging.getLogger( __name__ ) log.setLevel(logging.DEBUG) diff -r fbad627b45ac -r e6dda627e6b0 lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py Sat Aug 22 23:18:47 2009 -0400 +++ b/lib/galaxy/tools/__init__.py Sat Aug 22 23:20:09 2009 -0400 @@ -1534,10 +1534,19 @@ child_dataset.flush() child_dataset.set_size() child_dataset.name = "Secondary Dataset (%s)" % ( designation ) - child_dataset.state = child_dataset.states.OK child_dataset.init_meta() child_dataset.set_meta() child_dataset.set_peek() + # Associate new dataset with job + job = None + for assoc in outdata.creating_job_associations: + job = assoc.job + break + if job: + assoc = self.app.model.JobToOutputDatasetAssociation( '__new_child_file_%s|%s__' % ( name, designation ), child_dataset ) + assoc.job = job + assoc.flush() + child_dataset.state = outdata.state child_dataset.flush() # Add child to return dict children[name][designation] = child_dataset @@ -1550,7 +1559,7 @@ def collect_primary_datasets( self, output): primary_datasets = {} - #Loop through output file names, looking for generated primary datasets in form of 'primary_associatedWithDatasetID_designation_visibility_extension' + #Loop through output file names, looking for generated primary datasets in form of 'primary_associatedWithDatasetID_designation_visibility_extension(_DBKEY)' for name, outdata in output.items(): for filename in glob.glob(os.path.join(self.app.config.new_file_path,"primary_%i_*" % outdata.id) ): if not name in primary_datasets: @@ -1563,19 +1572,32 @@ if visible == "visible": visible = True else: visible = False ext = fields.pop(0).lower() + dbkey = outdata.dbkey + if fields: + dbkey = fields[ 0 ] # Create new primary dataset - primary_data = self.app.model.HistoryDatasetAssociation( extension=ext, designation=designation, visible=visible, dbkey=outdata.dbkey, create_dataset=True ) + primary_data = self.app.model.HistoryDatasetAssociation( extension=ext, designation=designation, visible=visible, dbkey=dbkey, create_dataset=True ) self.app.security_agent.copy_dataset_permissions( outdata.dataset, primary_data.dataset ) primary_data.flush() # Move data from temp location to dataset location shutil.move( filename, primary_data.file_name ) primary_data.set_size() - primary_data.name = dataset.name - primary_data.info = dataset.info - primary_data.state = primary_data.states.OK - primary_data.init_meta( copy_from=dataset ) + primary_data.name = outdata.name + primary_data.info = outdata.info + primary_data.init_meta( copy_from=outdata ) + primary_data.dbkey = dbkey primary_data.set_meta() primary_data.set_peek() + # Associate new dataset with job + job = None + for assoc in outdata.creating_job_associations: + job = assoc.job + break + if job: + assoc = self.app.model.JobToOutputDatasetAssociation( '__new_primary_file_%s|%s__' % ( name, designation ), primary_data ) + assoc.job = job + assoc.flush() + primary_data.state = outdata.state primary_data.flush() outdata.history.add_dataset( primary_data ) # Add dataset to return dict diff -r fbad627b45ac -r e6dda627e6b0 lib/galaxy/tools/actions/upload.py --- a/lib/galaxy/tools/actions/upload.py Sat Aug 22 23:18:47 2009 -0400 +++ b/lib/galaxy/tools/actions/upload.py Sat Aug 22 23:20:09 2009 -0400 @@ -20,12 +20,10 @@ for upload_dataset in incoming['files']: f = upload_dataset['file_data'] if isinstance( f, FieldStorage ): - # very small files can be StringIOs - if 'name' in dir( f.file ) and f.file.name != '<fdopen>': - local_filename = util.mkstemp_ln( f.file.name, 'upload_file_data_' ) - f.file.close() - else: - local_filename = datatypes.sniff.stream_to_file( f.file, prefix="strio_upload_file_" )[0] + assert not isinstance( f.file, StringIO.StringIO ) + assert f.file.name != '<fdopen>' + local_filename = util.mkstemp_ln( f.file.name, 'upload_file_data_' ) + f.file.close() upload_dataset['file_data'] = dict( filename = f.filename, local_filename = local_filename ) if upload_dataset['url_paste'].strip() != '': diff -r fbad627b45ac -r e6dda627e6b0 lib/galaxy/tools/parameters/dynamic_options.py --- a/lib/galaxy/tools/parameters/dynamic_options.py Sat Aug 22 23:18:47 2009 -0400 +++ b/lib/galaxy/tools/parameters/dynamic_options.py Sat Aug 22 23:20:09 2009 -0400 @@ -242,6 +242,55 @@ rval.append( add_value ) return rval +class RemoveValueFilter( Filter ): + """ + Removes a value from an options list. + + Type: remove_value + + Required Attributes: + value: value to remove from select list + or + ref: param to refer to + or + meta_ref: dataset to refer to + key: metadata key to compare to + """ + def __init__( self, d_option, elem ): + Filter.__init__( self, d_option, elem ) + self.value = elem.get( "value", None ) + self.ref_name = elem.get( "ref", None ) + self.meta_ref = elem.get( "meta_ref", None ) + self.metadata_key = elem.get( "key", None ) + assert self.value is not None or ( ( self.ref_name is not None or self.meta_ref is not None )and self.metadata_key is not None ), ValueError( "Required 'value' or 'ref' and 'key' attributes missing from filter" ) + self.multiple = string_as_bool( elem.get( "multiple", "False" ) ) + self.separator = elem.get( "separator", "," ) + def filter_options( self, options, trans, other_values ): + if trans is not None and trans.workflow_building_mode: return options + assert self.value is not None or ( self.ref_name is not None and self.ref_name in other_values ) or (self.meta_ref is not None and self.meta_ref in other_values ) or ( trans is not None and trans.workflow_building_mode), Exception( "Required dependency '%s' or '%s' not found in incoming values" % ( self.ref_name, self.meta_ref ) ) + def compare_value( option_value, filter_value ): + if isinstance( filter_value, list ): + if self.multiple: + option_value = option_value.split( self.separator ) + for value in filter_value: + if value not in filter_value: + return False + return True + return option_value in filter_value + if self.multiple: + return filter_value in option_value.split( self.separator ) + return option_value == filter_value + value = self.value + if value is None: + if self.ref_name is not None: + value = other_values.get( self.ref_name ) + else: + data_ref = other_values.get( self.meta_ref ) + if not isinstance( data_ref, self.dynamic_option.tool_param.tool.app.model.HistoryDatasetAssociation ): + return options #cannot modify options + value = data_ref.metadata.get( self.metadata_key, None ) + return [ ( disp_name, optval, selected ) for disp_name, optval, selected in options if not compare_value( optval, value ) ] + class SortByColumnFilter( Filter ): """ Sorts an options list by a column @@ -274,6 +323,7 @@ unique_value = UniqueValueFilter, multiple_splitter = MultipleSplitterFilter, add_value = AdditionalValueFilter, + remove_value = RemoveValueFilter, sort_by = SortByColumnFilter ) class DynamicOptions( object ): diff -r fbad627b45ac -r e6dda627e6b0 lib/galaxy/web/controllers/admin.py --- a/lib/galaxy/web/controllers/admin.py Sat Aug 22 23:18:47 2009 -0400 +++ b/lib/galaxy/web/controllers/admin.py Sat Aug 22 23:20:09 2009 -0400 @@ -764,11 +764,7 @@ # See if we have any field contents info = info_association.info if info: - field_contents = {} - for index, value in enumerate( info.content ): - key = 'field_%i' % index - field_contents[ key ] = value - widgets = get_form_widgets( trans, template, field_contents ) + widgets = get_form_widgets( trans, template, info.content ) else: widgets = get_form_widgets( trans, template ) else: @@ -965,11 +961,7 @@ # See if we have any field contents info = info_association.info if info: - field_contents = {} - for index, value in enumerate( info.content ): - key = 'field_%i' % index - field_contents[ key ] = value - widgets = get_form_widgets( trans, template, field_contents ) + widgets = get_form_widgets( trans, template, info.content ) else: widgets = get_form_widgets( trans, template ) else: @@ -1220,11 +1212,7 @@ # See if we have any field contents info = info_association.info if info: - field_contents = {} - for index, value in enumerate( info.content ): - key = 'field_%i' % index - field_contents[ key ] = value - widgets = get_form_widgets( trans, template, field_contents ) + widgets = get_form_widgets( trans, template, info.content ) else: widgets = get_form_widgets( trans, template ) else: @@ -2027,7 +2015,7 @@ 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( 'new_element_name_%i' % i, None ) ): + if not util.restore_text( params.get( 'state_name_%i' % i, None ) ): proceed = False break if not proceed: @@ -2045,8 +2033,8 @@ ss.delete() ss.flush() for i in range( num_states ): - name = util.restore_text( params.get( 'new_element_name_%i' % i, None )) - desc = util.restore_text( params.get( 'new_element_description_%i' % i, None )) + 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) ss.flush() msg = "The new request type named '%s' with %s state(s) has been created" % (rt.name, num_states) diff -r fbad627b45ac -r e6dda627e6b0 lib/galaxy/web/controllers/forms.py --- a/lib/galaxy/web/controllers/forms.py Sat Aug 22 23:18:47 2009 -0400 +++ b/lib/galaxy/web/controllers/forms.py Sat Aug 22 23:20:09 2009 -0400 @@ -175,7 +175,7 @@ 'visible': True, 'required': False, 'type': BaseField.form_field_types()[0], - 'selectlist': '' } + 'selectlist': [] } self.current_form['fields'].append(empty_field) def __get_field(self, index, **kwd): params = util.Params( kwd ) @@ -183,10 +183,10 @@ # To reproduce, create a new form, click the "add field" button, click the # browser back arrow, then click the "add field" button again. # You should never attempt to "restore_text()" on a None object... - name = util.restore_text( params.get( 'field_name_%i' % index, None ) ) - helptext = util.restore_text( params.get( 'field_helptext_%i' % index, None ) ) + name = util.restore_text( params.get( 'field_name_%i' % index, '' ) ) + helptext = util.restore_text( params.get( 'field_helptext_%i' % index, '' ) ) required = params.get( 'field_required_%i' % index, False ) - field_type = util.restore_text( params.get( 'field_type_%i' % index, None ) ) + field_type = util.restore_text( params.get( 'field_type_%i' % index, '' ) ) if field_type == 'SelectField': selectlist = self.__get_selectbox_options(index, **kwd) return {'label': name, @@ -419,22 +419,39 @@ else: fdc_list = trans.app.model.FormDefinitionCurrent.query().all() return [ fdc.latest_form for fdc in fdc_list ] -def get_form_widgets( trans, form, contents={} ): + + +def get_form_widgets( trans, form, contents=[], user=None, **kwd ): ''' Return the list of widgets that comprise a form definition, including field contents if any. ''' + params = util.Params( kwd ) + if not user: + user = trans.user widgets = [] for index, field in enumerate( form.fields ): field_name = 'field_%i' % index - if field_name in contents: - value = contents[ field_name ] - elif field[ 'type' ] == 'CheckboxField': - # Since we do not have contents, set checkbox value to False - value = False + # determine the value of the field + if field_name in kwd: + # the user had already filled out this field and the same form is re-rendered + # due to some reason like required fields have been left out. + if field[ 'type' ] == 'CheckboxField': + value = CheckboxField.is_checked( util.restore_text( params.get( field_name, False ) ) ) + else: + value = util.restore_text( params.get( field_name, '' ) ) + elif contents: + # this field has a saved value + value = str(contents[ index ]) else: - # Set other field types to empty string - value = '' + # if none of the above, then leave the field empty + if field[ 'type' ] == 'CheckboxField': + # Since we do not have contents, set checkbox value to False + value = False + else: + # Set other field types to empty string + value = '' + # create the field widget field_widget = eval( field[ 'type' ] )( field_name ) if field[ 'type' ] == 'TextField': field_widget.set_size( 40 ) @@ -442,6 +459,10 @@ elif field[ 'type' ] == 'TextArea': field_widget.set_size( 3, 40 ) field_widget.value = value + elif field['type'] == 'AddressField': + field_widget.user = user + field_widget.value = value + field_widget.params = params elif field[ 'type' ] == 'SelectField': for option in field[ 'selectlist' ]: if option == value: diff -r fbad627b45ac -r e6dda627e6b0 lib/galaxy/web/controllers/library.py --- a/lib/galaxy/web/controllers/library.py Sat Aug 22 23:18:47 2009 -0400 +++ b/lib/galaxy/web/controllers/library.py Sat Aug 22 23:20:09 2009 -0400 @@ -137,11 +137,7 @@ # See if we have any field contents info = library.info_association[0].info if info: - field_contents = {} - for index, value in enumerate( info.content ): - key = 'field_%i' % index - field_contents[ key ] = value - widgets = get_form_widgets( trans, template, field_contents ) + widgets = get_form_widgets( trans, template, info.content ) else: widgets = get_form_widgets( trans, template ) else: @@ -475,11 +471,7 @@ # See if we have any field contents info = info_association.info if info: - field_contents = {} - for index, value in enumerate( info.content ): - key = 'field_%i' % index - field_contents[ key ] = value - widgets = get_form_widgets( trans, template, field_contents ) + widgets = get_form_widgets( trans, template, info.content ) else: widgets = get_form_widgets( trans, template ) else: @@ -996,11 +988,7 @@ # See if we have any field contents info = info_association.info if info: - field_contents = {} - for index, value in enumerate( info.content ): - key = 'field_%i' % index - field_contents[ key ] = value - widgets = get_form_widgets( trans, template, field_contents ) + widgets = get_form_widgets( trans, template, info.content ) else: widgets = get_form_widgets( trans, template ) else: @@ -1173,3 +1161,13 @@ edit_info=True, msg=util.sanitize_text( msg ), messagetype='done' ) ) + + +def get_authorized_libs(trans, user): + all_libraries = trans.app.model.Library.filter(trans.app.model.Library.table.c.deleted == False).order_by(trans.app.model.Library.name).all() + authorized_libraries = [] + for library in all_libraries: + if trans.app.security_agent.allow_action(user, trans.app.security_agent.permitted_actions.LIBRARY_ADD, library_item=library) \ + or trans.app.security_agent.allow_action(user, trans.app.security_agent.permitted_actions.LIBRARY_MODIFY, library_item=library): + authorized_libraries.append(library) + return authorized_libraries \ No newline at end of file diff -r fbad627b45ac -r e6dda627e6b0 lib/galaxy/web/controllers/requests.py --- a/lib/galaxy/web/controllers/requests.py Sat Aug 22 23:18:47 2009 -0400 +++ b/lib/galaxy/web/controllers/requests.py Sat Aug 22 23:20:09 2009 -0400 @@ -8,6 +8,8 @@ from galaxy.web.form_builder import * from datetime import datetime, timedelta from cgi import escape, FieldStorage +from galaxy.web.controllers.forms import get_form_widgets +from galaxy.web.controllers.library import get_authorized_libs log = logging.getLogger( __name__ ) @@ -62,18 +64,12 @@ request_grid = RequestsListGrid() @web.expose + @web.require_login( "create/submit sequencing requests" ) def index( self, trans ): return trans.fill_template( "requests/index.mako" ) - - def get_authorized_libs(self, trans): - all_libraries = trans.app.model.Library.filter(trans.app.model.Library.table.c.deleted == False).order_by(trans.app.model.Library.name).all() - authorized_libraries = [] - for library in all_libraries: - if trans.app.security_agent.allow_action(trans.user, trans.app.security_agent.permitted_actions.LIBRARY_ADD, library_item=library) \ - or trans.app.security_agent.allow_action(trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MODIFY, library_item=library): - authorized_libraries.append(library) - return authorized_libraries + @web.expose + @web.require_login( "create/submit sequencing requests" ) def list( self, trans, **kwargs ): ''' List all request made by the current user @@ -137,7 +133,6 @@ Shows the request details ''' request = trans.app.model.Request.get(id) - libraries = self.get_authorized_libs(trans) # list of widgets to be rendered on the request form request_details = [] # main details @@ -146,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, @@ -201,6 +199,7 @@ copy_list.add_option(s[0], i) return copy_list @web.expose + @web.require_login( "create/submit sequencing requests" ) def show_request(self, trans, **kwd): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) @@ -326,6 +325,7 @@ @web.expose + @web.require_login( "create/submit sequencing requests" ) def delete_sample(self, trans, **kwd): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) @@ -348,6 +348,7 @@ edit_mode=self.edit_mode) @web.expose + @web.require_login( "create/submit sequencing requests" ) def toggle_request_details(self, trans, **kwd): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) @@ -384,6 +385,7 @@ select_reqtype.add_option(rt.name, rt.id) return select_reqtype @web.expose + @web.require_login( "create/submit sequencing requests" ) def new(self, trans, **kwd): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) @@ -413,8 +415,8 @@ if params.get('create_request_button', False) == 'Save': return trans.response.send_redirect( web.url_for( controller='requests', action='list', - msg=msg , - messagetype='done') ) + message=msg , + status='done') ) elif params.get('create_request_samples_button', False) == 'Add samples': new_kwd = {} new_kwd['id'] = trans.security.encode_id(request.id) @@ -457,12 +459,10 @@ helptext='(Optional)')) # libraries selectbox - libraries = self.get_authorized_libs(trans) + libraries = get_authorized_libs(trans, trans.user) libui = self.__library_ui(libraries, **kwd) widgets = widgets + libui - widgets = self.__create_form(trans, request_type.request_form_id, widgets, - form_values, **kwd) - title = 'Add a new request of type: %s' % request_type.name + widgets = widgets + get_form_widgets(trans, request_type.request_form, contents=[], **kwd) return trans.fill_template( '/requests/new_request.mako', select_request_type=select_request_type, request_type=request_type, @@ -502,58 +502,13 @@ return [widget, new_lib] else: return [widget] - - def __create_form(self, trans, form_id, widgets=[], form_values=None, **kwd): - # TODO: RC - replace this method by importing as follows: - # from galaxy.web.controllers.forms import get_form_widgets - params = util.Params( kwd ) - form = trans.app.model.FormDefinition.get(form_id) - # form fields - for index, field in enumerate(form.fields): - # value of the field - if field['type'] == 'CheckboxField': - value = util.restore_text( params.get( 'field_%i' % index, False ) ) - else: - value = util.restore_text( params.get( 'field_%i' % index, '' ) ) - if not value: - if form_values: - value = str(form_values.content[index]) - # create the field - fw = eval(field['type'])('field_%i' % index) - if field['type'] == 'TextField': - fw.set_size(40) - fw.value = value - elif field['type'] == 'TextArea': - fw.set_size(3, 40) - fw.value = value - elif field['type'] == 'AddressField': - fw.user = trans.user - fw.value = value - fw.params = params - elif field['type'] == 'SelectField': - for option in field['selectlist']: - if option == value: - fw.add_option(option, option, selected=True) - else: - fw.add_option(option, option) - elif field['type'] == 'CheckboxField': - fw.checked = value - # require/optional - if field['required'] == 'required': - req = 'Required' - else: - req = 'Optional' - widgets.append(dict(label=field['label'], - widget=fw, - helptext=field['helptext']+' ('+req+')')) - return widgets def __validate(self, trans, request): ''' Validates the request entered by the user ''' empty_fields = [] - if not request.library: - empty_fields.append('Data library') +# if not request.library: +# empty_fields.append('Data library') # check rest of the fields of the form for index, field in enumerate(request.type.request_form.fields): if field['required'] == 'required' and request.values.content[index] in ['', None]: @@ -622,6 +577,7 @@ request.flush() return request @web.expose + @web.require_login( "create/submit sequencing requests" ) def edit(self, trans, **kwd): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) @@ -698,11 +654,10 @@ helptext='(Optional)')) # libraries selectbox - libraries = self.get_authorized_libs(trans) + libraries = get_authorized_libs(trans, trans.user) libui = self.__library_ui(libraries, request, **kwd) widgets = widgets + libui - widgets = self.__create_form(trans, request.type.request_form_id, widgets, - request.values, **kwd) + widgets = widgets + get_form_widgets(trans, request.type.request_form, request.values.content, **kwd) return trans.fill_template( '/requests/edit_request.mako', select_request_type=select_request_type, request_type=request.type, @@ -735,6 +690,8 @@ 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 deleted.' % request.name, **kwd) ) def __undelete_request(self, trans, id): try: @@ -754,6 +711,8 @@ 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(self, trans, id): try: @@ -784,10 +743,14 @@ request.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) ) @web.expose + @web.require_login( "create/submit sequencing requests" ) def submit_request(self, trans, **kwd): params = util.Params( kwd ) try: @@ -817,13 +780,16 @@ # change request's submitted field request.state = request.states.SUBMITTED request.flush() - ## TODO 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) ) @web.expose + @web.require_login( "create/submit sequencing requests" ) def show_events(self, trans, **kwd): params = util.Params( kwd ) try: diff -r fbad627b45ac -r e6dda627e6b0 lib/galaxy/web/controllers/requests_admin.py --- a/lib/galaxy/web/controllers/requests_admin.py Sat Aug 22 23:18:47 2009 -0400 +++ b/lib/galaxy/web/controllers/requests_admin.py Sat Aug 22 23:20:09 2009 -0400 @@ -7,19 +7,20 @@ import logging, tempfile, zipfile, tarfile, os, sys from galaxy.web.form_builder import * from datetime import datetime, timedelta +from galaxy.web.controllers.forms import get_form_widgets +from galaxy.web.controllers.library import get_authorized_libs log = logging.getLogger( __name__ ) - -# States for passing messages -SUCCESS, INFO, WARNING, ERROR = "done", "info", "warning", "error" class RequestsListGrid( grids.Grid ): title = "Sequencing Requests" model_class = model.Request default_sort_key = "-create_time" + show_filter = model.Request.states.SUBMITTED columns = [ grids.GridColumn( "Name", key="name", - link=( lambda item: iff( item.deleted, None, dict( operation="show_request", id=item.id ) ) )), + 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 ) ) ), ), @@ -30,15 +31,18 @@ ] operations = [ -# grids.GridOperation( "Edit", allow_multiple=False, condition=( lambda item: not item.deleted ) ), -# grids.GridOperation( "Samples", allow_multiple=False, condition=( lambda item: not item.deleted ) ), -# grids.GridOperation( "Delete", condition=( lambda item: not item.deleted ) ), -# grids.GridOperation( "Undelete", condition=( lambda item: item.deleted ) ), + 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( "Delete", allow_multiple=False, 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 ) ) ] def get_user(self, trans, request): @@ -48,9 +52,9 @@ def get_request_type(self, trans, request): request_type = trans.app.model.RequestType.get(request.request_type_id) return request_type.name - def apply_default_filter( self, trans, query ): - return query.filter(or_(self.model_class.state==self.model_class.states.SUBMITTED, - self.model_class.state==self.model_class.states.COMPLETE)) +# def apply_default_filter( self, trans, query ): +# return query.filter(or_(self.model_class.state==self.model_class.states.SUBMITTED, +# self.model_class.state==self.model_class.states.COMPLETE)) def number_of_samples(self, trans, request): return str(len(request.samples)) @@ -67,32 +71,277 @@ ''' 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) + 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) if 'show_filter' in kwargs.keys(): if kwargs['show_filter'] == 'All': - self.request_grid.default_filter = dict(deleted=False) + 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.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, template='/admin/requests/grid.mako', **kwargs ) - def __show_request(self, trans, id): + @web.expose + @web.require_admin + def edit(self, trans, **kwd): + params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) + try: + request = trans.app.model.Request.get(int(params.get('request_id', None))) + except: + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='list', + status='error', + message="Invalid request ID", + **kwd) ) + if params.get('show', False) == 'True': + return self.__edit_request(trans, request.id, **kwd) + elif params.get('save_changes_request_button', False) == 'Save changes' \ + or params.get('edit_samples_button', False) == 'Edit samples': + request_type = trans.app.model.RequestType.get(int(params.select_request_type)) + if not util.restore_text(params.get('name', '')): + msg = 'Please enter the <b>Name</b> of the request' + kwd['messagetype'] = 'error' + kwd['msg'] = msg + kwd['show'] = 'True' + 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_admin', + action='list', + message=msg , + status='done') ) + elif params.get('edit_samples_button', False) == 'Edit samples': + 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_admin', + action='show_request', + msg=msg , + messagetype='done', + **new_kwd) ) + elif params.get('refresh', False) == 'true': + return self.__edit_request(trans, request.id, **kwd) + def __edit_request(self, trans, id, **kwd): try: request = trans.app.model.Request.get(id) except: - return trans.response.send_redirect( web.url_for( controller='requests', + msg = "Invalid request ID" + log.warn( msg ) + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='list', + status='error', + message=msg) ) + params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) + select_request_type = self.__select_request_type(trans, request.type.id) + # list of widgets to be rendered on the request form + widgets = [] + if util.restore_text( params.get( 'name', '' ) ): + name = util.restore_text( params.get( 'name', '' ) ) + else: + name = request.name + widgets.append(dict(label='Name', + widget=TextField('name', 40, name), + helptext='(Required)')) + if util.restore_text( params.get( 'desc', '' ) ): + desc = util.restore_text( params.get( 'desc', '' ) ) + else: + desc = request.desc + widgets.append(dict(label='Description', + widget=TextField('desc', 40, desc), + helptext='(Optional)')) + # libraries selectbox + 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', + select_request_type=select_request_type, + request_type=request.type, + request=request, + widgets=widgets, + msg=msg, + messagetype=messagetype) + return self.__show_request_form(trans) + def __delete_request(self, trans, id): + try: + request = 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 + request.flush() + kwd = {} + 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) ) + def __undelete_request(self, trans, id): + try: + request = 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 + request.flush() + kwd = {} + 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) ) + def __submit(self, trans, id): + try: + request = 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) ) + msg = self.__validate(trans, request) + if msg: + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='edit', + messagetype = 'error', + msg=msg, + request_id=request.id, + show='True') ) + # get the new state + new_state = request.type.states[0] + for s in request.samples: + event = trans.app.model.SampleEvent(s, new_state, 'Samples submitted to the system') + event.flush() + # change request's submitted field + request.state = request.states.SUBMITTED + request.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) ) + @web.expose + @web.require_admin + def submit_request(self, trans, **kwd): + params = util.Params( kwd ) + try: + id = int(params.get('id', False)) + request = 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) ) + msg = self.__validate(trans, request) + if msg: + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='edit', + messagetype='error', + msg=msg, + request_id=request.id, + show='True') ) + # get the new state + new_state = request.type.states[0] + for s in request.samples: + event = trans.app.model.SampleEvent(s, new_state, 'Samples submitted to the system') + event.flush() + # change request's submitted field + request.state = request.states.SUBMITTED + request.flush() + 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) ) + def __copy_sample(self): + copy_list = SelectField('copy_sample') + copy_list.add_option('None', -1, selected=True) + for i, s in enumerate(self.current_samples): + copy_list.add_option(s[0], i) + return copy_list + def __update_samples(self, request, **kwd): + params = util.Params( kwd ) + num_samples = len(self.current_samples) + self.current_samples = [] + for s in request.samples: + self.current_samples.append([s.name, s.values.content]) + for index in range(num_samples-len(request.samples)): + sample_index = index + len(request.samples) + sample_name = util.restore_text( params.get( 'sample_%i_name' % sample_index, '' ) ) + sample_values = [] + 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, messagetype, msg): + try: + request = trans.app.model.Request.get(id) + except: + return trans.response.send_redirect( web.url_for( controller='requests_admin', action='list', status='error', message="Invalid request ID", **kwd) ) self.current_samples = [] + self.edit_mode = False for s in request.samples: self.current_samples.append([s.name, s.values.content]) self.details_state = 'Show request details' @@ -100,8 +349,163 @@ request=request, request_details=self.request_details(trans, id), current_samples = self.current_samples, - details_state=self.details_state) + sample_copy=self.__copy_sample(), + details_state=self.details_state, + edit_mode=self.edit_mode, + msg=msg, messagetype=messagetype) @web.expose + @web.require_admin + def show_request(self, trans, **kwd): + params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) + try: + request = trans.app.model.Request.get(int(params.get('request_id', None))) + except: + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='list', + status='error', + message="Invalid request ID", + **kwd) ) + if params.get('import_samples_button', False) == 'Import samples': + try: + file_obj = params.get('file_data', '') + import csv + reader = csv.reader(file_obj.file) + for row in reader: + self.current_samples.append([row[0], row[1:]]) + return trans.fill_template( '/admin/requests/show_request.mako', + request=request, + request_details=self.request_details(trans, request.id), + current_samples=self.current_samples, + sample_copy=self.__copy_sample(), + details_state=self.details_state, + edit_mode=self.edit_mode) + except: + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='list', + status='error', + 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' + self.__update_samples(request, **kwd) + # add an empty or filled sample + # if the user has selected a sample no. to copy then copy the contents + # of the src sample to the new sample else an empty sample + src_sample_index = int(params.get( 'copy_sample', -1 )) + if src_sample_index == -1: + # empty sample + self.current_samples.append(['Sample_%i' % (len(self.current_samples)+1),['' for field in request.type.sample_form.fields]]) + else: + self.current_samples.append([self.current_samples[src_sample_index][0]+'_%i' % (len(self.current_samples)+1), + [val for val in self.current_samples[src_sample_index][1]]]) + return trans.fill_template( '/admin/requests/show_request.mako', + request=request, + request_details=self.request_details(trans, request.id), + current_samples=self.current_samples, + sample_copy=self.__copy_sample(), + details_state=self.details_state, + edit_mode=self.edit_mode) + elif params.get('save_samples_button', False) == 'Save': + # update current_samples + self.__update_samples(request, **kwd) + # check for duplicate sample names + msg = '' + for index in range(len(self.current_samples)-len(request.samples)): + sample_index = index + len(request.samples) + sample_name = self.current_samples[sample_index][0] + if not sample_name.strip(): + msg = 'Please enter the name of sample number %i' % sample_index + break + count = 0 + for i in range(len(self.current_samples)): + if sample_name == self.current_samples[i][0]: + count = count + 1 + if count > 1: + msg = "This request has <b>%i</b> samples with the name <b>%s</b>.\nSamples belonging to a request must have unique names." % (count, sample_name) + break + if msg: + return trans.fill_template( '/admin/requests/show_request.mako', + request=request, + request_details=self.request_details(trans, request.id), + current_samples = self.current_samples, + sample_copy=self.__copy_sample(), details_state=self.details_state, + messagetype='error', msg=msg) + # save all the new/unsaved samples entered by the user + if not self.edit_mode: + for index in range(len(self.current_samples)-len(request.samples)): + sample_index = index + len(request.samples) + sample_name = util.restore_text( params.get( 'sample_%i_name' % sample_index, '' ) ) + sample_values = [] + 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), '' ) )) + form_values = trans.app.model.FormValues(request.type.sample_form, sample_values) + form_values.flush() + s = trans.app.model.Sample(sample_name, '', request, form_values) + s.flush() + else: + for index in range(len(self.current_samples)): + sample_index = index + sample_name = self.current_samples[sample_index][0] + new_sample_name = util.restore_text( params.get( 'sample_%i_name' % sample_index, '' ) ) + sample_values = [] + 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), '' ) )) + sample = request.has_sample(sample_name) + if sample: + form_values = trans.app.model.FormValues.get(sample.values.id) + form_values.content = sample_values + form_values.flush() + sample.name = new_sample_name + sample.flush() + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='list', + operation='show_request', + id=trans.security.encode_id(request.id)) ) + elif params.get('edit_samples_button', False) == 'Edit samples': + self.edit_mode = True + return trans.fill_template( '/admin/requests/show_request.mako', + request=request, + request_details=self.request_details(trans, request.id), + current_samples=self.current_samples, + sample_copy=self.__copy_sample(), + details_state=self.details_state, + edit_mode=self.edit_mode) + elif params.get('cancel_changes_button', False) == 'Cancel': + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='list', + operation='show_request', + id=trans.security.encode_id(request.id)) ) + + + @web.expose + @web.require_admin + def delete_sample(self, trans, **kwd): + params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) + request = trans.app.model.Request.get(int(params.get('request_id', 0))) + sample_index = int(params.get('sample_id', 0)) + sample_name = self.current_samples[sample_index][0] + s = request.has_sample(sample_name) + if s: + s.delete() + s.flush() + request.flush() + del self.current_samples[sample_index] + return trans.fill_template( '/admin/requests/show_request.mako', + request=request, + request_details=self.request_details(trans, request.id), + current_samples = self.current_samples, + sample_copy=self.__copy_sample(), + details_state=self.details_state, + edit_mode=self.edit_mode) + + @web.expose + @web.require_admin def toggle_request_details(self, trans, **kwd): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) @@ -128,24 +532,28 @@ # 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: + value=request.library.name + else: + value = None request_details.append(dict(label='Data library', - value=trans.app.model.Library.get(request.library_id).name, + value=value, helptext='Data library where the resultant dataset will be stored')) # form fields for index, field in enumerate(request.type.request_form.fields): @@ -167,15 +575,262 @@ value=request.values.content[index], helptext=field['helptext']+' ('+req+')')) return request_details + + def __select_request_type(self, trans, rtid): + rt_ids = ['none'] + for rt in trans.app.model.RequestType.query().all(): + if not rt.deleted: + rt_ids.append(str(rt.id)) + select_reqtype = SelectField('select_request_type', + refresh_on_change=True, + refresh_on_change_values=rt_ids[1:]) + if rtid == 'none': + select_reqtype.add_option('Select one', 'none', selected=True) + else: + select_reqtype.add_option('Select one', 'none') + for rt in trans.app.model.RequestType.query().all(): + if not rt.deleted: + if rtid == rt.id: + select_reqtype.add_option(rt.name, rt.id, selected=True) + else: + select_reqtype.add_option(rt.name, rt.id) + return select_reqtype + @web.expose + @web.require_admin + def new(self, trans, **kwd): + params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) + if params.get('select_request_type', False) == 'True': + return trans.fill_template( '/admin/requests/new_request.mako', + select_request_type=self.__select_request_type(trans, 'none'), + widgets=[], + msg=msg, + messagetype=messagetype) + elif params.get('create', False) == 'True': + if params.get('create_request_button', False) == 'Save' \ + or params.get('create_request_samples_button', False) == 'Add samples': + request_type = trans.app.model.RequestType.get(int(params.select_request_type)) + if not util.restore_text(params.get('name', '')) \ + or util.restore_text(params.get('select_user', '')) == unicode('none'): + msg = 'Please enter the <b>Name</b> of the request and the <b>user</b> on behalf of whom this request will be submitted before saving this request' + kwd['create'] = 'True' + kwd['messagetype'] = 'error' + kwd['msg'] = msg + kwd['create_request_button'] = None + kwd['create_request_samples_button'] = None + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='new', + **kwd) ) + request = self.__save_request(trans, None, **kwd) + msg = 'The new request named %s has been created' % request.name + 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': + new_kwd = {} + new_kwd['id'] = trans.security.encode_id(request.id) + new_kwd['operation'] = 'show_request' + new_kwd['add_sample'] = True + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='list', + message=msg , + status='done', + **new_kwd) ) + else: + return self.__show_request_form(trans, **kwd) + elif params.get('refresh', False) == 'true': + return self.__show_request_form(trans, **kwd) + def __show_request_form(self, trans, **kwd): + params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) + try: + request_type = trans.app.model.RequestType.get(int(params.select_request_type)) + except: + return trans.fill_template( '/admin/requests/new_request.mako', + select_request_type=self.__select_request_type(trans, 'none'), + widgets=[], + msg=msg, + messagetype=messagetype) + form_values = None + select_request_type = self.__select_request_type(trans, request_type.id) + # user + user_id = params.get( 'select_user', 'none' ) + try: + user = trans.app.model.User.get(int(user_id)) + except: + user = None + # list of widgets to be rendered on the request form + widgets = [] + widgets.append(dict(label='Select user', + widget=self.__select_user(trans, user_id), + helptext='The request would be submitted on behalf of this user (Required)')) + widgets.append(dict(label='Name', + widget=TextField('name', 40, + util.restore_text( params.get( 'name', '' ) )), + helptext='(Required)')) + widgets.append(dict(label='Description', + widget=TextField('desc', 40, + util.restore_text( params.get( 'desc', '' ) )), + helptext='(Optional)')) + # libraries selectbox + libui = self.__library_ui(trans, user, **kwd) + widgets = widgets + libui + widgets = widgets + get_form_widgets(trans, request_type.request_form, contents=[], user=user, **kwd) + return trans.fill_template( '/admin/requests/new_request.mako', + select_request_type=select_request_type, + request_type=request_type, + widgets=widgets, + msg=msg, + messagetype=messagetype) + def __select_user(self, trans, userid): + user_ids = ['none'] + for user in trans.app.model.User.query().all(): + if not user.deleted: + user_ids.append(str(user.id)) + select_user = SelectField('select_user', + refresh_on_change=True, + refresh_on_change_values=user_ids[1:]) + if userid == 'none': + select_user.add_option('Select one', 'none', selected=True) + else: + select_user.add_option('Select one', 'none') + for user in trans.app.model.User.query().all(): + if not user.deleted: + if userid == str(user.id): + select_user.add_option(user.email, user.id, selected=True) + else: + select_user.add_option(user.email, user.id) + return select_user + + def __library_ui(self, trans, user, request=None, **kwd): + params = util.Params( kwd ) + lib_id = params.get( 'library_id', 'none' ) + if not user: + libraries = trans.app.model.Library.filter(trans.app.model.Library.table.c.deleted == False).order_by(trans.app.model.Library.name).all() + else: + libraries = get_authorized_libs(trans, user) + lib_list = SelectField('library_id', refresh_on_change=True, + refresh_on_change_values=['new']) + if request and lib_id == 'none': + if request.library: + lib_id = str(request.library.id) + if lib_id == 'none': + lib_list.add_option('Select one', 'none', selected=True) + else: + lib_list.add_option('Select one', 'none') + for lib in libraries: + if str(lib.id) == lib_id: + lib_list.add_option(lib.name, lib.id, selected=True) + else: + lib_list.add_option(lib.name, lib.id) + if lib_id == 'new': + lib_list.add_option('Create a new data library', 'new', selected=True) + else: + lib_list.add_option('Create a new data library', 'new') + widget = dict(label='Data library', + widget=lib_list, + helptext='Data library where the resultant dataset will be stored.') + if lib_id == 'new': + new_lib = dict(label='Create a new Library', + widget=TextField('new_library_name', 40, + util.restore_text( params.get( 'new_library_name', '' ) )), + helptext='Enter a library name here to request a new library') + return [widget, new_lib] + else: + return [widget] + def __validate(self, trans, request): + ''' + Validates the request entered by the user + ''' + empty_fields = [] +# if not request.library: +# empty_fields.append('Library') + # check rest of the fields of the form + for index, field in enumerate(request.type.request_form.fields): + if field['required'] == 'required' and request.values.content[index] in ['', None]: + empty_fields.append(field['label']) + if empty_fields: + msg = 'Fill the following fields of the request <b>%s</b> before submitting<br/>' % request.name + for ef in empty_fields: + msg = msg + '<b>' +ef + '</b><br/>' + return msg + return None + def __save_request(self, trans, request=None, **kwd): + ''' + This method saves a new request if request_id is None. + ''' + params = util.Params( kwd ) + request_type = trans.app.model.RequestType.get(int(params.select_request_type)) + if request: + user = request.user + else: + user = trans.app.model.User.get(int(params.get('select_user', ''))) + name = util.restore_text(params.get('name', '')) + desc = util.restore_text(params.get('desc', '')) + # library + try: + library = trans.app.model.Library.get(int(params.get('library_id', None))) + except: + library = None + # fields + values = [] + for index, field in enumerate(request_type.request_form.fields): + if field['type'] == 'AddressField': + 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=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, '')) + user_address.address = util.restore_text(params.get('field_%i_address1' % index, ''))+' '+util.restore_text(params.get('field_%i_address2' % index, '')) + user_address.city = util.restore_text(params.get('field_%i_city' % index, '')) + user_address.state = util.restore_text(params.get('field_%i_state' % index, '')) + user_address.postal_code = util.restore_text(params.get('field_%i_postal_code' % index, '')) + user_address.country = util.restore_text(params.get('field_%i_country' % index, '')) + user_address.phone = util.restore_text(params.get('field_%i_phone' % index, '')) + user_address.flush() + trans.user.refresh() + values.append(int(user_address.id)) + elif value == unicode('none'): + values.append('') + else: + values.append(int(value)) + else: + values.append(util.restore_text(params.get('field_%i' % index, ''))) + form_values = trans.app.model.FormValues(request_type.request_form, values) + form_values.flush() + if not request: + request = trans.app.model.Request(name, desc, request_type, + user, form_values, + library=library, + state=trans.app.model.Request.states.UNSUBMITTED) + request.flush() + else: + request.name = name + request.desc = desc + request.type = request_type + request.user = user + request.values = form_values + request.library = library + request.flush() + return request @web.expose @web.require_admin def bar_codes(self, trans, **kwd): params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) request_id = params.get( 'request_id', None ) if request_id: request = trans.app.model.Request.get( int( request_id )) if not request: - 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", @@ -191,7 +846,9 @@ bc)) return trans.fill_template( '/admin/samples/bar_codes.mako', samples_list=[s for s in request.samples], - user=request.user, request=request, widgets=widgets) + user=request.user, request=request, widgets=widgets, + messagetype=messagetype, + msg=msg) @web.expose @web.require_admin def save_bar_codes(self, trans, **kwd): @@ -199,7 +856,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", @@ -255,9 +912,10 @@ sample.bar_code = bar_code sample.flush() return trans.response.send_redirect( web.url_for( controller='requests_admin', - action='list', - operation='show_request', - id=trans.security.encode_id(request.id)) ) + action='bar_codes', + request_id=request.id, + msg='Bar codes has been saved for this request', + messagetype='done')) def __set_request_state(self, request): # check if all the samples of the current request are in the final state complete = True diff -r fbad627b45ac -r e6dda627e6b0 lib/galaxy/web/controllers/tool_runner.py --- a/lib/galaxy/web/controllers/tool_runner.py Sat Aug 22 23:18:47 2009 -0400 +++ b/lib/galaxy/web/controllers/tool_runner.py Sat Aug 22 23:20:09 2009 -0400 @@ -82,7 +82,7 @@ job = assoc.job break if not job: - raise Exception("Failed to get job information for dataset hid %d" % hid) + raise Exception("Failed to get job information for dataset hid %d" % data.hid) # Get the tool object tool_id = job.tool_id try: diff -r fbad627b45ac -r e6dda627e6b0 lib/galaxy/web/controllers/user.py --- a/lib/galaxy/web/controllers/user.py Sat Aug 22 23:18:47 2009 -0400 +++ b/lib/galaxy/web/controllers/user.py Sat Aug 22 23:20:09 2009 -0400 @@ -229,6 +229,8 @@ def manage_addresses(self, trans, **kwd): if trans.user: 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' ) ) if show_filter == 'All': addresses = [address for address in trans.user.addresses] @@ -238,7 +240,9 @@ addresses = [address for address in trans.user.addresses if not address.deleted] return trans.fill_template( 'user/address.mako', addresses=addresses, - show_filter=show_filter) + show_filter=show_filter, + msg=msg, + messagetype=messagetype) else: # User not logged in, history group must be only public return trans.show_error_message( "You must be logged in to change your default permitted actions." ) diff -r fbad627b45ac -r e6dda627e6b0 lib/galaxy/web/framework/base.py --- a/lib/galaxy/web/framework/base.py Sat Aug 22 23:18:47 2009 -0400 +++ b/lib/galaxy/web/framework/base.py Sat Aug 22 23:20:09 2009 -0400 @@ -216,11 +216,18 @@ # tempfiles. Necessary for externalizing the upload tool. It's a little hacky # but for performance reasons it's way better to use Paste's tempfile than to # create a new one and copy. -import cgi +import cgi, tempfile class FieldStorage( cgi.FieldStorage ): def make_file(self, binary=None): - import tempfile return tempfile.NamedTemporaryFile() + def read_lines(self): + # Always make a new file + self.file = self.make_file() + self.__file = None + if self.outerboundary: + self.read_lines_to_outerboundary() + else: + self.read_lines_to_eof() cgi.FieldStorage = FieldStorage class Request( webob.Request ): diff -r fbad627b45ac -r e6dda627e6b0 static/welcome.html --- a/static/welcome.html Sat Aug 22 23:18:47 2009 -0400 +++ b/static/welcome.html Sat Aug 22 23:20:09 2009 -0400 @@ -71,7 +71,7 @@ <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td> - <a href="javascript:parent.show_in_overlay({url:'http://screencast.g2.bx.psu.edu/galaxy/quickie1_TabSeq/flow.html',width:640,height:500,scroll:'no'})"> + <a href="javascript:parent.show_in_overlay({url:'http://screencast.g2.bx.psu.edu/galaxy/quickie1_TabSeq/quickie1_TabSeq.flv',width:640,height:500,scroll:'no'})"> <div class="quickie"> <img src="images/qk/quickie1_small.png" border="0"> </div> diff -r fbad627b45ac -r e6dda627e6b0 templates/admin/forms/edit_form.mako --- a/templates/admin/forms/edit_form.mako Sat Aug 22 23:18:47 2009 -0400 +++ b/templates/admin/forms/edit_form.mako Sat Aug 22 23:20:09 2009 -0400 @@ -70,7 +70,7 @@ </%def> <div class="toolForm"> - <div class="toolFormTitle">Edit form definition '${form.name}'</div> + <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, num_fields=len(form.fields) )}" method="post" > %for label, input in form_details: <div class="form-row"> diff -r fbad627b45ac -r e6dda627e6b0 templates/admin/requests/add_states.mako --- a/templates/admin/requests/add_states.mako Sat Aug 22 23:18:47 2009 -0400 +++ b/templates/admin/requests/add_states.mako Sat Aug 22 23:20:09 2009 -0400 @@ -12,9 +12,9 @@ %for element_count in range( num_states ): <div class="form-row"> <label>${1+element_count}) State name:</label> - <input type="text" name="new_element_name_${element_count}" value="" size="40"/> + <input type="text" name="state_name_${element_count}" value="" size="40"/> <label>State help text (optional):</label> - <input type="text" name="new_element_description_${element_count}" value="" size="40"/> + <input type="text" name="state_desc_${element_count}" value="" size="40"/> </div> <div style="clear: both"></div> %endfor diff -r fbad627b45ac -r e6dda627e6b0 templates/admin/requests/edit_request.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/admin/requests/edit_request.mako Sat Aug 22 23:20:09 2009 -0400 @@ -0,0 +1,88 @@ +<%inherit file="/base.mako"/> +<%namespace file="/message.mako" import="render_msg" /> + +%if msg: + ${render_msg( msg, messagetype )} +%endif + +<script type="text/javascript"> +$( function() { + $( "select[refresh_on_change='true']").change( function() { + var refresh = false; + var refresh_on_change_values = $( this )[0].attributes.getNamedItem( 'refresh_on_change_values' ) + if ( refresh_on_change_values ) { + refresh_on_change_values = refresh_on_change_values.value.split( ',' ); + var last_selected_value = $( this )[0].attributes.getNamedItem( 'last_selected_value' ); + for( i= 0; i < refresh_on_change_values.length; i++ ) { + if ( $( this )[0].value == refresh_on_change_values[i] || ( last_selected_value && last_selected_value.value == refresh_on_change_values[i] ) ){ + refresh = true; + break; + } + } + } + else { + refresh = true; + } + if ( refresh ){ + $( "#edit_request" ).submit(); + } + }); +}); +</script> + +<br/> +<br/> +<ul class="manage-table-actions"> + <li> + <a class="action-button" href="${h.url_for( controller='requests_admin', action='list', operation='show_request', id=trans.security.encode_id(request.id) )}"> + <span>Browse this request</span></a> + </li> + <li> + <a class="action-button" href="${h.url_for( controller='requests_admin', action='list')}"> + <span>Browse requests</span></a> + </li> +</ul> + +<div class="toolForm"> + <div class="toolFormTitle">Edit request "${request.name}" from ${request.user.email}</div> + %if len(select_request_type.options) == 1: + There are no request types created for a new request. + %else: + <div class="toolFormBody"> + <form name="edit_request" id="edit_request" action="${h.url_for( controller='requests_admin', action='edit', request_id=request.id)}" method="post" > + <div class="form-row"> + <label> + Select Request Type: + </label> + ${select_request_type.get_html()} + </div> + + %if select_request_type.get_selected() != ('Select one', 'none'): + %for i, field in enumerate(widgets): + <div class="form-row"> + <label>${field['label']}</label> + ${field['widget'].get_html()} + %if field['label'] == 'Library' and new_library: + ${new_library.get_html()} + %endif + <div class="toolParamHelp" style="clear: both;"> + ${field['helptext']} + </div> + <div style="clear: both"></div> + </div> + %endfor + <div class="form-row"> + <div style="float: left; width: 250px; margin-right: 10px;"> + <input type="hidden" name="refresh" value="true" size="40"/> + </div> + <div style="clear: both"></div> + </div> + <div class="form-row"> + <input type="submit" name="save_changes_request_button" value="Save changes"/> + ##<input type="submit" name="edit_samples_button" value="Edit samples"/> + </div> + %endif + </form> + </div> +</div> +%endif \ No newline at end of file diff -r fbad627b45ac -r e6dda627e6b0 templates/admin/requests/grid.mako --- a/templates/admin/requests/grid.mako Sat Aug 22 23:18:47 2009 -0400 +++ b/templates/admin/requests/grid.mako Sat Aug 22 23:20:09 2009 -0400 @@ -76,29 +76,28 @@ <div class="grid-header"> <h2>${grid.title}</h2> - ##%if len(query.all()): + %if len(trans.app.model.Request.query().all()): ##<span class="title">Filter:</span> %for i, filter in enumerate( grid.standard_filters ): %if i > 0: <span>|</span> %endif - %if 'state' in grid.default_filter: - %if grid.default_filter['state'] == 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 + %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: - %if filter.label == 'All': - <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 + <span class="filter"><a href="${h.url_for( controller='requests_admin', action='list', show_filter=filter.label )}">${filter.label}</a></span> %endif %endfor - ##%endif + %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. diff -r fbad627b45ac -r e6dda627e6b0 templates/admin/requests/new_request.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/admin/requests/new_request.mako Sat Aug 22 23:20:09 2009 -0400 @@ -0,0 +1,84 @@ +<%inherit file="/base.mako"/> +<%namespace file="/message.mako" import="render_msg" /> + +%if msg: + ${render_msg( msg, messagetype )} +%endif + +<script type="text/javascript"> +$( function() { + $( "select[refresh_on_change='true']").change( function() { + var refresh = false; + var refresh_on_change_values = $( this )[0].attributes.getNamedItem( 'refresh_on_change_values' ) + if ( refresh_on_change_values ) { + refresh_on_change_values = refresh_on_change_values.value.split( ',' ); + var last_selected_value = $( this )[0].attributes.getNamedItem( 'last_selected_value' ); + for( i= 0; i < refresh_on_change_values.length; i++ ) { + if ( $( this )[0].value == refresh_on_change_values[i] || ( last_selected_value && last_selected_value.value == refresh_on_change_values[i] ) ){ + refresh = true; + break; + } + } + } + else { + refresh = true; + } + if ( refresh ){ + $( "#new_request" ).submit(); + } + }); +}); +</script> + +<br/> +<br/> +<ul class="manage-table-actions"> + <li> + <a class="action-button" href="${h.url_for( controller='requests_admin', action='list')}"> + <span>Browse requests</span></a> + </li> +</ul> + +<div class="toolForm"> + <div class="toolFormTitle">Add a new request</div> + %if len(select_request_type.options) == 1: + There are no request types created for a new request. + %else: + <div class="toolFormBody"> + <form name="new_request" id="new_request" action="${h.url_for( controller='requests_admin', action='new', create=True )}" method="post" > + <div class="form-row"> + <label> + Select Request Type + </label> + ${select_request_type.get_html()} + </div> + + %if select_request_type.get_selected() != ('Select one', 'none'): + %for i, field in enumerate(widgets): + <div class="form-row"> + <label>${field['label']}</label> + ${field['widget'].get_html()} + %if field['label'] == 'Library' and new_library: + ${new_library.get_html()} + %endif + <div class="toolParamHelp" style="clear: both;"> + ${field['helptext']} + </div> + <div style="clear: both"></div> + </div> + %endfor + <div class="form-row"> + <div style="float: left; width: 250px; margin-right: 10px;"> + <input type="hidden" name="refresh" value="true" size="40"/> + </div> + <div style="clear: both"></div> + </div> + <div class="form-row"> + <input type="submit" name="create_request_button" value="Save"/> + <input type="submit" name="create_request_samples_button" value="Add samples"/> + </div> + %endif + </form> + </div> +</div> +%endif \ No newline at end of file diff -r fbad627b45ac -r e6dda627e6b0 templates/admin/requests/show_request.mako --- a/templates/admin/requests/show_request.mako Sat Aug 22 23:18:47 2009 -0400 +++ b/templates/admin/requests/show_request.mako Sat Aug 22 23:20:09 2009 -0400 @@ -12,18 +12,49 @@ </div> <ul class="manage-table-actions"> - <li> - <a class="action-button" href="${h.url_for( controller='requests_admin', action='bar_codes', request_id=request.id)}"> - <span>Bar codes</span></a> - </li> + %if request.unsubmitted() and request.samples: + <li> + <a class="action-button" confirm="More samples cannot be added to this request once it is submitted. Click OK to submit." href="${h.url_for( controller='requests_admin', action='submit_request', id=request.id)}"> + <span>Submit request</span></a> + </li> + %endif + %if request.submitted() and request.samples: + <li> + <a class="action-button" href="${h.url_for( controller='requests_admin', action='bar_codes', request_id=request.id)}"> + <span>Bar codes</span></a> + </li> + %endif </ul> + +<%def name="render_sample_form( index, sample_name, sample_values )"> + <td> + <input type="text" name=sample_${index}_name value="${sample_name}" size="10"/> + <div class="toolParamHelp" style="clear: both;"> + <i>${' (required)' }</i> + </div> + </td> + <td> + </td> + %for field_index, field in enumerate(request.type.sample_form.fields): + <td> + <input type="text" name=sample_${index}_field_${field_index} value="${sample_values[field_index]}" size="7"/> + <div class="toolParamHelp" style="clear: both;"> + <i>${'('+field['required']+')' }</i> + </div> + </td> + %endfor +</%def> <%def name="render_sample( index, sample )"> <td> ${sample.name} </td> <td> - <a href="${h.url_for( controller='requests_admin', action='show_events', sample_id=sample.id)}">${sample.current_state().name}</a> + %if sample.request.unsubmitted(): + Unsubmitted + %else: + <a href="${h.url_for( controller='requests_admin', action='show_events', sample_id=sample.id)}">${sample.current_state().name}</a> + %endif </td> %for field_index, field in enumerate(request.type.sample_form.fields): <td> @@ -34,10 +65,10 @@ %endif </td> %endfor + </%def> <div class="toolForm"> - ##<div class="toolFormTitle">Request Details: '${request_details[0]['value']}'</div> <div class="form-row"> <a href="${h.url_for( controller='requests_admin', action='toggle_request_details', request_id=request.id )}">${details_state}</a> </div> @@ -57,13 +88,21 @@ </div> <div style="clear: both"></div> %endfor + <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)}"> + <span>Edit request details</span></a> + </li> + </ul> + </div> %endif </div> </div> <div class="toolForm"> ##<div class="toolFormTitle">Samples (${len(request.samples)})</div> - <form id="edit_form" name="edit_form" action="${h.url_for( controller='requests', action='show_request', request_id=request.id )}" method="post" > + <form id="edit_form" name="edit_form" action="${h.url_for( controller='requests_admin', action='show_request' )}" enctype="multipart/form-data" method="post" > <div class="form-row"> %if current_samples: <table class="grid"> @@ -80,22 +119,88 @@ </div> </th> %endfor + <th></th> </tr> <thead> <tbody> + <% + request.refresh() + %> %for sample_index, sample in enumerate(current_samples): - <tr> - <td>${sample_index+1}</td> - ${render_sample( sample_index, request.samples[sample_index] )} - </tr> + %if edit_mode: + <tr> + <td>${sample_index+1}</td> + ${render_sample_form( sample_index, sample[0], sample[1])} + </tr> + %else: + <tr> + <td>${sample_index+1}</td> + %if sample_index in range(len(request.samples)): + ${render_sample( sample_index, request.samples[sample_index] )} + %else: + ${render_sample_form( sample_index, sample[0], sample[1])} + %endif + <td> + %if request.unsubmitted(): + <a class="action-button" href="${h.url_for( controller='requests_admin', action='delete_sample', request_id=request.id, sample_id=sample_index)}"> + <img src="${h.url_for('/static/images/delete_icon.png')}" /> + <span></span></a> + %endif + </td> + </tr> + %endif %endfor </tbody> </table> %else: <label>There are no samples.</label> %endif - </div> - ##</div> + %if not edit_mode: + <table class="grid"> + <tbody> + <tr> + <div class="form-row"> + <td> + %if current_samples and not request.complete(): + <input type="submit" name="edit_samples_button" value="Edit samples"/> + %endif + </td> + %if request.unsubmitted(): + <td> + <label>Import from csv file</label> + <input type="file" name="file_data" /> + <input type="submit" name="import_samples_button" value="Import samples"/> + </td> + <td> + %if current_samples: + <label>Copy from sample</label> + ${sample_copy.get_html()} + %endif + <input type="submit" name="add_sample_button" value="Add New"/> + </td> + %endif + </div> + </tr> + </tbody> + </table> + %endif + %if request.samples or current_samples: + <div class="form-row"> + <div style="float: left; width: 250px; margin-right: 10px;"> + <input type="hidden" name="refresh" value="true" size="40"/> + </div> + <div style="clear: both"></div> + </div> + <div class="form-row"> + %if edit_mode: + <input type="submit" name="save_samples_button" value="Save"/> + <input type="submit" name="cancel_changes_button" value="Cancel"/> + %elif request.unsubmitted(): + <input type="submit" name="save_samples_button" value="Save"/> + %endif + </div> + %endif + <input type="hidden" name="request_id" value="${request.id}" /> </form> </div> diff -r fbad627b45ac -r e6dda627e6b0 templates/admin/samples/bar_codes.mako --- a/templates/admin/samples/bar_codes.mako Sat Aug 22 23:18:47 2009 -0400 +++ b/templates/admin/samples/bar_codes.mako Sat Aug 22 23:20:09 2009 -0400 @@ -40,7 +40,7 @@ </tbody> </table> <div class="form-row"> - <input type="submit" name="save_new_sample_type" value="Save"/> + <input type="submit" name="save_bar_codes" value="Save"/> </div> </form> </div> \ No newline at end of file diff -r fbad627b45ac -r e6dda627e6b0 templates/admin/samples/events.mako --- a/templates/admin/samples/events.mako Sat Aug 22 23:18:47 2009 -0400 +++ b/templates/admin/samples/events.mako Sat Aug 22 23:20:09 2009 -0400 @@ -56,7 +56,7 @@ </div> %endfor <div class="form-row"> - <input type="submit" name="add_event" value="Save"/> + <input type="submit" name="add_event_button" value="Save"/> </div> </form> </div> diff -r fbad627b45ac -r e6dda627e6b0 templates/base_panels.mako --- a/templates/base_panels.mako Sat Aug 22 23:18:47 2009 -0400 +++ b/templates/base_panels.mako Sat Aug 22 23:20:09 2009 -0400 @@ -138,7 +138,7 @@ ${tab( "libraries", "Data Libraries", h.url_for( controller='library', action='index' ))} - %if trans.request_types(): + %if trans.user and trans.request_types(): <td class="tab"> <a>Lab</a> <div class="submenu"> diff -r fbad627b45ac -r e6dda627e6b0 templates/requests/grid.mako --- a/templates/requests/grid.mako Sat Aug 22 23:18:47 2009 -0400 +++ b/templates/requests/grid.mako Sat Aug 22 23:20:09 2009 -0400 @@ -76,7 +76,7 @@ <div class="grid-header"> <h2>${grid.title}</h2> - ##%if len(query.all()): + %if len(trans.user.requests): ##<span class="title">Filter:</span> %for i, filter in enumerate( grid.standard_filters ): %if i > 0: @@ -88,17 +88,16 @@ <span class="filter"><a href="${h.url_for( controller='requests', action='list', show_filter=filter.label )}">${filter.label}</a></span> %endif %endfor - ##%endif + %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>New request</span></a> + <span>Create a new request</span></a> </li> </ul> - %if not len(query.all()): There are no request(s). @@ -215,4 +214,4 @@ </tfoot> </table> </form> -%endif \ No newline at end of file +%endif diff -r fbad627b45ac -r e6dda627e6b0 templates/requests/show_request.mako --- a/templates/requests/show_request.mako Sat Aug 22 23:18:47 2009 -0400 +++ b/templates/requests/show_request.mako Sat Aug 22 23:20:09 2009 -0400 @@ -68,7 +68,6 @@ </%def> <div class="toolForm"> - ##<div class="toolFormTitle">Request Details: '${request_details[0]['value']}'</div> <div class="form-row"> <a href="${h.url_for( controller='requests', action='toggle_request_details', request_id=request.id )}">${details_state}</a> </div> @@ -217,7 +216,6 @@ %endif </div> %endif - ##</div> - <input type="hidden" name="request_id" value="${request.id}" /> + <input type="hidden" name="request_id" value="${request.id}" /> </form> </div> diff -r fbad627b45ac -r e6dda627e6b0 templates/user/address.mako --- a/templates/user/address.mako Sat Aug 22 23:18:47 2009 -0400 +++ b/templates/user/address.mako Sat Aug 22 23:20:09 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 fbad627b45ac -r e6dda627e6b0 test/base/twilltestcase.py --- a/test/base/twilltestcase.py Sat Aug 22 23:18:47 2009 -0400 +++ b/test/base/twilltestcase.py Sat Aug 22 23:20:09 2009 -0400 @@ -972,7 +972,7 @@ self.home() # Form stuff - def create_form( self, name='Form One', description='This is Form One', num_fields=1 ): + def create_form( self, name='Form One', desc='This is Form One', num_fields=1 ): """ Create a new form definition. Testing framework is still limited to only testing one instance for each repeat. This has to do with the 'flat' nature of defining @@ -988,7 +988,7 @@ self.visit_url( "%s/forms/new" % self.url ) self.check_page_for_string( 'Create a new form definition' ) tc.fv( "1", "name", name ) # form field 1 is the field named name... - tc.fv( "1", "description", description ) # form field 1 is the field named name... + tc.fv( "1", "description", desc ) # form field 1 is the field named name... tc.submit( "create_form_button" ) for index in range( num_fields ): field_name = 'field_name_%i' % index @@ -1001,7 +1001,140 @@ check_str = "The form '%s' has been updated with the changes." % name self.check_page_for_string( check_str ) 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)"): + """ + Edit form details; name & description + """ + self.home() + self.visit_url( "%s/forms/edit?form_id=%i&show_form=True" % (self.url, form_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, 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.check_page_for_string( 'Edit form definition "%s"' % form_name) + for i, field in enumerate(fields): + index = i+field_index + tc.submit( "add_field_button" ) + tc.fv( "1", "field_name_%i" % index, field['name'] ) + tc.fv( "1", "field_helptext_%i" % index, field['desc'] ) + tc.fv( "1", "field_type_%i" % index, field['type'] ) + tc.fv( "1", "field_required_%i" % index, field['required'] ) +# if field['type'] == 'SelectField': +# for option_index, option in enumerate(field['selectlist']): +# self.visit_url( "%s/forms/edit?select_box_options=add&form_id=%i&field_index=%i" % \ +# (self.url, form_id, index)) +# #data = self.last_page() +# #file( "rc.html", 'wb' ).write(data) +# tc.fv( "1", "field_%i_option_%i" % (index, option_index), option ) + tc.submit( "save_changes_button" ) + check_str = "The form '%s' has been updated with the changes." % form_name + self.check_page_for_string( check_str ) + self.home() + def form_remove_field( self, form_id, form_name, field_name): + """ + 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.check_page_for_string( 'Edit form definition "%s"' % form_name) + tc.submit( "remove_button" ) + tc.submit( "save_changes_button" ) + check_str = "The form '%s' has been updated with the changes." % form_name + self.check_page_for_string( check_str ) + self.home() + # Requests stuff + def create_request_type( self, name, desc, request_form_id, sample_form_id, states ): + self.home() + self.visit_url( "%s/admin/request_type?create=True" % 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", "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.fv("1", "state_name_%i" % index, state[0]) + tc.fv("1", "state_desc_%i" % index, state[1]) + tc.submit( "save_request_type" ) + self.check_page_for_string( "Request type <b>%s</b> has been created" % name ) + def create_request( self, request_type_id, name, desc, library_id, fields ): + self.home() + self.visit_url( "%s/requests/new?create=True&select_request_type=%i" % (self.url, request_type_id) ) + self.check_page_for_string( 'Add a new request' ) + tc.fv( "1", "name", name ) + tc.fv( "1", "desc", desc ) + tc.fv( "1", "library_id", str(library_id) ) + for index, field_value in enumerate(fields): + tc.fv( "1", "field_%i" % index, field_value ) + tc.submit( "create_request_button" ) + def create_request_admin( self, request_type_id, user_id, name, desc, library_id, fields ): + self.home() + self.visit_url( "%s/requests_admin/new?create=True&select_request_type=%i" % (self.url, request_type_id) ) + self.check_page_for_string( 'Add a new request' ) + tc.fv( "1", "select_user", str(user_id) ) + tc.fv( "1", "name", name ) + tc.fv( "1", "desc", desc ) + tc.fv( "1", "library_id", str(library_id) ) + 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 ) )) + self.check_page_for_string( 'Sequencing Request "%s"' % request_name ) + for sample_index, sample in enumerate(samples): + tc.submit( "add_sample_button" ) + sample_name, fields = sample + tc.fv( "1", "sample_%i_name" % sample_index, sample_name ) + for field_index, field_value in enumerate(fields): + tc.fv( "1", "sample_%i_field_%i" % ( sample_index, field_index ), field_value ) + tc.submit( "save_samples_button" ) + def submit_request( self, request_id, request_name ): + self.home() + self.visit_url( "%s/requests/submit_request?id=%i" % ( self.url, request_id )) + self.check_page_for_string( 'The request <b>%s</b> has been submitted.' % request_name ) + def add_bar_codes( self, request_id, request_name, bar_codes ): + self.home() + self.visit_url( "%s/requests_admin/bar_codes?request_id=%i" % (self.url, request_id) ) + self.check_page_for_string( 'Bar codes for Samples of Request "%s"' % request_name ) + for index, bar_code in enumerate(bar_codes): + tc.fv( "1", "sample_%i_bar_code" % index, bar_code ) + tc.submit( "save_bar_codes" ) + def change_sample_state( self, sample_name, sample_id, new_state_id, comment='' ): + self.home() + self.visit_url( "%s/requests_admin/show_events?sample_id=%i" % (self.url, sample_id) ) + self.check_page_for_string( 'Events for Sample "%s"' % sample_name ) + tc.fv( "1", "select_state", str(new_state_id) ) + tc.fv( "1", "comment", comment ) + tc.submit( "add_event_button" ) + # Address stuff + def create_address( self, address ): + self.home() + self.visit_url( "%s/user/new_address" % self.url ) + self.check_page_for_string( 'New address' ) + for name, value in address.iteritems(): + tc.fv( "1", name, value ) + tc.submit( "Save_button" ) # Library stuff def create_library( self, name='Library One', description='This is Library One' ): """Create a new library""" diff -r fbad627b45ac -r e6dda627e6b0 test/functional/test_forms_and_requests.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/functional/test_forms_and_requests.py Sat Aug 22 23:20:09 2009 -0400 @@ -0,0 +1,274 @@ +import galaxy.model +from galaxy.model.orm import * +from base.twilltestcase import * + +not_logged_in_as_admin_security_msg = 'You must be logged in as an administrator to access this feature.' +logged_in_as_admin_security_msg = 'You must be an administrator to access this feature.' +not_logged_in_security_msg = 'You must be logged in to create/submit sequencing requests' +form_one_name = "Request Form" +form_two_name = "Sample Form" +request_type_name = 'Test Requestype' +sample_states = [ ( 'New', 'Sample entered into the system' ), + ( 'Received', 'Sample tube received' ), + ( 'Done', 'Sequence run complete' ) ] +address1 = dict( short_desc="Office", + name="James Bond", + institution="MI6" , + address1="MI6 Headquaters", + address2="", + city="London", + state="London", + postal_code="007", + country="United Kingdom", + phone="007-007-0007" ) + + +def get_latest_form(form_name): + fdc_list = galaxy.model.FormDefinitionCurrent.filter( galaxy.model.FormDefinitionCurrent.table.c.deleted==False )\ + .order_by( galaxy.model.FormDefinitionCurrent.table.c.create_time.desc() ) + for fdc in fdc_list: + if form_name == fdc.latest_form.name: + return fdc.latest_form + return None + + +class TestFormsAndRequests( TwillTestCase ): + def test_000_create_form( self ): + """Testing creating a new form and editing it""" + self.logout() + self.login( email='test@bx.psu.edu' ) + # create a form + global form_one_name + name = form_one_name + desc = "This is Form One's description" + self.create_form( name=name, desc=desc ) + self.home() + self.visit_page( 'forms/manage' ) + self.check_page_for_string( name ) + self.check_page_for_string( desc ) + # Get the form_definition object for later tests + form_one = galaxy.model.FormDefinition.filter( and_( galaxy.model.FormDefinition.table.c.name==name, + galaxy.model.FormDefinition.table.c.desc==desc ) ).all()[-1] + assert form_one is not None, 'Problem retrieving form named "%s" from the database' % name + # 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.home() + self.visit_page( 'forms/manage' ) + self.check_page_for_string( new_name ) + self.check_page_for_string( new_desc ) + form_one_name = new_name + def test_005_add_form_fields( self ): + """Testing adding fields to a form definition""" + fields = [dict(name='Test field name one', + desc='Test field description one', + type='TextField', + required='required'), + dict(name='Test field name two', + desc='Test field description two', + type='AddressField', + required='optional')] + form_one = get_latest_form(form_one_name) + self.form_add_field(form_one.id, form_one.name, 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) +#This following test has been commented out as it is causing: +#TwillException: multiple matches to "remove_button" +# def test_010_remove_form_fields( self ): +# """Testing removing fields from a form definition""" +# form_one = get_latest_form(form_one_name) +# self.form_remove_field( form_one.id, form_one.name, 'Test field name one' ) +# form_one_latest = get_latest_form(form_one_name) +# assert len(form_one_latest.fields) == len(form_one.fields)-1 + def test_015_create_sample_form( self ): + """Testing creating another form (for samples)""" + global form_two_name + name = form_two_name + desc = "This is Form One's description" + self.create_form( name=name, desc=desc ) + self.home() + self.visit_page( 'forms/manage' ) + self.check_page_for_string( name ) + self.check_page_for_string( desc ) + def test_020_create_request_type( self ): + """Testing creating a new requestype""" + request_form = get_latest_form(form_one_name) + sample_form = get_latest_form(form_two_name) + self.create_request_type(request_type_name, "test request type", + str(request_form.id), str(sample_form.id), sample_states ) + global request_type + request_type = galaxy.model.RequestType.filter( and_( galaxy.model.RequestType.table.c.name==request_type_name ) ).all()[-1] + assert request_type is not None, 'Problem retrieving request type named "%s" from the database' % request_type_name + def test_025_create_address_and_library( self ): + """Testing address & library creation""" + # first create a regular user + self.logout() + self.login( email='test1@bx.psu.edu' ) + self.logout() + self.login( email='test@bx.psu.edu' ) + # first create a library for the request so that it can be submitted later + lib_name = 'TestLib001' + self.create_library( lib_name, '' ) + self.visit_page( 'admin/browse_libraries' ) + self.check_page_for_string( lib_name ) + # Get the library object for later tests + global library_one + library_one = galaxy.model.Library.filter( and_( galaxy.model.Library.table.c.name==lib_name, + galaxy.model.Library.table.c.deleted==False ) ).first() + assert library_one is not None, 'Problem retrieving library named "%s" from the database' % lib_name + global admin_user + admin_user = galaxy.model.User.filter( galaxy.model.User.table.c.email=='test@bx.psu.edu' ).first() + assert admin_user is not None, 'Problem retrieving user with email "test@bx.psu.edu" from the database' + # Get the admin user's private role for later use + global admin_user_private_role + admin_user_private_role = None + for role in admin_user.all_roles(): + if role.name == admin_user.email and role.description == 'Private Role for %s' % admin_user.email: + admin_user_private_role = role + break + if not admin_user_private_role: + raise AssertionError( "Private role not found for user '%s'" % admin_user.email ) + global regular_user1 + regular_user1 = galaxy.model.User.filter( galaxy.model.User.table.c.email=='test1@bx.psu.edu' ).first() + assert regular_user1 is not None, 'Problem retrieving user with email "test1@bx.psu.edu" from the database' + # Get the regular user's private role for later use + global regular_user1_private_role + regular_user1_private_role = None + for role in regular_user1.all_roles(): + if role.name == regular_user1.email and role.description == 'Private Role for %s' % regular_user1.email: + regular_user1_private_role = role + break + if not regular_user1_private_role: + raise AssertionError( "Private role not found for user '%s'" % regular_user1.email ) + # Set permissions on the library, sort for later testing + permissions_in = [ k for k, v in galaxy.model.Library.permitted_actions.items() ] + permissions_out = [] + # Role one members are: admin_user, regular_user1. Each of these users will be permitted to + # LIBRARY_ADD, LIBRARY_MODIFY, LIBRARY_MANAGE for library items. + self.set_library_permissions( str( library_one.id ), library_one.name, str( regular_user1_private_role.id ), permissions_in, permissions_out ) + # create address + #self.create_address( user_address1 ) + #self.check_page_for_string( 'Address <b>%s</b> has been added' % user_address1[ 'short_desc' ] ) + ## TODO: FIX HACK + ## the user address creation should be done as a test. + global user_address + user_address = galaxy.model.UserAddress() + user_address.user = galaxy.model.User.filter( galaxy.model.User.table.c.email=='test1@bx.psu.edu' ).first() + user_address.desc = address1[ 'short_desc' ] + user_address.name = address1[ 'name' ] + user_address.institution = address1[ 'institution' ] + user_address.address = address1[ 'address1' ]+' '+address1[ 'address2' ] + user_address.city = address1[ 'city' ] + user_address.state = address1[ 'state' ] + user_address.postal_code = address1[ 'postal_code' ] + user_address.country = address1[ 'country' ] + user_address.phone = address1[ 'phone' ] + user_address.flush() + user_address.user.refresh() + def test_030_create_request( self ): + """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' ) + # set field values + fields = ['field one value', 'field two value', str(user_address.id)] + # create the request + request_name, request_desc = 'Request One', 'Request One Description' + self.create_request(request_type.id, request_name, request_desc, library_one.id, fields) + self.check_page_for_string( request_name ) + self.check_page_for_string( request_desc ) + global request_one + request_one = galaxy.model.Request.filter( and_( galaxy.model.Request.table.c.name==request_name, + galaxy.model.Request.table.c.deleted==False ) ).first() + # check if the request's state is now set to 'unsubmitted' + assert request_one.state is not request_one.states.UNSUBMITTED, "The state of the request '%s' should be set to '%s'" % ( request_one.name, request_one.states.UNSUBMITTED ) + # sample fields + samples = [ ( 'Sample One', [ 'S1 Field 0 Value' ] ), + ( 'Sample Two', [ 'S2 Field 0 Value' ] ) ] + # add samples to this request + self.add_samples( request_one.id, request_one.name, samples ) + for sample_name, fields in samples: + self.check_page_for_string( sample_name ) + 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() + # 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 ) + def test_035_request_lifecycle( self ): + """Testing request lifecycle as it goes through all the states""" + # 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.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 ) + # set bar codes for the samples + bar_codes = [ '1234567890', '0987654321' ] + self.add_bar_codes( request_one.id, request_one.name, bar_codes ) + self.check_page_for_string( 'Bar codes has been saved for this request' ) + # change the states of all the samples of this request + for sample in request_one.samples: + self.change_sample_state( sample.name, sample.id, request_type.states[1].id ) + self.check_page_for_string( request_type.states[1].name ) + self.check_page_for_string( request_type.states[1].desc ) + self.change_sample_state( sample.name, sample.id, request_type.states[2].id ) + self.check_page_for_string( request_type.states[2].name ) + self.check_page_for_string( request_type.states[2].desc ) + self.home() + request_one.refresh() + # check if the request's state is now set to 'complete' + 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_40_admin_create_request_on_behalf_of_regular_user( self ): +# """Testing creating and submitting a request as an admin on behalf of a regular user""" +# self.logout() +# self.login( email='test@bx.psu.edu' ) +## permissions_in = [ k for k, v in galaxy.model.Library.permitted_actions.items() ] +## permissions_out = [] +## self.set_library_permissions( str( library_one.id ), library_one.name, str( admin_user_private_role.id ), permissions_in, permissions_out ) +# # set field values +# fields = ['field one value', 'field two value', str(user_address.id)] +# # create the request +# request_name, request_desc = 'Request Two', 'Request Two Description' +# self.create_request_admin(request_type.id, regular_user1.id, request_name, request_desc, library_one.id, fields) +# self.check_page_for_string( request_name ) +# self.check_page_for_string( request_desc ) +# global request_two +# request_one = galaxy.model.Request.filter( and_( galaxy.model.Request.table.c.name==request_name, +# galaxy.model.Request.table.c.deleted==False ) ).first() +# # 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 ) +# # sample fields +# samples = [ ( 'Sample One', [ 'S1 Field 0 Value' ] ), +# ( 'Sample Two', [ 'S2 Field 0 Value' ] ) ] +# # add samples to this request +# self.add_samples( request_two.id, request_two.name, samples ) +# for sample_name, fields in samples: +# self.check_page_for_string( sample_name ) +# self.check_page_for_string( 'Unsubmitted' ) +# for field_value in fields: +# self.check_page_for_string( field_value ) +# # submit the request +# self.submit_request( request_two.id, request_two.name ) +# request_two.refresh() +# # 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 ) + + + + + + + \ No newline at end of file diff -r fbad627b45ac -r e6dda627e6b0 test/functional/test_security_and_libraries.py --- a/test/functional/test_security_and_libraries.py Sat Aug 22 23:18:47 2009 -0400 +++ b/test/functional/test_security_and_libraries.py Sat Aug 22 23:20:09 2009 -0400 @@ -196,7 +196,7 @@ dhps.sort() # Compare DefaultHistoryPermissions and actions_in - should be the same if dhps != actions_in: - raise AssertionError( 'DefaultHistoryPermissions "%s" for history id %d differ from actions "%s" passed for changing' \ + raise AssertionError( 'DefaultHistoryPermissions "%s" for history id %d differ from actions "%s" passed for changing' \ % ( str( dhps ), latest_history.id, str( actions_in ) ) ) # Make sure DatasetPermissionss are correct if len( latest_dataset.actions ) != len( latest_history.default_permissions ): @@ -209,7 +209,7 @@ dps.sort() # Compare DatasetPermissionss and DefaultHistoryPermissions - should be the same if dps != dhps: - raise AssertionError( 'DatasetPermissionss "%s" for dataset id %d differ from DefaultHistoryPermissions "%s"' \ + raise AssertionError( 'DatasetPermissionss "%s" for dataset id %d differ from DefaultHistoryPermissions "%s"' \ % ( str( dps ), latest_dataset.id, str( dhps ) ) ) self.logout() def test_020_create_new_user_account_as_admin( self ): diff -r fbad627b45ac -r e6dda627e6b0 tools/extract/liftOver_wrapper_code.py --- a/tools/extract/liftOver_wrapper_code.py Sat Aug 22 23:18:47 2009 -0400 +++ b/tools/extract/liftOver_wrapper_code.py Sat Aug 22 23:20:09 2009 -0400 @@ -3,7 +3,6 @@ to_dbkey = param_dict['to_dbkey'].split('.')[0].split('To')[1] to_dbkey = to_dbkey[0].lower()+to_dbkey[1:] out_data['out_file1'].set_dbkey(to_dbkey) - out_data['out_file2'].set_dbkey(to_dbkey) out_data['out_file1'].name = out_data['out_file1'].name + " [ MAPPED COORDINATES ]" out_data['out_file2'].name = out_data['out_file2'].name + " [ UNMAPPED COORDINATES ]" diff -r fbad627b45ac -r e6dda627e6b0 tools/metag_tools/split_paired_reads.py --- a/tools/metag_tools/split_paired_reads.py Sat Aug 22 23:18:47 2009 -0400 +++ b/tools/metag_tools/split_paired_reads.py Sat Aug 22 23:20:09 2009 -0400 @@ -1,7 +1,7 @@ #! /usr/bin/python """ -Split Solexa paired end reads +Split fixed length paired end reads """ import os, sys @@ -12,9 +12,13 @@ outfile_end1 = open(sys.argv[2], 'w') outfile_end2 = open(sys.argv[3], 'w') - for i, line in enumerate(file(infile)): + i = 0 + + for line in file( infile ): line = line.rstrip() - if not line or line.startswith('#'): continue + + if not line: + continue end1 = '' end2 = '' @@ -42,5 +46,9 @@ outfile_end1.write('%s\n' %(end1)) outfile_end2.write('%s\n' %(end2)) + i += 1 + + if i % 4 != 0 : + sys.stderr.write("WARNING: Number of lines in the input file was not divisible by 4.\nCheck consistency of the input fastq file.\n") outfile_end1.close() outfile_end2.close() \ No newline at end of file diff -r fbad627b45ac -r e6dda627e6b0 tools/solid_tools/maq_cs_wrapper.py --- a/tools/solid_tools/maq_cs_wrapper.py Sat Aug 22 23:18:47 2009 -0400 +++ b/tools/solid_tools/maq_cs_wrapper.py Sat Aug 22 23:20:09 2009 -0400 @@ -48,9 +48,9 @@ cmd1 = "solid2fastq_modified.pl 'yes' %s %s %s %s %s %s %s 2>&1" %(tmpf.name,tmpr.name,tmps.name,f3_read_fname,f3_qual_fname,r3_read_fname,r3_qual_fname) try: os.system(cmd1) - os.system('zcat -f %s >> %s' %(tmpf.name,tmpffastq.name)) - os.system('zcat -f %s >> %s' %(tmpr.name,tmprfastq.name)) - os.system('zcat -f %s >> %s' %(tmps.name,tmpsfastq.name)) + os.system('gunzip -c %s >> %s' %(tmpf.name,tmpffastq.name)) + os.system('gunzip -c %s >> %s' %(tmpr.name,tmprfastq.name)) + os.system('gunzip -c %s >> %s' %(tmps.name,tmpsfastq.name)) except Exception, eq: stop_err("Error converting data to fastq format." + str(eq)) @@ -135,7 +135,7 @@ cmd1 = "solid2fastq_modified.pl 'no' %s %s %s %s %s %s %s 2>&1" %(tmpf.name,None,None,f3_read_fname,f3_qual_fname,None,None) try: os.system(cmd1) - os.system('zcat -f %s >> %s' %(tmpf.name,tmpfastq.name)) + os.system('gunzip -c %s >> %s' %(tmpf.name,tmpfastq.name)) tmpf.close() except: stop_err("Error converting data to fastq format.")
participants (1)
-
Greg Von Kuster