details: http://www.bx.psu.edu/hg/galaxy/rev/c40962280e72 changeset: 2700:c40962280e72 user: rc date: Wed Sep 16 12:39:57 2009 -0400 description: Forms: - Added 'type' and 'layout' columns to the form_definition table - Added types to forms; Request, Sample & Library info template - Added layouts to sample form definition to support multiple grids while rendering Requests: - Added 'folder_id' column to the request table - Added the Data Library Folder selectbox when creating a new request - Moved the 4 request_type methods to requests_admin from admin controller Updated the functional tests 21 file(s) affected in this change: lib/galaxy/model/__init__.py lib/galaxy/model/mapping.py lib/galaxy/model/migrate/versions/0019_request_library_folder.py lib/galaxy/web/controllers/admin.py lib/galaxy/web/controllers/forms.py lib/galaxy/web/controllers/library.py lib/galaxy/web/controllers/requests.py lib/galaxy/web/controllers/requests_admin.py lib/galaxy/web/form_builder.py templates/admin/forms/edit_form.mako templates/admin/forms/manage_forms.mako templates/admin/index.mako templates/admin/requests/add_states.mako templates/admin/requests/create_request_type.mako templates/admin/requests/manage_request_types.mako templates/admin/requests/show_request.mako templates/admin/requests/view_request_type.mako templates/requests/new_request.mako templates/requests/show_request.mako test/base/twilltestcase.py test/functional/test_forms_and_requests.py diffs (1969 lines): diff -r 1fb29bd2725a -r c40962280e72 lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py Wed Sep 16 11:27:50 2009 -0400 +++ b/lib/galaxy/model/__init__.py Wed Sep 16 12:39:57 2009 -0400 @@ -1005,11 +1005,31 @@ return os.path.abspath( os.path.join( path, "metadata_%d.dat" % self.id ) ) class FormDefinition( object ): - def __init__(self, name=None, desc=None, fields=[], current_form=None): + types = Bunch( REQUEST = 'Sequencing Request Form', + SAMPLE = 'Sequencing Sample Form', + LIBRARY_INFO_TEMPLATE = 'Library information template' ) + def __init__(self, name=None, desc=None, fields=[], current_form=None, form_type=None, layout=None): self.name = name self.desc = desc self.fields = fields self.form_definition_current = current_form + self.type = form_type + self.layout = layout + def fields_of_grid(self, layout_grid_name): + fields_dict = {} + if not layout_grid_name: + for i, f in enumerate(self.fields): + fields_dict[i] = f + else: + layout_index = -1 + for index, lg_name in enumerate(self.layout): + if lg_name == layout_grid_name: + layout_index = index + break + for i, f in enumerate(self.fields): + if f['layout'] == str(layout_index): + fields_dict[i] = f + return fields_dict class FormDefinitionCurrent( object ): def __init__(self, form_definition=None): @@ -1025,13 +1045,14 @@ SUBMITTED = 'Submitted', COMPLETE = 'Complete') def __init__(self, name=None, desc=None, request_type=None, user=None, - form_values=None, library=None, state=False): + form_values=None, library=None, folder=None, state=False): self.name = name self.desc = desc self.type = request_type self.values = form_values self.user = user self.library = library + self.folder = folder self.state = state self.samples_list = [] def add_sample(self, sample_name=None, sample_desc=None, sample_values=None): diff -r 1fb29bd2725a -r c40962280e72 lib/galaxy/model/mapping.py --- a/lib/galaxy/model/mapping.py Wed Sep 16 11:27:50 2009 -0400 +++ b/lib/galaxy/model/mapping.py Wed Sep 16 12:39:57 2009 -0400 @@ -465,7 +465,9 @@ Integer, ForeignKey( "form_definition_current.id", name='for_def_form_def_current_id_fk', use_alter=True ), index=True ), - Column( "fields", JSONType() ) ) + Column( "fields", JSONType() ), + Column( "type", TrimmedString( 255 ), index=True ), + Column( "layout", JSONType() ), ) RequestType.table = Table('request_type', metadata, Column( "id", Integer, primary_key=True), @@ -494,6 +496,7 @@ Column( "request_type_id", Integer, ForeignKey( "request_type.id" ), index=True ), Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), Column( "library_id", Integer, ForeignKey( "library.id" ), index=True ), + Column( "folder_id", Integer, ForeignKey( "library_folder.id" ), index=True ), Column( "state", TrimmedString( 255 ), index=True ), Column( "deleted", Boolean, index=True, default=False ) ) @@ -612,8 +615,10 @@ backref="requests" ), samples=relation( Sample, primaryjoin=( Request.table.c.id == Sample.table.c.request_id ) ), + folder=relation( LibraryFolder, + primaryjoin=( Request.table.c.folder_id == LibraryFolder.table.c.id ) ), library=relation( Library, - primaryjoin=( Request.table.c.library_id == Library.table.c.id ) ), + primaryjoin=( Request.table.c.library_id == Library.table.c.id ) ) ) ) assign_mapper( context, RequestType, RequestType.table, diff -r 1fb29bd2725a -r c40962280e72 lib/galaxy/model/migrate/versions/0019_request_library_folder.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/galaxy/model/migrate/versions/0019_request_library_folder.py Wed Sep 16 12:39:57 2009 -0400 @@ -0,0 +1,84 @@ +from sqlalchemy import * +from sqlalchemy.orm import * +from sqlalchemy.exceptions import * +from migrate import * +from migrate.changeset import * +import datetime +now = datetime.datetime.utcnow +import sys, logging +# Need our custom types, but don't import anything else from model +from galaxy.model.custom_types import * + +log = logging.getLogger( __name__ ) +log.setLevel(logging.DEBUG) +handler = logging.StreamHandler( sys.stdout ) +format = "%(name)s %(levelname)s %(asctime)s %(message)s" +formatter = logging.Formatter( format ) +handler.setFormatter( formatter ) +log.addHandler( handler ) + +metadata = MetaData( migrate_engine ) +db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, transactional=False ) ) + +def display_migration_details(): + print "========================================" + print """This script creates a request.folder_id column which is a foreign +key to the library_folder table. This also adds a 'type' and 'layout' column +to the form_definition table.""" + print "========================================" + +def upgrade(): + display_migration_details() + # Load existing tables + metadata.reflect() + # Create the folder_id column + try: + Request_table = Table( "request", metadata, autoload=True ) + except NoSuchTableError: + Request_table = None + log.debug( "Failed loading table request" ) + if Request_table: + try: + col = Column( "folder_id", Integer, index=True ) + col.create( Request_table ) + assert col is Request_table.c.folder_id + except Exception, e: + log.debug( "Adding column 'folder_id' to request table failed: %s" % ( str( e ) ) ) + try: + LibraryFolder_table = Table( "library_folder", metadata, autoload=True ) + except NoSuchTableError: + Request_table = None + log.debug( "Failed loading table library_folder" ) + # Add 1 foreign key constraint to the library_folder table + if Request_table and LibraryFolder_table: + try: + cons = ForeignKeyConstraint( [Request_table.c.folder_id], + [LibraryFolder_table.c.id], + name='request_folder_id_fk' ) + # Create the constraint + cons.create() + except Exception, e: + log.debug( "Adding foreign key constraint 'request_folder_id_fk' to table 'library_folder' failed: %s" % ( str( e ) ) ) + # Create the type column in form_definition + try: + FormDefinition_table = Table( "form_definition", metadata, autoload=True ) + except NoSuchTableError: + FormDefinition_table = None + log.debug( "Failed loading table form_definition" ) + if FormDefinition_table: + try: + col = Column( "type", TrimmedString( 255 ), index=True ) + col.create( FormDefinition_table ) + assert col is FormDefinition_table.c.type + except Exception, e: + log.debug( "Adding column 'type' to form_definition table failed: %s" % ( str( e ) ) ) + try: + col = Column( "layout", JSONType()) + col.create( FormDefinition_table ) + assert col is FormDefinition_table.c.layout + except Exception, e: + log.debug( "Adding column 'layout' to form_definition table failed: %s" % ( str( e ) ) ) + + +def downgrade(): + pass diff -r 1fb29bd2725a -r c40962280e72 lib/galaxy/web/controllers/admin.py --- a/lib/galaxy/web/controllers/admin.py Wed Sep 16 11:27:50 2009 -0400 +++ b/lib/galaxy/web/controllers/admin.py Wed Sep 16 12:39:57 2009 -0400 @@ -749,122 +749,3 @@ else: last_updated[job.id] = '%s minutes' % int( delta.seconds / 60 ) return trans.fill_template( '/admin/jobs.mako', jobs = jobs, last_updated = last_updated, cutoff = cutoff, msg = msg, messagetype = messagetype ) - @web.expose - @web.require_admin - def manage_request_types( self, trans, **kwd ): - params = util.Params( kwd ) - msg = util.restore_text( params.get( 'msg', '' ) ) - messagetype = params.get( 'messagetype', 'done' ) - show_filter = util.restore_text( params.get( 'show_filter', 'Active' ) ) - forms = get_all_forms(trans, all_versions=True) - request_types_list = trans.app.model.RequestType.query().all() - if show_filter == 'All': - request_types = request_types_list - elif show_filter == 'Deleted': - request_types = [rt for rt in request_types_list if rt.deleted] - else: - request_types = [rt for rt in request_types_list if not rt.deleted] - return trans.fill_template( '/admin/requests/manage_request_types.mako', - request_types=request_types, - forms=forms, - show_filter=show_filter, - msg=msg, - messagetype=messagetype ) - @web.expose - @web.require_admin - def request_type( self, trans, **kwd ): - params = util.Params( kwd ) - msg = util.restore_text( params.get( 'msg', '' ) ) - messagetype = params.get( 'messagetype', 'done' ) - if params.get( 'create', False ): - return trans.fill_template( '/admin/requests/create_request_type.mako', - forms=get_all_forms( trans, - filter=dict(deleted=False) ), - msg=msg, - messagetype=messagetype) - elif params.get( 'define_states_button', False ): - return trans.fill_template( '/admin/requests/add_states.mako', - request_type_name=util.restore_text( params.name ), - desc=util.restore_text( params.description ), - num_states=int(util.restore_text( params.num_states )), - request_form_id=int(util.restore_text( params.request_form_id )), - sample_form_id=int(util.restore_text( params.sample_form_id )), - msg=msg, - messagetype=messagetype) - elif params.get( 'save_request_type', False ): - st, msg = self._save_request_type(trans, **kwd) - if not st: - return trans.fill_template( '/admin/requests/create_request_type.mako', - forms=get_all_forms( trans ), - msg=msg, - messagetype='error') - return trans.response.send_redirect( web.url_for( controller='admin', - action='manage_request_types', - msg='Request type <b>%s</b> has been created' % st.name, - messagetype='done') ) - elif params.get('view', False): - rt = trans.app.model.RequestType.get(int(util.restore_text( params.id ))) - ss_list = trans.app.model.SampleState.filter(trans.app.model.SampleState.table.c.request_type_id == rt.id).all() - return trans.fill_template( '/admin/requests/view_request_type.mako', - request_type=rt, - forms=get_all_forms( trans ), - states_list=ss_list, - deleted=False, - show_deleted=False, - msg=msg, - messagetype=messagetype ) - def _save_request_type(self, trans, **kwd): - params = util.Params( kwd ) - num_states = int( util.restore_text( params.get( 'num_states', 0 ) )) - proceed = True - for i in range( num_states ): - if not util.restore_text( params.get( 'state_name_%i' % i, None ) ): - proceed = False - break - if not proceed: - msg = "All the state name(s) must be completed." - return None, msg - rt = trans.app.model.RequestType() - rt.name = util.restore_text( params.name ) - rt.desc = util.restore_text( params.description ) or "" - rt.request_form = trans.app.model.FormDefinition.get(int( params.request_form_id )) - rt.sample_form = trans.app.model.FormDefinition.get(int( params.sample_form_id )) - rt.flush() - # set sample states - ss_list = trans.app.model.SampleState.filter(trans.app.model.SampleState.table.c.request_type_id == rt.id).all() - for ss in ss_list: - ss.delete() - ss.flush() - for i in range( num_states ): - name = util.restore_text( params.get( 'state_name_%i' % i, None )) - desc = util.restore_text( params.get( 'state_desc_%i' % i, None )) - ss = trans.app.model.SampleState(name, desc, rt) - ss.flush() - msg = "The new request type named '%s' with %s state(s) has been created" % (rt.name, num_states) - return rt, msg - @web.expose - @web.require_admin - def delete_request_type( self, trans, **kwd ): - params = util.Params( kwd ) - msg = util.restore_text( params.get( 'msg', '' ) ) - messagetype = params.get( 'messagetype', 'done' ) - rt = trans.app.model.RequestType.get(int(util.restore_text( params.request_type_id ))) - rt.deleted = True - rt.flush() - return trans.response.send_redirect( web.url_for( controller='admin', - action='manage_request_types', - msg='Request type <b>%s</b> has been deleted' % rt.name, - messagetype='done') ) - @web.expose - @web.require_admin - def undelete_request_type( self, trans, **kwd ): - params = util.Params( kwd ) - msg = util.restore_text( params.get( 'msg', '' ) ) - messagetype = params.get( 'messagetype', 'done' ) - rt = trans.app.model.RequestType.get(int(util.restore_text( params.request_type_id ))) - rt.deleted = False - rt.flush() - return trans.response.send_redirect( web.url_for( controller='admin', - action='manage_request_types', - msg='Request type <b>%s</b> has been undeleted' % rt.name, - messagetype='done') ) diff -r 1fb29bd2725a -r c40962280e72 lib/galaxy/web/controllers/forms.py --- a/lib/galaxy/web/controllers/forms.py Wed Sep 16 11:27:50 2009 -0400 +++ b/lib/galaxy/web/controllers/forms.py Wed Sep 16 12:39:57 2009 -0400 @@ -31,37 +31,72 @@ show_filter = params.get( 'show_filter', 'Active' ) return self._show_forms_list(trans, msg, messagetype, show_filter) def _show_forms_list(self, trans, msg, messagetype, show_filter='Active'): - fdc_list = trans.app.model.FormDefinitionCurrent.query().all() + all_forms = trans.app.model.FormDefinitionCurrent.query().all() if show_filter == 'All': - forms_list = fdc_list + forms_list = all_forms elif show_filter == 'Deleted': - forms_list = [form for form in fdc_list if form.deleted] + forms_list = [form for form in all_forms if form.deleted] else: - forms_list = [form for form in fdc_list if not form.deleted] + forms_list = [form for form in all_forms if not form.deleted] return trans.fill_template( '/admin/forms/manage_forms.mako', fdc_list=forms_list, + all_forms=all_forms, show_filter=show_filter, msg=msg, messagetype=messagetype ) + def __form_types_widget(self, trans, selected='none'): + form_type_selectbox = SelectField( 'form_type_selectbox', + refresh_on_change=True, + refresh_on_change_values=[trans.app.model.FormDefinition.types.SAMPLE] ) + if selected == 'none': + form_type_selectbox.add_option('Select one', 'none', selected=True) + else: + form_type_selectbox.add_option('Select one', 'none') + for ft in trans.app.model.FormDefinition.types.items(): + if selected == ft[1]: + form_type_selectbox.add_option(ft[1], ft[1], selected=True) + else: + form_type_selectbox.add_option(ft[1], ft[1]) + return form_type_selectbox + @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' ) + self.__imported_from_file = False if params.get( 'create_form_button', False ): fd, msg = self.__save_form( trans, fdc_id=None, **kwd ) + if not fd: + return trans.response.send_redirect( web.url_for( controller='forms', + action='new', + msg=msg, + messagetype='error' ) ) self.__get_saved_form( fd ) - return trans.response.send_redirect( web.url_for( controller='forms', - action='edit', - form_id=fd.id, - show_form=True ) ) + if self.__imported_from_file: + return trans.response.send_redirect( web.url_for( controller='forms', + action='edit', + show_form=True, + form_id=fd.id) ) + else: + return trans.response.send_redirect( web.url_for( controller='forms', + action='edit', + form_id=fd.id, + add_field_button='Add field', + num_fields=0, + name=fd.name, + description=fd.desc, + form_type_selectbox=fd.type ) ) self.current_form = {} self.current_form[ 'name' ] = 'New Form' self.current_form[ 'desc' ] = '' + self.current_form['type'] = 'none' + self.current_form[ 'layout' ] = ['Main'] self.current_form[ 'fields' ] = [] inputs = [ ( 'Name', TextField( 'name', 40, self.current_form[ 'name' ] ) ), ( 'Description', TextField( 'description', 40, self.current_form[ 'desc' ] ) ), + ( 'Type', self.__form_types_widget(trans, selected=self.current_form['type']) ), ( 'Import from csv file (Optional)', FileField( 'file_data', 40, '' ) ) ] return trans.fill_template( '/admin/forms/create_form.mako', inputs=inputs, @@ -115,12 +150,19 @@ # The following two dicts store the unsaved select box options self.del_options = {} self.add_options = {} - if fd.fields: - return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) - else: - # If the form is empty, we'll simulate a click on the add_field_button so the - # form will be displayed with the field choice, saving a mouse click. - return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, empty_form=True, **kwd ) + return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) + #Add a layout grid + elif params.get( 'add_layout_grid', False ): + self.__update_current_form( trans, **kwd ) + self.__add_layout_grid() + # show the form again + return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) + # Delete a layout grid + elif params.get( 'remove_layout_grid_button', False ): + self.__update_current_form( trans, **kwd ) + index = int( kwd[ 'remove_layout_grid_button' ].split( ' ' )[2] ) - 1 + self.__remove_layout_grid( index ) + return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) # Delete a field elif params.get( 'remove_button', False ): self.__update_current_form( trans, **kwd ) @@ -163,7 +205,11 @@ elif params.get( 'select_box_options', False ) == 'add': index = int( kwd[ 'field_index' ] ) self.current_form[ 'fields' ][ index ][ 'selectlist' ].append( '' ) - return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) + return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) + def __add_layout_grid(self): + self.current_form['layout'].append('') + def __remove_layout_grid(self, index): + del self.current_form['layout'][index] def __remove_field(self, index): del self.current_form['fields'][index] def __add_field(self): @@ -175,7 +221,8 @@ 'visible': True, 'required': False, 'type': BaseField.form_field_types()[0], - 'selectlist': [] } + 'selectlist': [], + 'layout': 'none' } self.current_form['fields'].append(empty_field) def __get_field(self, index, **kwd): params = util.Params( kwd ) @@ -187,6 +234,7 @@ 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, '' ) ) + layout = params.get( 'field_layout_%i' % index, '' ) if field_type == 'SelectField': selectlist = self.__get_selectbox_options(index, **kwd) return {'label': name, @@ -194,12 +242,14 @@ 'visible': True, 'required': required, 'type': field_type, - 'selectlist': selectlist } + 'selectlist': selectlist, + 'layout': layout } return {'label': name, 'helptext': helptext, 'visible': True, 'required': required, - 'type': field_type} + 'type': field_type, + 'layout': layout} def __get_selectbox_options(self, index, **kwd): ''' This method gets all the options entered by the user for field when @@ -219,6 +269,8 @@ self.current_form = {} self.current_form['name'] = fd.name self.current_form['desc'] = fd.desc + self.current_form['type'] = fd.type + self.current_form['layout'] = list(copy.deepcopy(fd.layout)) self.current_form['fields'] = list(copy.deepcopy(fd.fields)) def __validate_form(self, **kwd): ''' @@ -230,6 +282,9 @@ # form name if not util.restore_text( params.name ): return None, 'Form name must be filled.' + # form type + if util.restore_text( params.form_type_selectbox ) == 'none': + return None, 'Form type must be selected.' # fields for i in range( len(self.current_form['fields']) ): if not util.restore_text(params.get( 'field_name_%i' % i, None )): @@ -239,6 +294,11 @@ params = util.Params( kwd ) name = util.restore_text( params.name ) desc = util.restore_text( params.description ) or "" + form_type = util.restore_text( params.form_type_selectbox ) + layout = [] + if form_type == trans.app.model.FormDefinition.types.SAMPLE: + for index in range(len(self.current_form[ 'layout' ])): + layout.append(params.get( 'grid_layout%i' % index, '' )) csv_file = params.get( 'file_data', '' ) if csv_file == '': # set form fields @@ -247,16 +307,18 @@ fields.append(self.__get_field(i, **kwd)) fields = fields else: - fields = self.__import_fields(trans, csv_file) - return name, desc, fields + fields = self.__import_fields(trans, csv_file, form_type) + return name, desc, form_type, layout, fields def __update_current_form(self, trans, **kwd): - name, desc, fields = self.__get_form(trans, **kwd) + name, desc, form_type, layout, fields = self.__get_form(trans, **kwd) self.current_form = {} self.current_form['name'] = name self.current_form['desc'] = desc + self.current_form['type'] = form_type + self.current_form['layout'] = layout self.current_form['fields'] = fields - def __import_fields(self, trans, csv_file): + def __import_fields(self, trans, csv_file, form_type): ''' "company","name of the company", "True", "required", "TextField",, "due date","turnaround time", "True", "optional", "SelectField","24 hours, 1 week, 1 month" @@ -265,20 +327,32 @@ fields = [] try: reader = csv.reader(csv_file.file) - for row in reader: - options = row[5].split(',') - fields.append({'label': row[0], - 'helptext': row[1], - 'visible': row[2], - 'required': row[3], - 'type': row[4], - 'selectlist': options}) + if form_type == trans.app.model.FormDefinition.types.SAMPLE: + for row in reader: + options = row[5].split(',') + fields.append({'label': row[0], + 'helptext': row[1], + 'visible': row[2], + 'required': row[3], + 'type': row[4], + 'selectlist': options, + 'layout':row[6]}) + else: + for row in reader: + options = row[5].split(',') + fields.append({'label': row[0], + 'helptext': row[1], + 'visible': row[2], + 'required': row[3], + 'type': row[4], + 'selectlist': options}) except: return trans.response.send_redirect( web.url_for( controller='forms', action='new', status='error', message='Error in importing <b>%s</b> file' % csv_file, **kwd)) + self.__imported_from_file = True return fields def __save_form(self, trans, fdc_id=None, **kwd): @@ -290,7 +364,7 @@ if not flag: return None, msg fd = trans.app.model.FormDefinition() - fd.name, fd.desc, fd.fields = self.__get_form(trans, **kwd) + fd.name, fd.desc, fd.type, fd.layout, fd.fields = self.__get_form(trans, **kwd) if fdc_id: # save changes to the existing form # change the pointer in the form_definition_current table to point # to this new record @@ -306,7 +380,7 @@ return fd, msg class FieldUI(object): - def __init__(self, index, field=None, field_type=None): + def __init__(self, layout_grids, index, field=None, field_type=None): ''' This method returns a list of widgets which describes a field. This includes label, helptext, type, & required/optional @@ -323,6 +397,11 @@ self.required = SelectField('field_required_'+str(index), display='radio') self.required.add_option('Required', 'required') self.required.add_option('Optional', 'optional', selected=True) + self.layout_grids = layout_grids + if layout_grids: + self.layout_selectbox = SelectField('field_layout_'+str(index)) + for index, grid_name in enumerate(layout_grids): + self.layout_selectbox.add_option("%i. %s" %(index+1, grid_name), index) if field: self.fill(field, field_type) def fill(self, field, field_type=None): @@ -350,6 +429,14 @@ self.required = SelectField('field_required_'+str(self.index), display='radio') self.required.add_option('Required', 'required', selected=True) self.required.add_option('Optional', 'optional') + # layout + if self.layout_grids: + self.layout_selectbox = SelectField('field_layout_'+str(self.index)) + for i, grid_name in enumerate(self.layout_grids): + if field['layout'] == str(i): + self.layout_selectbox.add_option("%i. %s" %(i+1, grid_name), i, selected=True) + else: + self.layout_selectbox.add_option("%i. %s" %(i+1, grid_name), i) def selectbox_ui(self, field): self.selectbox_options = [] if field['selectlist']: @@ -358,6 +445,12 @@ TextField('field_'+str(self.index)+'_option_'+str(ctr), 40, option))) def get(self): + if self.layout_grids: + return [( 'Label', self.label ), + ( 'Help text', self.helptext ), + ( 'Type', self.fieldtype, self.selectbox_options), + ( '', self.required), + ( 'Select the grid layout to place this field', self.layout_selectbox)] return [( 'Label', self.label ), ( 'Help text', self.helptext ), ( 'Type', self.fieldtype, self.selectbox_options), @@ -367,31 +460,29 @@ def label(self): return str(self.index)+'.'+self.label - def __show( self, trans, form, msg='', messagetype='done', empty_form=False, **kwd ): + def __show( self, trans, form, msg='', messagetype='done', **kwd ): ''' This method displays the form and any of the changes made to it, The empty_form param allows for this method to simulate clicking the "add_field_button" on the edit_form.mako page so that the page is displayed with the first field to be added, saving a mouse click. ''' - if empty_form: - # Send params that will simulate a button click on the add_field_button - # button on edit_form.mako. - param_dict = { 'form_id' : str( form.id ), - 'num_fields' : '0', - 'refresh' : 'true', - 'name' : form.name, - 'description' : form.desc, - 'add_field_button' : 'Add field' } - self.edit( trans, **param_dict ) params = util.Params( kwd ) # name & description form_details = [ ( 'Name', TextField( 'name', 40, self.current_form[ 'name' ] ) ), - ( 'Description', TextField( 'description', 40, self.current_form[ 'desc' ] ) ) ] + ( 'Description', TextField( 'description', 40, self.current_form[ 'desc' ] ) ), + ( 'Type', self.__form_types_widget(trans, selected=self.current_form['type']) ) ] + form_layout = [] + if self.current_form['type'] == trans.app.model.FormDefinition.types.SAMPLE: + for index, lg in enumerate(self.current_form['layout']): + form_layout.append( TextField( 'grid_layout%i' % index, 40, lg )) # fields field_details = [] for index, field in enumerate( self.current_form[ 'fields' ] ): - field_ui = self.FieldUI( index, field ) + if self.current_form['type'] == trans.app.model.FormDefinition.types.SAMPLE: + field_ui = self.FieldUI( self.current_form['layout'], index, field ) + else: + field_ui = self.FieldUI( None, index, field ) field_details.append( field_ui.get() ) return trans.fill_template( '/admin/forms/edit_form.mako', form_details=form_details, @@ -399,10 +490,12 @@ form=form, field_types=BaseField.form_field_types(), msg=msg, - messagetype=messagetype ) + messagetype=messagetype, + current_form_type=self.current_form['type'], + layout_grids=form_layout ) # Common methods for all components that use forms -def get_all_forms( trans, all_versions=False, filter=None ): +def get_all_forms( trans, all_versions=False, filter=None, form_type='All' ): ''' Return all the latest forms from the form_definition_current table if all_versions is set to True. Otherwise return all the versions @@ -418,7 +511,11 @@ fdc_list = trans.app.model.FormDefinitionCurrent.query().filter_by(**filter) else: fdc_list = trans.app.model.FormDefinitionCurrent.query().all() - return [ fdc.latest_form for fdc in fdc_list ] + if form_type == 'All': + return [ fdc.latest_form for fdc in fdc_list ] + else: + return [ fdc.latest_form for fdc in fdc_list if fdc.latest_form.type == form_type ] + def get_form_widgets( trans, form, contents=[], user=None, **kwd ): diff -r 1fb29bd2725a -r c40962280e72 lib/galaxy/web/controllers/library.py --- a/lib/galaxy/web/controllers/library.py Wed Sep 16 11:27:50 2009 -0400 +++ b/lib/galaxy/web/controllers/library.py Wed Sep 16 12:39:57 2009 -0400 @@ -1100,7 +1100,8 @@ library_id=library_id, folder_id=folder_id, ldda_id=ldda_id, - forms=get_all_forms( trans, filter=dict(deleted=False) ), + forms=get_all_forms( trans, filter=dict(deleted=False), + form_type=trans.app.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE ), msg=msg, messagetype=messagetype ) @web.expose diff -r 1fb29bd2725a -r c40962280e72 lib/galaxy/web/controllers/requests.py --- a/lib/galaxy/web/controllers/requests.py Wed Sep 16 11:27:50 2009 -0400 +++ b/lib/galaxy/web/controllers/requests.py Wed Sep 16 12:39:57 2009 -0400 @@ -148,7 +148,7 @@ request_details.append(dict(label='Date created', value=request.create_time, helptext='')) - # library associated + # library associated if request.library: value = request.library.name else: @@ -156,6 +156,14 @@ request_details.append( dict( label='Data library', value=value, helptext='Data library where the resultant dataset will be stored' ) ) + # folder associated + if request.folder: + value = request.folder.name + else: + value = None + request_details.append( dict( label='Data library folder', + value=value, + helptext='Data library folder where the resultant dataset will be stored' ) ) # form fields for index, field in enumerate(request.type.request_form.fields): if field['required']: @@ -230,7 +238,7 @@ return trans.response.send_redirect( web.url_for( controller='requests', action='list', status='error', - message='Error in importing <b>%s</b> samples file' % file_obj.file, + message='Error in importing samples file', **kwd)) elif params.get('add_sample_button', False) == 'Add New': # save the all (saved+unsaved) sample info in 'current_samples' @@ -488,7 +496,9 @@ def __library_ui(self, libraries, request=None, **kwd): params = util.Params( kwd ) lib_id = params.get( 'library_id', 'none' ) - lib_list = SelectField( 'library_id', refresh_on_change=True, refresh_on_change_values=['new'] ) + lib_id_list = ['new'] + [str(lib.id) for lib in libraries.keys()] + lib_list = SelectField( 'library_id', refresh_on_change=True, refresh_on_change_values=lib_id_list ) + folders = [] if request and lib_id == 'none': if request.library: lib_id = str(request.library.id) @@ -499,23 +509,48 @@ for lib, hidden_folder_ids in libraries.items(): if str(lib.id) == lib_id: lib_list.add_option(lib.name, lib.id, selected=True) + folders.append( lib.root_folder ) + for f in lib.root_folder.folders: + if str(f.id) not in hidden_folder_ids.split(','): + folders.append( f ) else: lib_list.add_option(lib.name, lib.id) + lib_list.refresh_on_change_values.append(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.') + lib_widget = dict(label='Data library', + widget=lib_list, + helptext='Data library where the resultant dataset will be stored.') + if folders: + if request: + if request.folder: + current_fid = request.folder.id + else: + current_fid = request.library.root_folder.id + else: + current_fid = params.get( 'folder_id', 'none' ) + folder_list = SelectField( 'folder_id') + for f in folders: + if str(f.id) == current_fid: + folder_list.add_option(f.name, f.id, selected=True) + else: + folder_list.add_option(f.name, f.id) + folder_widget = dict(label='Folder', + widget=folder_list, + helptext='Folder of the selected data library where the resultant dataset will be stored.') if lib_id == 'new': new_lib = dict(label='Create a new data library', widget=TextField('new_library_name', 40, util.restore_text( params.get( 'new_library_name', '' ) )), helptext='Enter a name here to request a new data library') - return [widget, new_lib] + return [lib_widget, new_lib] else: - return [widget] + if folders: + return [lib_widget, folder_widget] + else: + return [lib_widget] def __validate(self, trans, request): ''' Validates the request entered by the user @@ -546,6 +581,13 @@ library = trans.app.model.Library.get(int(params.get('library_id', None))) except: library = None + try: + folder = trans.app.model.LibraryFolder.get(int(params.get('folder_id', None))) + except: + if library: + folder = library.root_folder + else: + folder = None # fields values = [] for index, field in enumerate(request_type.request_form.fields): @@ -577,7 +619,7 @@ if not request: request = trans.app.model.Request(name, desc, request_type, trans.user, form_values, - library=library, + library=library, folder=folder, state=trans.app.model.Request.states.UNSUBMITTED) request.flush() else: @@ -587,6 +629,7 @@ request.user = trans.user request.values = form_values request.library = library + request.folder = folder request.state = trans.app.model.Request.states.UNSUBMITTED request.flush() return request diff -r 1fb29bd2725a -r c40962280e72 lib/galaxy/web/controllers/requests_admin.py --- a/lib/galaxy/web/controllers/requests_admin.py Wed Sep 16 11:27:50 2009 -0400 +++ b/lib/galaxy/web/controllers/requests_admin.py Wed Sep 16 12:39:57 2009 -0400 @@ -8,6 +8,7 @@ from galaxy.web.form_builder import * from datetime import datetime, timedelta from galaxy.web.controllers.forms import get_form_widgets +from galaxy.web.controllers.forms import get_all_forms log = logging.getLogger( __name__ ) @@ -100,6 +101,7 @@ else: self.request_grid.default_filter = dict(state=kwargs['show_filter'], deleted=False) self.request_grid.show_filter = kwargs.get('show_filter', trans.app.model.Request.states.SUBMITTED) + self.__update_request_state(trans) # Render the list view return self.request_grid( trans, **kwargs ) @web.expose @@ -553,8 +555,17 @@ else: value = None request_details.append(dict(label='Data library', - value=value, - helptext='Data library where the resultant dataset will be stored')) + value=value, + helptext='Data library where the resultant dataset will be stored')) + # folder associated + if request.folder: + value = request.folder.name + else: + value = None + request_details.append( dict( label='Data library folder', + value=value, + helptext='Data library folder where the resultant dataset will be stored' ) ) + # form fields for index, field in enumerate(request.type.request_form.fields): if field['required']: @@ -714,26 +725,31 @@ """ params = util.Params( kwd ) lib_id = params.get( 'library_id', 'none' ) - all_libraries = trans.app.model.Library.filter( trans.app.model.Library.table.c.deleted == False ) \ - .order_by( trans.app.model.Library.name ).all() - roles = user.all_roles() - actions_to_check = [ trans.app.security_agent.permitted_actions.LIBRARY_ADD ] - # The libraries dictionary looks like: { library : '1,2' }, library : '3' } - # Its keys are the libraries that should be displayed for the current user and whose values are a - # string of comma-separated folder ids, of the associated folders the should NOT be displayed. - # The folders that should not be displayed may not be a complete list, but it is ultimately passed - # to the calling method to keep from re-checking the same folders when the library / folder - # select lists are rendered. - # - # TODO: RC, when you add the folders select list to your request form, take advantage of the hidden_folder_ids - # so that you do not need to check those same folders yet again when populating the select list. - # - libraries = {} - for library in all_libraries: - can_show, hidden_folder_ids = trans.app.security_agent.show_library_item( user, roles, library, actions_to_check ) - if can_show: - libraries[ library ] = hidden_folder_ids - lib_list = SelectField( 'library_id', refresh_on_change=True, refresh_on_change_values=['new'] ) + if not user: + libraries = {} + else: + all_libraries = trans.app.model.Library.filter( trans.app.model.Library.table.c.deleted == False ) \ + .order_by( trans.app.model.Library.name ).all() + roles = user.all_roles() + actions_to_check = [ trans.app.security_agent.permitted_actions.LIBRARY_ADD ] + # The libraries dictionary looks like: { library : '1,2' }, library : '3' } + # Its keys are the libraries that should be displayed for the current user and whose values are a + # string of comma-separated folder ids, of the associated folders the should NOT be displayed. + # The folders that should not be displayed may not be a complete list, but it is ultimately passed + # to the calling method to keep from re-checking the same folders when the library / folder + # select lists are rendered. + # + # TODO: RC, when you add the folders select list to your request form, take advantage of the hidden_folder_ids + # so that you do not need to check those same folders yet again when populating the select list. + # + libraries = {} + for library in all_libraries: + can_show, hidden_folder_ids = trans.app.security_agent.show_library_item( user, roles, library, actions_to_check ) + if can_show: + libraries[ library ] = hidden_folder_ids + lib_id_list = ['new'] + [str(lib.id) for lib in libraries.keys()] + lib_list = SelectField( 'library_id', refresh_on_change=True, refresh_on_change_values=lib_id_list ) + folders = [] if request and lib_id == 'none': if request.library: lib_id = str(request.library.id) @@ -744,23 +760,48 @@ for lib, hidden_folder_ids in libraries.items(): if str(lib.id) == lib_id: lib_list.add_option(lib.name, lib.id, selected=True) + folders.append( lib.root_folder ) + for f in lib.root_folder.folders: + if str(f.id) not in hidden_folder_ids.split(','): + folders.append( f ) else: lib_list.add_option(lib.name, lib.id) + lib_list.refresh_on_change_values.append(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.') + lib_widget = dict(label='Data library', + widget=lib_list, + helptext='Data library where the resultant dataset will be stored.') + if folders: + if request: + if request.folder: + current_fid = request.folder.id + else: + current_fid = request.library.root_folder.id + else: + current_fid = params.get( 'folder_id', 'none' ) + folder_list = SelectField( 'folder_id') + for f in folders: + if str(f.id) == current_fid: + folder_list.add_option(f.name, f.id, selected=True) + else: + folder_list.add_option(f.name, f.id) + folder_widget = dict(label='Folder', + widget=folder_list, + helptext='Folder of the selected data library where the resultant dataset will be stored.') if lib_id == 'new': - new_lib = dict(label='Create a new Library', + new_lib = dict(label='Create a new data 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] + helptext='Enter a name here to request a new data library') + return [lib_widget, new_lib] else: - return [widget] + if folders: + return [lib_widget, folder_widget] + else: + return [lib_widget] def __validate(self, trans, request): ''' Validates the request entered by the user @@ -795,6 +836,13 @@ library = trans.app.model.Library.get(int(params.get('library_id', None))) except: library = None + try: + folder = trans.app.model.LibraryFolder.get(int(params.get('folder_id', None))) + except: + if library: + folder = library.root_folder + else: + folder = None # fields values = [] for index, field in enumerate(request_type.request_form.fields): @@ -826,7 +874,7 @@ if not request: request = trans.app.model.Request(name, desc, request_type, user, form_values, - library=library, + library=library, folder=folder, state=trans.app.model.Request.states.UNSUBMITTED) request.flush() else: @@ -836,6 +884,7 @@ request.user = user request.values = form_values request.library = library + request.folder = folder request.flush() return request @web.expose @@ -934,6 +983,13 @@ request_id=request.id, msg='Bar codes has been saved for this request', messagetype='done')) + + def __update_request_state(self, trans): + requests = trans.app.model.Request.query.filter_by(deleted=False, + state=trans.app.model.Request.states.SUBMITTED) + for request in requests: + self.__set_request_state(request) + def __set_request_state(self, request): # check if all the samples of the current request are in the final state complete = True @@ -1013,4 +1069,128 @@ return trans.fill_template( '/admin/samples/events.mako', events_list=events_list, sample=sample, widgets=widgets, title=title) - \ No newline at end of file + + # Request Type Stuff + @web.expose + @web.require_admin + def manage_request_types( self, trans, **kwd ): + params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) + show_filter = util.restore_text( params.get( 'show_filter', 'Active' ) ) + forms = get_all_forms(trans, all_versions=True) + request_types_list = trans.app.model.RequestType.query().all() + if show_filter == 'All': + request_types = request_types_list + elif show_filter == 'Deleted': + request_types = [rt for rt in request_types_list if rt.deleted] + else: + request_types = [rt for rt in request_types_list if not rt.deleted] + return trans.fill_template( '/admin/requests/manage_request_types.mako', + request_types=request_types, + forms=forms, + show_filter=show_filter, + msg=msg, + messagetype=messagetype ) + @web.expose + @web.require_admin + def request_type( self, trans, **kwd ): + params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) + if params.get( 'create', False ): + return trans.fill_template( '/admin/requests/create_request_type.mako', + request_forms=get_all_forms( trans, + filter=dict(deleted=False), + form_type=trans.app.model.FormDefinition.types.REQUEST ), + sample_forms=get_all_forms( trans, + filter=dict(deleted=False), + form_type=trans.app.model.FormDefinition.types.SAMPLE ), + msg=msg, + messagetype=messagetype) + elif params.get( 'define_states_button', False ): + return trans.fill_template( '/admin/requests/add_states.mako', + request_type_name=util.restore_text( params.name ), + desc=util.restore_text( params.description ), + num_states=int(util.restore_text( params.num_states )), + request_form_id=int(util.restore_text( params.request_form_id )), + sample_form_id=int(util.restore_text( params.sample_form_id )), + msg=msg, + messagetype=messagetype) + elif params.get( 'save_request_type', False ): + st, msg = self.__save_request_type(trans, **kwd) + if not st: + return trans.fill_template( '/admin/requests/create_request_type.mako', + forms=get_all_forms( trans ), + msg=msg, + messagetype='error') + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='manage_request_types', + msg='Request type <b>%s</b> has been created' % st.name, + messagetype='done') ) + elif params.get('view', False): + rt = trans.app.model.RequestType.get(int(util.restore_text( params.id ))) + ss_list = trans.app.model.SampleState.filter(trans.app.model.SampleState.table.c.request_type_id == rt.id).all() + return trans.fill_template( '/admin/requests/view_request_type.mako', + request_type=rt, + forms=get_all_forms( trans ), + states_list=ss_list, + deleted=False, + show_deleted=False, + msg=msg, + messagetype=messagetype ) + def __save_request_type(self, trans, **kwd): + params = util.Params( kwd ) + num_states = int( util.restore_text( params.get( 'num_states', 0 ) )) + proceed = True + for i in range( num_states ): + if not util.restore_text( params.get( 'state_name_%i' % i, None ) ): + proceed = False + break + if not proceed: + msg = "All the state name(s) must be completed." + return None, msg + rt = trans.app.model.RequestType() + rt.name = util.restore_text( params.name ) + rt.desc = util.restore_text( params.description ) or "" + rt.request_form = trans.app.model.FormDefinition.get(int( params.request_form_id )) + rt.sample_form = trans.app.model.FormDefinition.get(int( params.sample_form_id )) + rt.flush() + # set sample states + ss_list = trans.app.model.SampleState.filter(trans.app.model.SampleState.table.c.request_type_id == rt.id).all() + for ss in ss_list: + ss.delete() + ss.flush() + for i in range( num_states ): + name = util.restore_text( params.get( 'state_name_%i' % i, None )) + desc = util.restore_text( params.get( 'state_desc_%i' % i, None )) + ss = trans.app.model.SampleState(name, desc, rt) + ss.flush() + msg = "The new request type named '%s' with %s state(s) has been created" % (rt.name, num_states) + return rt, msg + @web.expose + @web.require_admin + def delete_request_type( self, trans, **kwd ): + params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) + rt = trans.app.model.RequestType.get(int(util.restore_text( params.request_type_id ))) + rt.deleted = True + rt.flush() + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='manage_request_types', + msg='Request type <b>%s</b> has been deleted' % rt.name, + messagetype='done') ) + @web.expose + @web.require_admin + def undelete_request_type( self, trans, **kwd ): + params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) + rt = trans.app.model.RequestType.get(int(util.restore_text( params.request_type_id ))) + rt.deleted = False + rt.flush() + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='manage_request_types', + msg='Request type <b>%s</b> has been undeleted' % rt.name, + messagetype='done') ) diff -r 1fb29bd2725a -r c40962280e72 lib/galaxy/web/form_builder.py --- a/lib/galaxy/web/form_builder.py Wed Sep 16 11:27:50 2009 -0400 +++ b/lib/galaxy/web/form_builder.py Wed Sep 16 12:39:57 2009 -0400 @@ -12,7 +12,7 @@ raise TypeError( "Abstract Method" ) @staticmethod def form_field_types(): - return ['TextField', 'TextArea', 'SelectField', 'CheckboxField', 'AddressField'] + return ['TextField', 'NumberField', 'TextArea', 'SelectField', 'CheckboxField', 'AddressField'] class TextField(BaseField): """ @@ -29,6 +29,25 @@ self.value = value or "" def get_html( self, prefix="" ): return '<input type="text" name="%s%s" size="%d" value="%s">' \ + % ( prefix, self.name, self.size, escape(str(self.value), quote=True) ) + def set_size(self, size): + self.size = int( size ) + +class NumberField(BaseField): + """ + A number input box. + + >>> print NumberField( "foo" ).get_html() + <input type="int" name="foo" size="10" value=""> + >>> print NumberField( "bins", size=4, value="12345" ).get_html() + <input type="int" name="bins" size="4" value="12345"> + """ + def __init__( self, name, size=None, value=None ): + self.name = name + self.size = int( size or 10 ) + self.value = value or "" + def get_html( self, prefix="" ): + return '<input type="int" name="%s%s" size="%d" value="%s">' \ % ( prefix, self.name, self.size, escape(str(self.value), quote=True) ) def set_size(self, size): self.size = int( size ) diff -r 1fb29bd2725a -r c40962280e72 templates/admin/forms/edit_form.mako --- a/templates/admin/forms/edit_form.mako Wed Sep 16 11:27:50 2009 -0400 +++ b/templates/admin/forms/edit_form.mako Wed Sep 16 12:39:57 2009 -0400 @@ -69,6 +69,16 @@ </div> </%def> +<%def name="render_layout( index, widget )"> + <div class="repeat-group-item"> + <div class="form-row"> + <b> ${index+1}</b> + ${widget.get_html()} + <input type="submit" name="remove_layout_grid_button" value="Remove grid ${index+1}"/> + </div> + </div> +</%def> + <div class="toolForm"> <div class="toolFormTitle">Edit form definition "${form.name}"</div> <form id="edit_form" name="edit_form" action="${h.url_for( controller='forms', action='edit', form_id=form.id, num_fields=len(form.fields) )}" method="post" > @@ -81,6 +91,18 @@ <div style="clear: both"></div> </div> %endfor + %if current_form_type == trans.app.model.FormDefinition.types.SAMPLE: + <div class="toolFormTitle">Form Layout</div> + <div class="form-row"> + <label>Layout grid names</label> + </div> + %for index, lg in enumerate(layout_grids): + ${render_layout( index, lg )} + %endfor + <div class="form-row"> + <input type="submit" name="add_layout_grid" value="Add layout grid"/> + </div> + %endif <div class="toolFormTitle">Fields (${len(form.fields)})</div> %for ctr, field in enumerate(field_details): ${render_field( ctr, field )} diff -r 1fb29bd2725a -r c40962280e72 templates/admin/forms/manage_forms.mako --- a/templates/admin/forms/manage_forms.mako Wed Sep 16 11:27:50 2009 -0400 +++ b/templates/admin/forms/manage_forms.mako Wed Sep 16 12:39:57 2009 -0400 @@ -29,6 +29,7 @@ %endif </td> <td><i>${form.desc}</i></td> + <td>${form.type}</td> </tr> </%def> @@ -41,7 +42,7 @@ </li> </ul> -%if not fdc_list: +%if not all_forms: There are no forms. %else: <div class="grid-header"> @@ -61,6 +62,7 @@ <tr> <th>Name</th> <th>Description</th> + <th>Type</th> </tr> </thead> <tbody> diff -r 1fb29bd2725a -r c40962280e72 templates/admin/index.mako --- a/templates/admin/index.mako Wed Sep 16 11:27:50 2009 -0400 +++ b/templates/admin/index.mako Wed Sep 16 12:39:57 2009 -0400 @@ -118,7 +118,7 @@ </div> <div class="toolSectionBody"> <div class="toolSectionBg"> - <div class="toolTitle"><a href="${h.url_for( controller='admin', action='manage_request_types' )}" target="galaxy_main">Manage request types</a></div> + <div class="toolTitle"><a href="${h.url_for( controller='requests_admin', action='manage_request_types' )}" target="galaxy_main">Manage request types</a></div> <div class="toolTitle"><a href="${h.url_for( controller='requests_admin', action='list')}" target="galaxy_main">Manage requests</a></div> </div> </div> diff -r 1fb29bd2725a -r c40962280e72 templates/admin/requests/add_states.mako --- a/templates/admin/requests/add_states.mako Wed Sep 16 11:27:50 2009 -0400 +++ b/templates/admin/requests/add_states.mako Wed Sep 16 12:39:57 2009 -0400 @@ -7,7 +7,7 @@ <div class="toolForm"> <div class="toolFormTitle">Create ${num_states} states for the '${request_type_name}' request type</div> - <form name="new_form_fields" action="${h.url_for( controller='admin', action='request_type', name=request_type_name, description=desc, num_states=num_states, request_form_id=request_form_id, sample_form_id=sample_form_id)}" method="post" > + <form name="new_form_fields" action="${h.url_for( controller='requests_admin', action='request_type', name=request_type_name, description=desc, num_states=num_states, request_form_id=request_form_id, sample_form_id=sample_form_id)}" method="post" > <div class="toolFormBody"> %for element_count in range( num_states ): <div class="form-row"> diff -r 1fb29bd2725a -r c40962280e72 templates/admin/requests/create_request_type.mako --- a/templates/admin/requests/create_request_type.mako Wed Sep 16 11:27:50 2009 -0400 +++ b/templates/admin/requests/create_request_type.mako Wed Sep 16 12:39:57 2009 -0400 @@ -8,11 +8,11 @@ <div class="toolForm"> <div class="toolFormTitle">Create a new request type</div> - %if not forms: - Create a form definition first to create a new request type. + %if not request_forms or not sample_forms: + Create a request & sample form definition first to create a new request type. %else: <div class="toolFormBody"> - <form name="create_request_type" action="${h.url_for( controller='admin', action='request_type')}" method="post" > + <form name="create_request_type" action="${h.url_for( controller='requests_admin', action='request_type')}" method="post" > <div class="form-row"> <label>Name:</label> <div style="float: left; width: 250px; margin-right: 10px;"> @@ -32,7 +32,7 @@ Request Form definition: </label> <select name="request_form_id"> - %for form in forms: + %for form in request_forms: <option value="${form.id}">${form.name}</option> %endfor </select> @@ -42,7 +42,7 @@ Sample Form definition: </label> <select name="sample_form_id"> - %for form in forms: + %for form in sample_forms: <option value="${form.id}">${form.name}</option> %endfor </select> diff -r 1fb29bd2725a -r c40962280e72 templates/admin/requests/manage_request_types.mako --- a/templates/admin/requests/manage_request_types.mako Wed Sep 16 11:27:50 2009 -0400 +++ b/templates/admin/requests/manage_request_types.mako Wed Sep 16 12:39:57 2009 -0400 @@ -13,7 +13,7 @@ <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='admin', action='request_type', create=True )}"><span>Create a new request type</span></a> + <a class="action-button" href="${h.url_for( controller='requests_admin', action='request_type', create=True )}"><span>Create a new request type</span></a> </li> </ul> @@ -24,9 +24,9 @@ <span>|</span> %endif %if show_filter == filter: - <span class="filter"><a href="${h.url_for( controller='admin', action='manage_request_types', show_filter=filter )}"><b>${filter}</b></a></span> + <span class="filter"><a href="${h.url_for( controller='requests_admin', action='manage_request_types', show_filter=filter )}"><b>${filter}</b></a></span> %else: - <span class="filter"><a href="${h.url_for( controller='admin', action='manage_request_types', show_filter=filter )}">${filter}</a></span> + <span class="filter"><a href="${h.url_for( controller='requests_admin', action='manage_request_types', show_filter=filter )}">${filter}</a></span> %endif %endfor </div> @@ -46,7 +46,7 @@ %for request_type in request_types: <tr> <td> - <a href="${h.url_for( controller='admin', action='request_type', view='True', id=request_type.id)}">${request_type.name}</a> + <a href="${h.url_for( controller='requests_admin', action='request_type', view='True', id=request_type.id)}">${request_type.name}</a> <a id="request_type-${request_type.id}-popup" class="popup-arrow" style="display: none;">▼</a> %if request_type.deleted: <div popupmenu="request_type-${request_type.id}-popup"> diff -r 1fb29bd2725a -r c40962280e72 templates/admin/requests/show_request.mako --- a/templates/admin/requests/show_request.mako Wed Sep 16 11:27:50 2009 -0400 +++ b/templates/admin/requests/show_request.mako Wed Sep 16 12:39:57 2009 -0400 @@ -26,18 +26,39 @@ %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): + +<%def name="render_sample_form( index, sample_name, sample_values, grid_index, fields_dict )"> + %if grid_index == 0: <td> - <input type="text" name=sample_${index}_field_${field_index} value="${sample_values[field_index]}" size="7"/> + <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> + %else: + <td> + ${sample_name} + </td> + %endif + %for field_index, field in fields_dict.items(): + <td> + %if field['type'] == 'TextField': + <input type="text" name="sample_${index}_field_${field_index}" value="${sample_values[field_index]}" size="7"/> + %elif field['type'] == 'SelectField': + <select name="sample_${index}_field_${field_index}" last_selected_value="2"> + %for option_index, option in enumerate(field['selectlist']): + %if option == sample_values[field_index]: + <option value="${option}" selected>${option}</option> + %else: + <option value="${option}">${option}</option> + %endif + %endfor + </select> + %elif field['type'] == 'CheckboxField': + <input type="checkbox" name="sample_${index}_field_${field_index}" value="Yes"/> + %endif <div class="toolParamHelp" style="clear: both;"> <i>${'('+field['required']+')' }</i> </div> @@ -45,18 +66,20 @@ %endfor </%def> -<%def name="render_sample( index, sample )"> +<%def name="render_sample( index, sample, grid_index, fields_dict )"> <td> ${sample.name} </td> - <td> - %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): + %if grid_index == 0: + <td> + %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> + %endif + %for field_index, field in fields_dict.items(): <td> %if sample.values.content[field_index]: ${sample.values.content[field_index]} @@ -65,7 +88,6 @@ %endif </td> %endfor - </%def> <div class="toolForm"> @@ -100,58 +122,81 @@ </div> </div> +<%def name="render_grid( grid_index, grid_name, fields_dict )"> + %if grid_name: + <div class="toolFormTitle">${grid_name}</div> + %endif + <div style="clear: both"></div> + <table class="grid"> + <thead> + <tr> + <th>No.</th> + <th>Sample Name</th> + %if grid_index == 0: + <th>State</th> + %endif + %for index, field in fields_dict.items(): + <th> + ${field['label']} + <div class="toolParamHelp" style="clear: both;"> + <i>${field['helptext']}</i> + </div> + </th> + %endfor + <th></th> + </tr> + <thead> + <tbody> + <% + request.refresh() + %> + %for sample_index, sample in enumerate(current_samples): + %if edit_mode: + <tr> + <td>${sample_index+1}</td> + ${render_sample_form( sample_index, sample[0], sample[1], grid_index, fields_dict)} + <td> + %if request.unsubmitted() and grid_index == 0: + <a class="action-button" href="${h.url_for( controller='requests', 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> + %else: + <tr> + <td>${sample_index+1}</td> + %if sample_index in range(len(request.samples)): + ${render_sample( sample_index, request.samples[sample_index], grid_index, fields_dict )} + %else: + ${render_sample_form( sample_index, sample[0], sample[1], grid_index, fields_dict)} + %endif + <td> + %if request.unsubmitted() and grid_index == 0: + <a class="action-button" href="${h.url_for( controller='requests', 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> +</%def> + <div class="toolForm"> ##<div class="toolFormTitle">Samples (${len(request.samples)})</div> <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"> - <thead> - <tr> - <th>No.</th> - <th>Sample Name</th> - <th>State</th> - %for field_index, field in enumerate(request.type.sample_form.fields): - <th> - ${field['label']} - <div class="toolParamHelp" style="clear: both;"> - <i>${field['helptext']}</i> - </div> - </th> - %endfor - <th></th> - </tr> - <thead> - <tbody> - <% - request.refresh() - %> - %for sample_index, sample in enumerate(current_samples): - %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> + %if not request.type.sample_form.layout: + ${render_grid( 0, "", request.type.sample_form.fields_of_grid( None ) )} + %else: + %for grid_index, grid_name in enumerate(request.type.sample_form.layout): + ${render_grid( grid_index, grid_name, request.type.sample_form.fields_of_grid( grid_name ) )} + %endfor + %endif %else: <label>There are no samples.</label> %endif diff -r 1fb29bd2725a -r c40962280e72 templates/admin/requests/view_request_type.mako --- a/templates/admin/requests/view_request_type.mako Wed Sep 16 11:27:50 2009 -0400 +++ b/templates/admin/requests/view_request_type.mako Wed Sep 16 12:39:57 2009 -0400 @@ -11,7 +11,7 @@ <div class="toolForm"> <div class="toolFormTitle">View request type details</div> <div class="toolFormBody"> - <form name="library" action="${h.url_for( controller='admin', action='request_type', save_changes=True, create=False, id=request_type.id, num_states=num_states )}" method="post" > + <form name="library"> <div class="form-row"> <label>Name</label> ${request_type.name} diff -r 1fb29bd2725a -r c40962280e72 templates/requests/new_request.mako --- a/templates/requests/new_request.mako Wed Sep 16 11:27:50 2009 -0400 +++ b/templates/requests/new_request.mako Wed Sep 16 12:39:57 2009 -0400 @@ -58,9 +58,9 @@ <div class="form-row"> <label>${field['label']}</label> ${field['widget'].get_html()} - %if field['label'] == 'Data library' and new_library: - ${new_library.get_html()} - %endif + ##%if field['label'] == 'Data library' and new_library: + ## ${new_library.get_html()} + ##%endif <div class="toolParamHelp" style="clear: both;"> ${field['helptext']} </div> diff -r 1fb29bd2725a -r c40962280e72 templates/requests/show_request.mako --- a/templates/requests/show_request.mako Wed Sep 16 11:27:50 2009 -0400 +++ b/templates/requests/show_request.mako Wed Sep 16 12:39:57 2009 -0400 @@ -26,18 +26,40 @@ -<%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): +<%def name="render_sample_form( index, sample_name, sample_values, grid_index, fields_dict )"> + %if grid_index == 0: <td> - <input type="text" name=sample_${index}_field_${field_index} value="${sample_values[field_index]}" size="7"/> + <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> + %else: + <td> + ${sample_name} + </td> + %endif + %for field_index, field in fields_dict.items(): + <td> + %if field['type'] == 'TextField': + <input type="text" name="sample_${index}_field_${field_index}" value="${sample_values[field_index]}" size="7"/> + %elif field['type'] == 'SelectField': + <select name="sample_${index}_field_${field_index}" last_selected_value="2"> + %for option_index, option in enumerate(field['selectlist']): + %if option == sample_values[field_index]: + <option value="${option}" selected>${option}</option> + %else: + <option value="${option}">${option}</option> + %endif + %endfor + </select> + %elif field['type'] == 'CheckboxField': + <input type="checkbox" name="sample_${index}_field_${field_index}" value="Yes"/> + %elif field['type'] == 'NumberField': + <input type=int name="sample_${index}_field_${field_index}" value="${sample_values[field_index]}" size="7"/> + %endif <div class="toolParamHelp" style="clear: both;"> <i>${'('+field['required']+')' }</i> </div> @@ -45,18 +67,20 @@ %endfor </%def> -<%def name="render_sample( index, sample )"> +<%def name="render_sample( index, sample, grid_index, fields_dict )"> <td> ${sample.name} </td> - <td> - %if sample.request.unsubmitted(): - Unsubmitted - %else: - <a href="${h.url_for( controller='requests', 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): + %if grid_index == 0: + <td> + %if sample.request.unsubmitted(): + Unsubmitted + %else: + <a href="${h.url_for( controller='requests', action='show_events', sample_id=sample.id)}">${sample.current_state().name}</a> + %endif + </td> + %endif + %for field_index, field in fields_dict.items(): <td> %if sample.values.content[field_index]: ${sample.values.content[field_index]} @@ -105,65 +129,81 @@ </div> </div> +<%def name="render_grid( grid_index, grid_name, fields_dict )"> + %if grid_name: + <div class="toolFormTitle">${grid_name}</div> + %endif + <div style="clear: both"></div> + <table class="grid"> + <thead> + <tr> + <th>No.</th> + <th>Sample Name</th> + %if grid_index == 0: + <th>State</th> + %endif + %for index, field in fields_dict.items(): + <th> + ${field['label']} + <div class="toolParamHelp" style="clear: both;"> + <i>${field['helptext']}</i> + </div> + </th> + %endfor + <th></th> + </tr> + <thead> + <tbody> + <% + request.refresh() + %> + %for sample_index, sample in enumerate(current_samples): + %if edit_mode: + <tr> + <td>${sample_index+1}</td> + ${render_sample_form( sample_index, sample[0], sample[1], grid_index, fields_dict)} + <td> + %if request.unsubmitted() and grid_index == 0: + <a class="action-button" href="${h.url_for( controller='requests', 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> + %else: + <tr> + <td>${sample_index+1}</td> + %if sample_index in range(len(request.samples)): + ${render_sample( sample_index, request.samples[sample_index], grid_index, fields_dict )} + %else: + ${render_sample_form( sample_index, sample[0], sample[1], grid_index, fields_dict)} + %endif + <td> + %if request.unsubmitted() and grid_index == 0: + <a class="action-button" href="${h.url_for( controller='requests', 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> +</%def> + <div class="toolForm"> ##<div class="toolFormTitle">Samples (${len(request.samples)})</div> <form id="show_request" name="show_request" action="${h.url_for( controller='requests', action='show_request' )}" enctype="multipart/form-data" method="post" > <div class="form-row"> - %if current_samples: - <table class="grid"> - <thead> - <tr> - <th>No.</th> - <th>Sample Name</th> - <th>State</th> - %for field_index, field in enumerate(request.type.sample_form.fields): - <th> - ${field['label']} - <div class="toolParamHelp" style="clear: both;"> - <i>${field['helptext']}</i> - </div> - </th> - %endfor - <th></th> - </tr> - <thead> - <tbody> - <% - request.refresh() - %> - %for sample_index, sample in enumerate(current_samples): - %if edit_mode: - <tr> - <td>${sample_index+1}</td> - ${render_sample_form( sample_index, sample[0], sample[1])} - <td> - %if request.unsubmitted(): - <a class="action-button" href="${h.url_for( controller='requests', 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> - %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', 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> + %if current_samples: + %if not request.type.sample_form.layout: + ${render_grid( 0, "", request.type.sample_form.fields_of_grid( None ) )} + %else: + %for grid_index, grid_name in enumerate(request.type.sample_form.layout): + ${render_grid( grid_index, grid_name, request.type.sample_form.fields_of_grid( grid_name ) )} + %endfor + %endif %else: <div class="form-row"> <label>There are no samples.</label> diff -r 1fb29bd2725a -r c40962280e72 test/base/twilltestcase.py --- a/test/base/twilltestcase.py Wed Sep 16 11:27:50 2009 -0400 +++ b/test/base/twilltestcase.py Wed Sep 16 12:39:57 2009 -0400 @@ -972,15 +972,13 @@ self.home() # Form stuff - def create_form( self, name='Form One', desc='This is Form One', num_fields=1 ): + def create_form( self, name, desc, formtype, 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 test param values. Using same-named parameters down different branches (having different scope in the tool) cannot be properly tested when they both exist at the same time. - TODO: RC: create an edit_form() method that will test the addition of a new field - of a specified type. """ # TODO: RC: enhance this so that all supported field types can be passed in # and tested. If nothing is passed, all fields are TextField. @@ -988,7 +986,8 @@ 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", desc ) # form field 1 is the field named name... + tc.fv( "1", "description", desc ) # form field 1 is the field named desc... + tc.fv( "1", "form_type_selectbox", formtype ) tc.submit( "create_form_button" ) for index in range( num_fields ): field_name = 'field_name_%i' % index @@ -1053,7 +1052,7 @@ # 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.visit_url( "%s/requests_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 ) @@ -1067,13 +1066,14 @@ 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 ): + def create_request( self, request_type_id, name, desc, library_id, folder_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) ) + #tc.fv( "1", "folder_id", str(folder_id) ) for index, field_value in enumerate(fields): tc.fv( "1", "field_%i" % index, field_value ) tc.submit( "create_request_button" ) @@ -1088,13 +1088,14 @@ 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): + def edit_request( self, request_id, name, new_name, new_desc, new_library_id, new_folder_id, new_fields): self.home() self.visit_url( "%s/requests/edit?request_id=%i&show=True" % (self.url, request_id) ) self.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) ) + tc.fv( "1", "folder_id", str(new_folder_id) ) for index, field_value in enumerate(new_fields): tc.fv( "1", "field_%i" % index, field_value ) tc.submit( "save_changes_request_button" ) diff -r 1fb29bd2725a -r c40962280e72 test/functional/test_forms_and_requests.py --- a/test/functional/test_forms_and_requests.py Wed Sep 16 11:27:50 2009 -0400 +++ b/test/functional/test_forms_and_requests.py Wed Sep 16 12:39:57 2009 -0400 @@ -41,14 +41,17 @@ global form_one_name name = form_one_name desc = "This is Form One's description" - self.create_form( name=name, desc=desc ) + formtype = 'Sequencing Request Form' + self.create_form( name=name, desc=desc, formtype=formtype ) self.home() self.visit_page( 'forms/manage' ) self.check_page_for_string( name ) self.check_page_for_string( desc ) + self.check_page_for_string( formtype ) # 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] + galaxy.model.FormDefinition.table.c.desc==desc, + galaxy.model.FormDefinition.table.c.type==formtype ) ).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)" @@ -86,15 +89,18 @@ global form_two_name name = form_two_name desc = "This is Form One's description" - self.create_form( name=name, desc=desc ) + formtype = 'Sequencing Sample Form' + self.create_form( name=name, desc=desc, formtype=formtype ) self.home() self.visit_page( 'forms/manage' ) self.check_page_for_string( name ) self.check_page_for_string( desc ) + self.check_page_for_string( formtype ) 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) + print request_form.id, sample_form.id self.create_request_type(request_type_name, "test request type", str(request_form.id), str(sample_form.id), sample_states ) global request_type @@ -147,6 +153,17 @@ # 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 a folder in the library + root_folder = library_one.root_folder + name = "Folder One" + self.add_folder( str( library_one.id ), str( root_folder.id ), name=name, description='' ) + global folder_one + folder_one = galaxy.model.LibraryFolder.filter( and_( galaxy.model.LibraryFolder.table.c.parent_id==root_folder.id, + galaxy.model.LibraryFolder.table.c.name==name ) ).first() + assert folder_one is not None, 'Problem retrieving library folder named "%s" from the database' % name + self.home() + self.visit_url( '%s/library_admin/browse_library?id=%s' % ( self.url, str( library_one.id ) ) ) + self.check_page_for_string( name ) # create address #self.create_address( user_address1 ) #self.check_page_for_string( 'Address <b>%s</b> has been added' % user_address1[ 'short_desc' ] ) @@ -175,7 +192,7 @@ 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.create_request(request_type.id, request_name, request_desc, library_one.id, folder_one.id, fields) self.check_page_for_string( request_name ) self.check_page_for_string( request_desc ) global request_one @@ -195,7 +212,7 @@ 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) + self.edit_request(request_one.id, request_one.name, request_one.name+' (Renamed)', request_one.desc+' (Re-described)', library_one.id, folder_one.id, fields) request_one.refresh() self.check_page_for_string( request_name+' (Renamed)' ) self.check_page_for_string( request_desc+' (Re-described)' )