details: http://www.bx.psu.edu/hg/galaxy/rev/228dd6f56b68 changeset: 2553:228dd6f56b68 user: rc date: Tue Aug 11 13:21:20 2009 -0400 description: Added browse button on csv importers in LIMS Fixed a bug in creating request types 9 file(s) affected in this change: lib/galaxy/web/controllers/admin.py lib/galaxy/web/controllers/forms.py lib/galaxy/web/controllers/library.py lib/galaxy/web/controllers/requests.py templates/admin/forms/create_form.mako templates/admin/requests/add_states.mako templates/admin/requests/create_request_type.mako templates/admin/requests/manage_request_types.mako templates/requests/show_request.mako diffs (332 lines): diff -r c021935a25ac -r 228dd6f56b68 lib/galaxy/web/controllers/admin.py --- a/lib/galaxy/web/controllers/admin.py Mon Aug 10 14:00:47 2009 -0400 +++ b/lib/galaxy/web/controllers/admin.py Tue Aug 11 13:21:20 2009 -0400 @@ -710,7 +710,7 @@ library=trans.app.model.Library.get( id ), deleted=deleted, created_ldda_ids=created_ldda_ids, - forms=get_all_forms( trans ), + forms=get_all_forms( trans, filter=dict(deleted=False) ), msg=msg, messagetype=messagetype, show_deleted=show_deleted ) @@ -1628,7 +1628,7 @@ library_item_desc = 'library' response_action = 'browse_library' response_id = library_id - forms = get_all_forms( trans ) + forms = get_all_forms( trans, filter=dict(deleted=False) ) if not forms: msg = "There are no forms on which to base the template, so create a form and " msg += "try again to add the information template to the %s." % library_item_desc @@ -1982,19 +1982,20 @@ 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 ), + forms=get_all_forms( trans, + filter=dict(deleted=False) ), msg=msg, messagetype=messagetype) - elif params.get( 'add_states', False ): + elif params.get( 'define_states_button', False ): return trans.fill_template( '/admin/requests/add_states.mako', - sample_type_name=util.restore_text( params.name ), + 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_new', False ): + 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', @@ -2005,7 +2006,7 @@ action='manage_request_types', msg='Request type <b>%s</b> has been created' % st.name, messagetype='done') ) - elif params.get('edit', False) == 'True': + 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', @@ -2039,9 +2040,6 @@ for ss in ss_list: ss.delete() ss.flush() - # unsubmitted state - #ss = trans.app.model.SampleState('Unsubmitted', 'Sample not yet submitted', rt) - ##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 )) @@ -2075,5 +2073,5 @@ 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, + msg='Request type <b>%s</b> has been undeleted' % rt.name, messagetype='done') ) diff -r c021935a25ac -r 228dd6f56b68 lib/galaxy/web/controllers/forms.py --- a/lib/galaxy/web/controllers/forms.py Mon Aug 10 14:00:47 2009 -0400 +++ b/lib/galaxy/web/controllers/forms.py Tue Aug 11 13:21:20 2009 -0400 @@ -62,7 +62,7 @@ self.current_form[ 'fields' ] = [] inputs = [ ( 'Name', TextField( 'name', 40, self.current_form[ 'name' ] ) ), ( 'Description', TextField( 'description', 40, self.current_form[ 'desc' ] ) ), - ( 'Import from csv file (Optional)', TextField( 'csv_file', 40, '' ) ) ] + ( 'Import from csv file (Optional)', FileField( 'file_data', 40, '' ) ) ] return trans.fill_template( '/admin/forms/create_form.mako', inputs=inputs, msg=msg, @@ -123,13 +123,13 @@ return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, empty_form=True, **kwd ) # Delete a field elif params.get( 'remove_button', False ): - self.__update_current_form( **kwd ) + self.__update_current_form( trans, **kwd ) index = int( kwd[ 'remove_button' ].split( ' ' )[2] ) - 1 self.__remove_field( index ) return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) # Save changes elif params.get( 'save_changes_button', False ): - self.__update_current_form( **kwd ) + self.__update_current_form( trans, **kwd ) fd_new, msg = self.__save_form( trans, fd.form_definition_current.id, **kwd ) if not fd_new: return self.__show( trans=trans, form=fd, msg=msg, messagetype='error', **kwd ) @@ -139,7 +139,7 @@ return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) #Add a field elif params.get( 'add_field_button', False ): - self.__update_current_form( **kwd ) + self.__update_current_form( trans, **kwd ) self.__add_field() # show the form again with one empty field return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) @@ -151,7 +151,7 @@ messagetype=messagetype ) # Refresh page, SelectField is selected/deselected as the type of a field elif params.get( 'refresh', False ): - self.__update_current_form( **kwd ) + self.__update_current_form( trans, **kwd ) return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) # Remove SelectField option elif params.get( 'select_box_options', False ) == 'remove': @@ -235,29 +235,28 @@ if not util.restore_text(params.get( 'field_name_%i' % i, None )): return None, "All the field label(s) must be completed." return True, '' - def __get_form(self, **kwd): + def __get_form(self, trans, **kwd): params = util.Params( kwd ) name = util.restore_text( params.name ) desc = util.restore_text( params.description ) or "" - if params.get( 'csv_file', None ): - csv_file = util.restore_text( params.get( 'csv_file', '' ) ) - if csv_file: - fields = self.__import_fields(csv_file) - else: + csv_file = params.get( 'file_data', '' ) + if csv_file == '': # set form fields fields = [] for i in range( len(self.current_form['fields']) ): fields.append(self.__get_field(i, **kwd)) fields = fields + else: + fields = self.__import_fields(trans, csv_file) return name, desc, fields - def __update_current_form(self, **kwd): - name, desc, fields = self.__get_form(**kwd) + def __update_current_form(self, trans, **kwd): + name, desc, fields = self.__get_form(trans, **kwd) self.current_form = {} self.current_form['name'] = name self.current_form['desc'] = desc self.current_form['fields'] = fields - def __import_fields(self, csv_file): + def __import_fields(self, trans, csv_file): ''' "company","name of the company", "True", "required", "TextField",, "due date","turnaround time", "True", "optional", "SelectField","24 hours, 1 week, 1 month" @@ -265,7 +264,7 @@ import csv fields = [] try: - reader = csv.reader(open(csv_file)) + reader = csv.reader(csv_file.file) for row in reader: options = row[5].split(',') fields.append({'label': row[0], @@ -291,7 +290,7 @@ if not flag: return None, msg fd = trans.app.model.FormDefinition() - fd.name, fd.desc, fd.fields = self.__get_form(**kwd) + fd.name, fd.desc, 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 @@ -415,9 +414,11 @@ ''' if all_versions: return trans.app.model.FormDefinition.query().all() + if filter: + 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 ] + return [ fdc.latest_form for fdc in fdc_list ] def get_form_widgets( trans, form, contents={} ): ''' Return the list of widgets that comprise a form definition, diff -r c021935a25ac -r 228dd6f56b68 lib/galaxy/web/controllers/library.py --- a/lib/galaxy/web/controllers/library.py Mon Aug 10 14:00:47 2009 -0400 +++ b/lib/galaxy/web/controllers/library.py Tue Aug 11 13:21:20 2009 -0400 @@ -1130,7 +1130,7 @@ library_id=library_id, folder_id=folder_id, ldda_id=ldda_id, - forms=get_all_forms( trans ), + forms=get_all_forms( trans, filter=dict(deleted=False) ), msg=msg, messagetype=messagetype ) @web.expose diff -r c021935a25ac -r 228dd6f56b68 lib/galaxy/web/controllers/requests.py --- a/lib/galaxy/web/controllers/requests.py Mon Aug 10 14:00:47 2009 -0400 +++ b/lib/galaxy/web/controllers/requests.py Tue Aug 11 13:21:20 2009 -0400 @@ -7,6 +7,8 @@ import logging, tempfile, zipfile, tarfile, os, sys from galaxy.web.form_builder import * from datetime import datetime, timedelta +from cgi import escape, FieldStorage + log = logging.getLogger( __name__ ) @@ -216,11 +218,10 @@ message="Invalid request ID", **kwd) ) if params.get('import_samples_button', False) == 'Import samples': - import traceback try: - fname = params.get('import_samples', '') + file_obj = params.get('file_data', '') import csv - reader = csv.reader(open(fname)) + reader = csv.reader(file_obj.file) for row in reader: self.current_samples.append([row[0], row[1:]]) return trans.fill_template( '/requests/show_request.mako', @@ -234,7 +235,7 @@ return trans.response.send_redirect( web.url_for( controller='requests', action='list', status='error', - message='Error in importing <b>%s</b> samples file' % fname, + message='Error in importing <b>%s</b> samples file' % file_obj.file, **kwd)) elif params.get('add_sample_button', False) == 'Add New': # save the all (saved+unsaved) sample info in 'current_samples' diff -r c021935a25ac -r 228dd6f56b68 templates/admin/forms/create_form.mako --- a/templates/admin/forms/create_form.mako Mon Aug 10 14:00:47 2009 -0400 +++ b/templates/admin/forms/create_form.mako Tue Aug 11 13:21:20 2009 -0400 @@ -8,7 +8,7 @@ <div class="toolForm"> <div class="toolFormTitle">Create a new form definition</div> <div class="toolFormBody"> - <form name="create_form" action="${h.url_for( controller='forms', action='new', create_form=True )}" method="post" > + <form name="create_form" action="${h.url_for( controller='forms', action='new', create_form=True )}" enctype="multipart/form-data" method="post" > %for label, input in inputs: <div class="form-row"> <label>${label}</label> diff -r c021935a25ac -r 228dd6f56b68 templates/admin/requests/add_states.mako --- a/templates/admin/requests/add_states.mako Mon Aug 10 14:00:47 2009 -0400 +++ b/templates/admin/requests/add_states.mako Tue Aug 11 13:21:20 2009 -0400 @@ -6,8 +6,8 @@ %endif <div class="toolForm"> - <div class="toolFormTitle">Create ${num_states} states for the '${sample_type_name}' request type</div> - <form name="new_form_fields" action="${h.url_for( controller='admin', action='request_type', save_new=True, create=False, edit=False, name=sample_type_name, description=desc, num_states=num_states, request_form_id=request_form_id, sample_form_id=sample_form_id)}" method="post" > + <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" > <div class="toolFormBody"> %for element_count in range( num_states ): <div class="form-row"> @@ -20,7 +20,7 @@ %endfor </div> <div class="form-row"> - <input type="submit" name="save_new_sample_type" value="Save"/> + <input type="submit" name="save_request_type" value="Save"/> </div> </form> </div> \ No newline at end of file diff -r c021935a25ac -r 228dd6f56b68 templates/admin/requests/create_request_type.mako --- a/templates/admin/requests/create_request_type.mako Mon Aug 10 14:00:47 2009 -0400 +++ b/templates/admin/requests/create_request_type.mako Tue Aug 11 13:21:20 2009 -0400 @@ -12,7 +12,7 @@ Create a 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', add_states=True, create=False, edit=False )}" method="post" > + <form name="create_request_type" action="${h.url_for( controller='admin', action='request_type')}" method="post" > <div class="form-row"> <label>Name:</label> <div style="float: left; width: 250px; margin-right: 10px;"> @@ -60,7 +60,7 @@ <div style="clear: both"></div> </div> <div class="form-row"> - <input type="submit" name="create_request_type_button" value="Define states"/> + <input type="submit" name="define_states_button" value="Define states"/> </div> </form> </div> diff -r c021935a25ac -r 228dd6f56b68 templates/admin/requests/manage_request_types.mako --- a/templates/admin/requests/manage_request_types.mako Mon Aug 10 14:00:47 2009 -0400 +++ b/templates/admin/requests/manage_request_types.mako Tue Aug 11 13:21:20 2009 -0400 @@ -46,7 +46,7 @@ %for request_type in request_types: <tr> <td> - <a href="${h.url_for( controller='admin', action='request_type', edit='True', id=request_type.id)}">${request_type.name}</a> + <a href="${h.url_for( controller='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 c021935a25ac -r 228dd6f56b68 templates/requests/show_request.mako --- a/templates/requests/show_request.mako Mon Aug 10 14:00:47 2009 -0400 +++ b/templates/requests/show_request.mako Tue Aug 11 13:21:20 2009 -0400 @@ -10,7 +10,6 @@ <div class="grid-header"> <h2>Sequencing Request "${request.name}"</h2> </div> - <ul class="manage-table-actions"> %if request.unsubmitted() and request.samples: @@ -109,7 +108,7 @@ <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' )}" method="post" > + <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"> @@ -186,7 +185,7 @@ <td> ##<div class="form-row"> <label>Import from csv file</label> - <input type="text" name="import_samples" value="" size="20"/> + <input type="file" name="file_data" /> <input type="submit" name="import_samples_button" value="Import samples"/> ##</div> </td>