[hg] galaxy 2481: Updates to forms/requests:
details: http://www.bx.psu.edu/hg/galaxy/rev/c60fc2075dd5 changeset: 2481:c60fc2075dd5 user: rc date: Tue Jul 14 15:49:53 2009 -0400 description: Updates to forms/requests: - Mappers added to form & requests tables - Required/optional fields in requests and samples are now enforced Bug fix: duplicate field names in a request is working now 9 file(s) affected in this change: lib/galaxy/model/__init__.py lib/galaxy/model/mapping.py lib/galaxy/web/controllers/admin.py lib/galaxy/web/controllers/forms.py lib/galaxy/web/controllers/requests.py lib/galaxy/web/controllers/requests_admin.py templates/base.mako templates/sample/grid.mako templates/sample/sample_events.mako diffs (935 lines): diff -r dc5068efc3e7 -r c60fc2075dd5 lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py Tue Jul 14 11:33:42 2009 -0400 +++ b/lib/galaxy/model/__init__.py Tue Jul 14 15:49:53 2009 -0400 @@ -1115,7 +1115,8 @@ self.content = content class Request( object ): - def __init__(self, name=None, desc=None, request_type_id=None, user_id=None, form_values_id=None, library_id=None): + def __init__(self, name=None, desc=None, request_type_id=None, user_id=None, + form_values_id=None, library_id=None): self.name = name self.desc = desc self.request_type_id = request_type_id diff -r dc5068efc3e7 -r c60fc2075dd5 lib/galaxy/model/mapping.py --- a/lib/galaxy/model/mapping.py Tue Jul 14 11:33:42 2009 -0400 +++ b/lib/galaxy/model/mapping.py Tue Jul 14 15:49:53 2009 -0400 @@ -607,19 +607,39 @@ assign_mapper( context, Sample, Sample.table, properties=dict( events=relation( SampleEvent, backref="sample", order_by=desc(SampleEvent.table.c.update_time) ), + values=relation( FormValues, + primaryjoin=( Sample.table.c.form_values_id == FormValues.table.c.id ) ), + request=relation( Request, + primaryjoin=( Sample.table.c.request_id == Request.table.c.id ) ), ) ) assign_mapper( context, FormValues, FormValues.table, properties=None) -assign_mapper( context, Request, Request.table, properties=None) +assign_mapper( context, Request, Request.table, + properties=dict( values=relation( FormValues, + primaryjoin=( Request.table.c.form_values_id == FormValues.table.c.id ) ), + type=relation( RequestType, + primaryjoin=( Request.table.c.request_type_id == RequestType.table.c.id ) ), + user=relation( User, + primaryjoin=( Request.table.c.user_id == User.table.c.id ), + backref="requests" ), + library=relation( Library, + primaryjoin=( Request.table.c.library_id == Library.table.c.id ) ), + ) ) assign_mapper( context, RequestType, RequestType.table, properties=dict( states=relation( SampleState, backref="request_type", order_by=desc(SampleState.table.c.update_time) ), + request_form=relation( FormDefinition, + primaryjoin=( RequestType.table.c.request_form_id == FormDefinition.table.c.id ) ), + sample_form=relation( FormDefinition, + primaryjoin=( RequestType.table.c.sample_form_id == FormDefinition.table.c.id ) ), ) ) -assign_mapper( context, FormDefinition, FormDefinition.table, properties=None) - +assign_mapper( context, FormDefinition, FormDefinition.table, + properties=dict( current=relation( FormDefinitionCurrent, + primaryjoin=( FormDefinition.table.c.form_definition_current_id == FormDefinitionCurrent.table.c.id ) ) + ) ) assign_mapper( context, FormDefinitionCurrent, FormDefinitionCurrent.table, properties=dict( forms=relation( FormDefinition, backref='form_definition_current', cascade="all, delete-orphan", @@ -628,11 +648,14 @@ primaryjoin=( FormDefinitionCurrent.table.c.latest_form_id == FormDefinition.table.c.id ) ) ) ) -assign_mapper( context, SampleEvent, SampleEvent.table, properties=None) +assign_mapper( context, SampleEvent, SampleEvent.table, + properties=dict( state=relation( SampleState, + primaryjoin=( SampleEvent.table.c.sample_state_id == SampleState.table.c.id ) ), + ) ) + assign_mapper( context, SampleState, SampleState.table, - properties=None #dict( sample=relation( Sample, backref="sample" ), - )# ) + properties=None ) assign_mapper( context, ValidationError, ValidationError.table ) @@ -701,8 +724,8 @@ assign_mapper( context, User, User.table, properties=dict( histories=relation( History, backref="user", order_by=desc(History.table.c.update_time) ), - requests=relation( Request, backref="user", - order_by=desc(Request.table.c.update_time) ), +# requests=relation( Request, backref="user", +# order_by=desc(Request.table.c.update_time) ), active_histories=relation( History, primaryjoin=( ( History.table.c.user_id == User.table.c.id ) & ( not_( History.table.c.deleted ) ) ), order_by=desc( History.table.c.update_time ) ), galaxy_sessions=relation( GalaxySession, order_by=desc( GalaxySession.table.c.update_time ) ), stored_workflow_menu_entries=relation( StoredWorkflowMenuEntry, backref="user", diff -r dc5068efc3e7 -r c60fc2075dd5 lib/galaxy/web/controllers/admin.py --- a/lib/galaxy/web/controllers/admin.py Tue Jul 14 11:33:42 2009 -0400 +++ b/lib/galaxy/web/controllers/admin.py Tue Jul 14 15:49:53 2009 -0400 @@ -2146,7 +2146,7 @@ msg=msg, messagetype=messagetype) elif params.get('save_new', False) == 'True': - st, msg = self._save_request_type(trans, params, None) + st, msg = self._save_request_type(trans, **kwd) if not st: return trans.fill_template( '/admin/requests/create_request_type.mako', forms=self._get_all_forms(trans, all_versions=False), @@ -2170,24 +2170,9 @@ show_deleted=False, msg=msg, messagetype=messagetype ) - elif params.get('save_changes', False) == 'True': - st = trans.app.model.SampleType.get(int(util.restore_text( params.id ))) - st, msg = self._save_sample_type(trans, params, st.id) - if st: - msg = "The sample type '%s' has been updated with the changes." % st.name - messagetype = 'done' - else: - messagetype = 'error' - ss_list = trans.app.model.SampleState.filter(trans.app.model.SampleState.table.c.sample_type_id == st.id).all() - return trans.fill_template( '/admin/samples/edit_sample_type.mako', - sample_type=st, - forms=self._get_all_forms(trans, all_versions=False), - states_list=ss_list, - deleted=False, - show_deleted=False, - msg=msg, - messagetype=messagetype ) - def _save_request_type(self, trans, params, request_type_id): + + 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 ): @@ -2197,10 +2182,7 @@ if not proceed: msg = "All the state name(s) must be completed." return None, msg - if not request_type_id: # create a new sample type to save - rt = trans.app.model.RequestType() - else: # use the existing sample type to save changes - rt = trans.app.model.RequestType.get(request_type_id) + rt = trans.app.model.RequestType() rt.name = util.restore_text( params.name ) rt.desc = util.restore_text( params.description ) or "" rt.request_form_id = int(util.restore_text( params.request_form_id )) diff -r dc5068efc3e7 -r c60fc2075dd5 lib/galaxy/web/controllers/forms.py --- a/lib/galaxy/web/controllers/forms.py Tue Jul 14 11:33:42 2009 -0400 +++ b/lib/galaxy/web/controllers/forms.py Tue Jul 14 15:49:53 2009 -0400 @@ -70,7 +70,7 @@ elif params.get('create_form', False) == 'True': if 'submitted' in params.new: self.num_add_fields = 0 - fd, msg = self.__save_form(trans, params) + fd, msg = self.__save_form(trans, fdc_id=None, **kwd) self.__get_saved_form(fd) return self._show_forms_list(trans, msg, messagetype) @web.expose @@ -90,29 +90,34 @@ # the following two dicts store the unsaved select box options self.del_options = {} self.add_options = {} - return self.__show(trans, params, fd) + return self.__show(trans=trans, form=fd, msg=msg, + messagetype=messagetype, **kwd) # DELETE FIELD elif params.get('remove_button', False): - self.__update_current_form(params) + self.__update_current_form(**kwd) index = int(params.get('remove_button', None).split(' ')[2])-1 self.__remove_field(index) - return self.__show(trans, params, fd) + return self.__show(trans=trans, form=fd, msg=msg, + messagetype=messagetype, **kwd) # SAVE CHANGES elif params.get('save_changes_button', False) == 'Save': - self.__update_current_form(params) - fd_new, msg = self.__save_form(trans, params, fd.form_definition_current.id) + self.__update_current_form(**kwd) + fd_new, msg = self.__save_form(trans, fd.form_definition_current.id, **kwd) if not fd_new: - return self.__show(trans, params, fd, msg, 'error') + return self.__show(trans=trans, form=fd, msg=msg, + messagetype='error', **kwd) else: fd = fd_new msg = "The form '%s' has been updated with the changes." % fd.name - return self.__show(trans, params, fd, msg) + return self.__show(trans=trans, form=fd, msg=msg, + messagetype=messagetype, **kwd) #ADD A FIELD elif params.get('add_field_button', False) == 'Add field': - self.__update_current_form(params) + self.__update_current_form(**kwd) self.__add_field() # show the form again with one empty field - return self.__show(trans, params, fd) + return self.__show(trans=trans, form=fd, msg=msg, + messagetype=messagetype, **kwd) # SHOW FORM READ ONLY elif params.get('read_only', False): return trans.fill_template( '/admin/forms/show_form_read_only.mako', @@ -121,21 +126,24 @@ messagetype=messagetype ) # REFRESH PAGE, SelectField is selected/deselected as the type of a field elif params.get('refresh', False) == 'true': - self.__update_current_form(params) - return self.__show(trans, params, fd) + self.__update_current_form(**kwd) + return self.__show(trans=trans, form=fd, msg=msg, + messagetype=messagetype, **kwd) # REMOVE SelectField OPTION elif params.get('select_box_options', False) == 'remove': - #self.__update_current_form(params) + #self.__update_current_form(**kwd) index = int(params.get( 'field_index', None )) option = int(params.get( 'option_index', None )) del self.current_form['fields'][index]['selectlist'][option] - return self.__show(trans, params, fd) + return self.__show(trans=trans, form=fd, msg=msg, + messagetype=messagetype, **kwd) # ADD SelectField OPTION elif params.get('select_box_options', False) == 'add': - #self.__update_current_form(params) + #self.__update_current_form(**kwd) index = int(params.get( 'field_index', None )) self.current_form['fields'][index]['selectlist'].append('') - return self.__show(trans, params, fd) + return self.__show(trans=trans, form=fd, msg=msg, + messagetype=messagetype, **kwd) def __remove_field(self, index): del self.current_form['fields'][index] def __add_field(self): @@ -149,26 +157,31 @@ 'type': BaseField.form_field_types()[0], 'selectlist': '' } self.current_form['fields'].append(empty_field) - def __get_field(self, params, index): + def __get_field(self, index, **kwd): + params = util.Params( kwd ) name = util.restore_text( params.get( 'field_name_%i' % index, None ) ) helptext = util.restore_text( params.get( 'field_helptext_%i' % index, None ) ) required = params.get( 'field_required_%i' % index, False ) field_type = util.restore_text( params.get( 'field_type_%i' % index, None ) ) if field_type == 'SelectField': - selectlist = self.__get_selectbox_options(params, index) - else: - selectlist = None + selectlist = self.__get_selectbox_options(index, **kwd) + return {'label': name, + 'helptext': helptext, + 'visible': True, + 'required': required, + 'type': field_type, + 'selectlist': selectlist } return {'label': name, 'helptext': helptext, 'visible': True, 'required': required, - 'type': field_type, - 'selectlist': selectlist } - def __get_selectbox_options(self, params, index): + 'type': field_type} + def __get_selectbox_options(self, index, **kwd): ''' This method gets all the options entered by the user for field when the fieldtype is SelectField ''' + params = util.Params( kwd ) ctr=0 sb_options = [] while True: @@ -183,12 +196,13 @@ self.current_form['name'] = fd.name self.current_form['desc'] = fd.desc self.current_form['fields'] = list(copy.deepcopy(fd.fields)) - def __validate_form(self, params): + def __validate_form(self, **kwd): ''' This method checks the following text inputs are filled out by the user - the name of form - name of all the fields ''' + params = util.Params( kwd ) # form name if not util.restore_text( params.name ): return None, 'Form name must be filled.' @@ -197,32 +211,33 @@ 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, params): + def __get_form(self, **kwd): + params = util.Params( kwd ) name = util.restore_text( params.name ) desc = util.restore_text( params.description ) or "" # set form fields fields = [] for i in range( len(self.current_form['fields']) ): - fields.append(self.__get_field(params, i)) + fields.append(self.__get_field(i, **kwd)) fields = fields return name, desc, fields - def __update_current_form(self, params): - name, desc, fields = self.__get_form(params) + def __update_current_form(self, **kwd): + name, desc, fields = self.__get_form(**kwd) self.current_form = {} self.current_form['name'] = name self.current_form['desc'] = desc self.current_form['fields'] = fields - def __save_form(self, trans, params, fdc_id=None): + def __save_form(self, trans, fdc_id=None, **kwd): ''' This method saves the current form ''' # check the form for invalid inputs - flag, msg = self.__validate_form(params) + flag, msg = self.__validate_form(**kwd) if not flag: return None, msg fd = trans.app.model.FormDefinition() - fd.name, fd.desc, fd.fields = self.__get_form(params) + fd.name, fd.desc, fd.fields = self.__get_form(**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 @@ -302,10 +317,11 @@ def label(self): return str(self.index)+'.'+self.label - def __show(self, trans, params, form, msg=None, messagetype='done'): + def __show(self, trans, form, msg=None, messagetype='done', **kwd): ''' This method displays the form and any of the changes made to it ''' + params = util.Params( kwd ) # name & description form_details = [ ( 'Name', TextField('name', 40, self.current_form['name']) ), ( 'Description', TextField('description', 40, self.current_form['desc']) ) ] diff -r dc5068efc3e7 -r c60fc2075dd5 lib/galaxy/web/controllers/requests.py --- a/lib/galaxy/web/controllers/requests.py Tue Jul 14 11:33:42 2009 -0400 +++ b/lib/galaxy/web/controllers/requests.py Tue Jul 14 15:49:53 2009 -0400 @@ -6,11 +6,9 @@ from galaxy.util.streamball import StreamBall import logging, tempfile, zipfile, tarfile, os, sys from galaxy.web.form_builder import * +from datetime import datetime, timedelta log = logging.getLogger( __name__ ) - -# States for passing messages -SUCCESS, INFO, WARNING, ERROR = "done", "info", "warning", "error" class RequestsListGrid( grids.Grid ): title = "Requests" @@ -41,8 +39,7 @@ def get_current_item( self, trans ): return None def get_request_type(self, trans, request): - request_type = trans.app.model.RequestType.get(request.request_type_id) - return request_type.name + return request.type.name def apply_default_filter( self, trans, query ): return query.filter_by( user=trans.user ) def number_of_samples(self, trans, request): @@ -83,7 +80,7 @@ return query.filter_by( request_id=self.request.id ) def get_status(self, trans, sample): all_states = trans.app.model.SampleEvent.filter(trans.app.model.SampleEvent.table.c.sample_id == sample.id).all() - curr_state = trans.app.model.SampleState.get(all_states[len(all_states)-1].sample_state_id) + curr_state = all_states[len(all_states)-1].state return curr_state.name class Requests( BaseController ): @@ -92,6 +89,7 @@ @web.expose 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 = [] @@ -134,9 +132,6 @@ Shows the request details ''' request = trans.app.model.Request.get(id) - request_type = trans.app.model.RequestType.get(request.request_type_id) - request_form = trans.app.model.FormDefinition.get(request_type.request_form_id) - request_values = trans.app.model.FormValues.get(request.form_values_id) libraries = self.get_authorized_libs(trans) # list of widgets to be rendered on the request form request_details = [] @@ -148,7 +143,7 @@ value=request.desc, helptext='')) request_details.append(dict(label='Type', - value=request_type.name, + value=request.type.name, helptext='')) request_details.append(dict(label='Date created', value=request.create_time, @@ -157,26 +152,26 @@ value=request.create_time, helptext='')) request_details.append(dict(label='User', - value=str(trans.user.email), + value=str(request.user.email), helptext='')) # library associated request_details.append(dict(label='Library', - value=trans.app.model.Library.get(request.library_id).name, + value=request.library.name, helptext='Associated library where the resultant \ dataset will be stored')) # form fields - for field in request_form.fields: + for index, field in enumerate(request.type.request_form.fields): if field['required']: req = 'Required' else: req = 'Optional' request_details.append(dict(label=field['label'], - value=request_values.content[field['label']], + value=request.values.content[index], helptext=field['helptext']+' ('+req+')')) return trans.fill_template( '/requests/view_request.mako', - request_form_id=request_form.id, + request_form_id=request.type.request_form.id, request_details=request_details, - request_type=request_type) + request_type=request.type) @web.expose def new(self, trans, **kwd): params = util.Params( kwd ) @@ -189,49 +184,74 @@ msg=msg, messagetype=messagetype ) elif params.get('create', False) == 'True': - request_type_id = int(util.restore_text( params.request_type_id )) - return self.__show_request_form(trans, params, request_type_id) + print >> sys.stderr, '###KWD', kwd + return self.__show_request_form(trans=trans, + request=None, **kwd) elif params.get('save', False) == 'True': - request = self.__save(trans, params) + request_type = trans.app.model.RequestType.get(int(params.request_type_id)) + msg = self.__validate(trans, + [('name','Name'), ('library_id','Library')], + request_type.request_form.fields, + **kwd) + if msg: + kwd['create'] = 'True' + return trans.response.send_redirect( web.url_for( controller='requests', + action='new', + msg=msg, + messagetype='error', + **kwd) ) + request = self.__save_request(trans, None, **kwd) msg = 'The new request named %s has been created' % request.name request_type_id = int(util.restore_text( params.request_type_id )) return trans.response.send_redirect( web.url_for( controller='requests', action='list', msg=msg , messagetype='done') ) - return self.__show_request_form(trans, params, request_type_id, request=request) - def __save(self, trans, params, request_id=None): + def __validate(self, trans, main_fields=[], form_fields=[], **kwd): ''' - This method save a new request if request_id is None. + Validates the request entered by the user ''' + params = util.Params( kwd ) + for field, field_name in main_fields: + if not util.restore_text(params.get(field, None)): + return 'Please enter the <b>%s</b> of the request' % field_name + # check rest of the fields of the form + for index, field in enumerate(form_fields): + if not util.restore_text(params.get('field_%i' % index, None)) and field['required']: + return 'Please enter the <b>%s</b> field of the request' % field['label'] + return None + def __save_request(self, trans, request_id=None, **kwd): + ''' + This method saves a new request if request_id is None. + ''' + params = util.Params( kwd ) if not request_id: - request_type_id = int(util.restore_text( params.request_type_id )) - request_form_id = trans.app.model.RequestType.get(request_type_id).request_form_id - request_form = trans.app.model.FormDefinition.get(request_form_id) + request_type = trans.app.model.RequestType.get(int(params.request_type_id )) else: - request = trans.app.model.Request.get(request_id) - form_values = trans.app.model.FormValues.get(request.form_values_id) - request_form = trans.app.model.FormDefinition.get(form_values.request_form_id) + # TODO editing + pass name = util.restore_text(params.get('name', '')) desc = util.restore_text(params.get('desc', '')) - library_id = util.restore_text(params.get('library', '')) - values = {} - for field in request_form.fields: - values[field['label']] = util.restore_text(params.get(field['label'], '')) + library_id = int(util.restore_text(params.get('library_id', 0))) + values = [] + for index, field in enumerate(request_type.request_form.fields): + values.append(util.restore_text(params.get('field_%i' % index, ''))) if not request_id: - form_values = trans.app.model.FormValues(request_form_id, values) + form_values = trans.app.model.FormValues(request_type.request_form.id, values) form_values.flush() - request = trans.app.model.Request(name, desc, request_type_id, + request = trans.app.model.Request(name, desc, request_type.id, trans.user.id, form_values.id, library_id) request.flush() else: - form_values.content = values - form_values.flush() + # TODO editing + pass return request - def __show_request_form(self, trans, params, request_type_id, request=None): - request_type = trans.app.model.RequestType.get(request_type_id) - request_form_id = request_type.request_form_id + def __show_request_form(self, trans, request=None, **kwd): + params = util.Params( kwd ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) + request_type = trans.app.model.RequestType.get(int(params.request_type_id)) if request: form_values = trans.app.model.FormValues.get(request.form_values_id) else: @@ -239,56 +259,63 @@ # list of widgets to be rendered on the request form widgets = [] widgets.append(dict(label='Name', - widget=TextField('name'), + widget=TextField('name', 40, + util.restore_text( params.get( 'name', '' ) )), helptext='(Required)')) widgets.append(dict(label='Description', - widget=TextField('desc'), + widget=TextField('desc', 40, + util.restore_text( params.get( 'desc', '' ) )), helptext='(Optional)')) - widgets[0]['widget'].set_size(40) - widgets[1]['widget'].set_size(40) # libraries selectbox + value = int(params.get( 'library_id', 0 )) libraries = self.get_authorized_libs(trans) - lib_list = SelectField('library') + lib_list = SelectField('library_id') for lib in libraries: - lib_list.add_option(lib.name, lib.id) + if lib.id == value: + lib_list.add_option(lib.name, lib.id, selected=True) + else: + lib_list.add_option(lib.name, lib.id) widgets.append(dict(label='Library', widget=lib_list, helptext='Associated library where the resultant \ dataset will be stored')) - widgets = self.__create_form(trans, params, request_form_id, widgets, form_values) + 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 return trans.fill_template( '/requests/new_request.mako', - request_form_id=request_form_id, + request_form_id=request_type.request_form_id, request_type=request_type, widgets=widgets, - title=title) + title=title, + msg=msg, + messagetype=messagetype) - def __create_form(self, trans, params, form_id, widgets=[], form_values=None): + def __create_form(self, trans, form_id, widgets=[], form_values=None, **kwd): + params = util.Params( kwd ) form = trans.app.model.FormDefinition.get(form_id) - if not form_values: - values = {} - for field in form.fields: - if field['type'] in ['SelectField' or 'CheckBoxField']: - values[field['label']] = False - else: - values[field['label']] = '' - else: - values = form_values.content # form fields - for field in form.fields: - fw = eval(field['type'])(field['label']) + 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, '' ) ) + # create the field + fw = eval(field['type'])('field_%i' % index) if field['type'] == 'TextField': fw.set_size(40) - fw.value = values[field['label']] + fw.value = value elif field['type'] == 'TextArea': fw.set_size(3, 40) - fw.value = values[field['label']] + fw.value = value elif field['type'] == 'SelectField': for option in field['selectlist']: - fw.add_option(option, option, values[field['label']]) - elif field['type'] == 'CheckBoxField': - fw.checked = values[field['label']] - + 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']: req = 'Required' else: @@ -302,13 +329,13 @@ params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) - request_id = int(util.restore_text( params.get( 'id', '' ) )) - return self.__show_sample_form(trans, params, request_id) + return self.__show_sample_form(trans, sample=None, **kwd) - def __show_sample_form(self, trans, params, request_id, sample=None): - request = trans.app.model.Request.get(request_id) - request_type = trans.app.model.RequestType.get(request.request_type_id) - sample_form_id = request_type.sample_form_id + def __show_sample_form(self, trans, sample=None, **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.request_id )) if sample: form_values = trans.app.model.FormValues.get(sample.form_values_id) else: @@ -316,50 +343,63 @@ # list of widgets to be rendered on the request form widgets = [] widgets.append(dict(label='Name', - widget=TextField('name'), + widget=TextField('name', 40, + util.restore_text( params.get( 'name', '' ) )), helptext='(Required)')) widgets.append(dict(label='Description', - widget=TextField('desc'), + widget=TextField('desc', 40, + util.restore_text( params.get( 'desc', '' ) )), helptext='(Optional)')) - widgets[0]['widget'].set_size(40) - widgets[1]['widget'].set_size(40) - widgets = self.__create_form(trans, params, sample_form_id, widgets, form_values) - title = 'Add a new sample to request: %s of type: %s' % (request.name, request_type.name) + widgets = self.__create_form(trans, request.type.sample_form_id, widgets, form_values, **kwd) + title = 'Add a new sample to request: %s of type: %s' % (request.name, request.type.name) return trans.fill_template( '/sample/new_sample.mako', - sample_form_id=sample_form_id, + sample_form_id=request.type.sample_form_id, request_id=request.id, widgets=widgets, - title=title) + title=title, + msg=msg, + messagetype=messagetype) @web.expose def samples(self, trans, **kwd): params = util.Params( kwd ) if params.get('save', False) == 'True': - sample = self.__save_sample(trans, params) + request = trans.app.model.Request.get(int(params.request_id )) + msg = self.__validate(trans, + [('name','Name')], + request.type.sample_form.fields, + **kwd) + if msg: + return trans.response.send_redirect( web.url_for( controller='requests', + action='add_sample', + msg=msg, + messagetype='error', + **kwd) ) + sample = self.__save_sample(trans, sample_id=None, **kwd) + msg = 'The new sample named %s has been created' % sample.name return trans.response.send_redirect( web.url_for( controller='requests', action='list', operation='samples', - id=trans.security.encode_id(sample.request_id)) ) - def __save_sample(self, trans, params, sample_id=None): + id=trans.security.encode_id(sample.request_id), + **kwd) ) + def __save_sample(self, trans, sample_id=None, **kwd): + params = util.Params( kwd ) if not sample_id: - request = trans.app.model.Request.get(int(util.restore_text( params.request_id ))) - request_type = trans.app.model.RequestType.get(request.request_type_id) - sample_form = trans.app.model.FormDefinition.get(request_type.sample_form_id) + request = trans.app.model.Request.get(int(params.request_id)) else: - sample = trans.app.model.Sample.get(sample_id) - form_data = trans.app.model.FormData.get(sample.form_data_id) - form = trans.app.model.FormDefinition.get(form_data.form_definition_id) + #TODO editing + pass name = util.restore_text(params.get('name', '')) desc = util.restore_text(params.get('desc', '')) - values = {} - for field in sample_form.fields: - values[field['label']] = util.restore_text(params.get(field['label'], '')) + values = [] + for index, field in enumerate(request.type.sample_form.fields): + values.append(util.restore_text(params.get('field_%i' % index, ''))) if not sample_id: - form_values = trans.app.model.FormValues(sample_form.id, values) + form_values = trans.app.model.FormValues(request.type.sample_form.id, values) form_values.flush() sample = trans.app.model.Sample(name, desc, request.id, form_values.id) sample.flush() # set the initial state - state = trans.app.model.SampleState.filter(trans.app.model.SampleState.table.c.request_type_id == request_type.id).first() + state = trans.app.model.SampleState.filter(trans.app.model.SampleState.table.c.request_type_id == request.type.id).first() event = trans.app.model.SampleEvent(sample.id, state.id) event.flush() else: @@ -371,10 +411,10 @@ Shows the sample details ''' sample = trans.app.model.Sample.get(sample_id) - request = trans.app.model.Request.get(sample.request_id) - request_type = trans.app.model.RequestType.get(request.request_type_id) - sample_form = trans.app.model.FormDefinition.get(request_type.sample_form_id) - sample_values = trans.app.model.FormValues.get(sample.form_values_id) + request = sample.request + request_type = sample.request.type + sample_form = sample.request.type.sample_form + sample_values = sample.values # list of widgets to be rendered on the request form sample_details = [] # main details @@ -398,31 +438,37 @@ helptext='Name/ID of the request this sample belongs to.')) # get the current state of the sample all_states = trans.app.model.SampleEvent.filter(trans.app.model.SampleEvent.table.c.sample_id == sample_id).all() - curr_state = trans.app.model.SampleState.get(all_states[len(all_states)-1].sample_state_id) + curr_state = all_states[len(all_states)-1].state sample_details.append(dict(label='State', value=curr_state.name, helptext=curr_state.desc)) # form fields - for field in sample_form.fields: + for index, field in enumerate(sample_form.fields): if field['required']: req = 'Required' else: req = 'Optional' sample_details.append(dict(label=field['label'], - value=sample_values.content[field['label']], + value=sample_values.content[index], helptext=field['helptext']+' ('+req+')')) return trans.fill_template( '/sample/view_sample.mako', sample_details=sample_details) def show_events(self, trans, sample_id): sample = trans.app.model.Sample.get(sample_id) events_list = [] - for event in trans.app.model.SampleEvent.filter(trans.app.model.SampleEvent.table.c.sample_id == sample_id).all(): - state = trans.app.model.SampleState.get(event.sample_state_id) - events_list.append((state.name, event.update_time, state.desc, event.comment)) + all_events = trans.app.model.SampleEvent.filter(trans.app.model.SampleEvent.table.c.sample_id == sample_id).all() + all_events.reverse() + for event in all_events: + delta = datetime.utcnow() - event.update_time + if delta > timedelta( minutes=60 ): + last_update = '%s hours' % int( delta.seconds / 60 / 60 ) + else: + last_update = '%s minutes' % int( delta.seconds / 60 ) + events_list.append((event.state.name, event.state.desc, last_update, event.comment)) return trans.fill_template( '/sample/sample_events.mako', events_list=events_list, sample_name=sample.name, - request=trans.app.model.Request.get(sample.request_id).name) + request=sample.request.name) diff -r dc5068efc3e7 -r c60fc2075dd5 lib/galaxy/web/controllers/requests_admin.py --- a/lib/galaxy/web/controllers/requests_admin.py Tue Jul 14 11:33:42 2009 -0400 +++ b/lib/galaxy/web/controllers/requests_admin.py Tue Jul 14 15:49:53 2009 -0400 @@ -146,9 +146,6 @@ Shows the request details ''' request = trans.app.model.Request.get(id) - request_type = trans.app.model.RequestType.get(request.request_type_id) - request_form = trans.app.model.FormDefinition.get(request_type.request_form_id) - request_values = trans.app.model.FormValues.get(request.form_values_id) libraries = self.get_authorized_libs(trans) # list of widgets to be rendered on the request form request_details = [] @@ -160,7 +157,7 @@ value=request.desc, helptext='')) request_details.append(dict(label='Type', - value=request_type.name, + value=request.type.name, helptext='')) request_details.append(dict(label='Date created', value=request.create_time, @@ -169,7 +166,7 @@ value=request.create_time, helptext='')) request_details.append(dict(label='User', - value=str(trans.user.email), + value=str(request.user.email), helptext='')) # library associated request_details.append(dict(label='Library', @@ -177,18 +174,18 @@ helptext='Associated library where the resultant \ dataset will be stored')) # form fields - for field in request_form.fields: + for index, field in enumerate(request.type.request_form.fields): if field['required']: req = 'Required' else: req = 'Optional' request_details.append(dict(label=field['label'], - value=request_values.content[field['label']], + value=request.values.content[index], helptext=field['helptext']+' ('+req+')')) return trans.fill_template( '/admin/requests/view_request.mako', - request_form_id=request_form.id, + request_form_id=request.type.request_form.id, request_details=request_details, - request_type=request_type) + request_type=request.type) @web.expose @web.require_admin @@ -202,10 +199,10 @@ Shows the sample details ''' sample = trans.app.model.Sample.get(sample_id) - request = trans.app.model.Request.get(sample.request_id) - request_type = trans.app.model.RequestType.get(request.request_type_id) - sample_form = trans.app.model.FormDefinition.get(request_type.sample_form_id) - sample_values = trans.app.model.FormValues.get(sample.form_values_id) + request = sample.request + request_type = sample.request.type + sample_form = sample.request.type.sample_form + sample_values = sample.values # list of widgets to be rendered on the request form sample_details = [] # main details @@ -229,18 +226,18 @@ helptext='Name/ID of the request this sample belongs to.')) # get the current state of the sample all_states = trans.app.model.SampleEvent.filter(trans.app.model.SampleEvent.table.c.sample_id == sample_id).all() - curr_state = trans.app.model.SampleState.get(all_states[len(all_states)-1].sample_state_id) + curr_state = all_states[len(all_states)-1].state sample_details.append(dict(label='State', value=curr_state.name, helptext=curr_state.desc)) # form fields - for field in sample_form.fields: + for index, field in enumerate(sample_form.fields): if field['required']: req = 'Required' else: req = 'Optional' sample_details.append(dict(label=field['label'], - value=sample_values.content[field['label']], + value=sample_values.content[index], helptext=field['helptext']+' ('+req+')')) return trans.fill_template( '/admin/samples/view_sample.mako', sample_details=sample_details) @@ -300,7 +297,9 @@ sample = trans.app.model.Sample.get(sample_id) request = trans.app.model.Request.get(sample.request_id) events_list = [] - for event in trans.app.model.SampleEvent.filter(trans.app.model.SampleEvent.table.c.sample_id == sample_id).order_by(trans.app.model.SampleEvent.c.update_time.desc()).all(): + all_events = trans.app.model.SampleEvent.filter(trans.app.model.SampleEvent.table.c.sample_id == sample_id).all() + all_events.reverse() + for event in all_events: state = trans.app.model.SampleState.get(event.sample_state_id) delta = datetime.utcnow() - event.update_time if delta > timedelta( minutes=60 ): diff -r dc5068efc3e7 -r c60fc2075dd5 templates/base.mako --- a/templates/base.mako Tue Jul 14 11:33:42 2009 -0400 +++ b/templates/base.mako Tue Jul 14 15:49:53 2009 -0400 @@ -58,4 +58,5 @@ $( "#edit_form" ).submit(); } }); -}); \ No newline at end of file +}); +</script> \ No newline at end of file diff -r dc5068efc3e7 -r c60fc2075dd5 templates/sample/grid.mako --- a/templates/sample/grid.mako Tue Jul 14 11:33:42 2009 -0400 +++ b/templates/sample/grid.mako Tue Jul 14 15:49:53 2009 -0400 @@ -89,7 +89,7 @@ <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='requests', action='add_sample', id=grid.request.id)}"> + <a class="action-button" href="${h.url_for( controller='requests', action='add_sample', request_id=grid.request.id)}"> <img src="${h.url_for('/static/images/silk/add.png')}" /> <span>Add sample</span></a> </li> diff -r dc5068efc3e7 -r c60fc2075dd5 templates/sample/sample_events.mako --- a/templates/sample/sample_events.mako Tue Jul 14 11:33:42 2009 -0400 +++ b/templates/sample/sample_events.mako Tue Jul 14 15:49:53 2009 -0400 @@ -14,17 +14,17 @@ <thead> <tr> <th>State</th> + <th>Description</th> <th>Updated</th> - <th>Description</th> <th>Comments</th> </tr> </thead> <tbody> - %for state, updated, desc, comments in events_list: + %for state, desc, updated, comments in events_list: <tr class="libraryRow libraryOrFolderRow" id="libraryRow"> <td><b><a>${state}</a></b></td> + <td><a>${desc}</a></td> <td><a>${updated}</a></td> - <td><a>${desc}</a></td> <td><a>${comments}</a></td> </tr> %endfor
participants (1)
-
Greg Von Kuster