details: http://www.bx.psu.edu/hg/galaxy/rev/079bf1a8422b changeset: 2486:079bf1a8422b user: rc date: Thu Jul 16 09:45:43 2009 -0400 description: Replaced id's with objects as parameters to all the form & requests table classes 6 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/requests.py lib/galaxy/web/controllers/requests_admin.py templates/admin/requests/manage_request_types.mako diffs (296 lines): diff -r dd5f1fe8f5e9 -r 079bf1a8422b lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py Wed Jul 15 14:11:35 2009 -0400 +++ b/lib/galaxy/model/__init__.py Thu Jul 16 09:45:43 2009 -0400 @@ -1099,53 +1099,55 @@ class FormDefinition( object ): - def __init__(self, name=None, desc=None, fields=[], current_form_id=None): + def __init__(self, name=None, desc=None, fields=[], current_form=None): self.name = name self.desc = desc self.fields = fields - self.form_definition_current_id = current_form_id + self.form_definition_current = current_form class FormDefinitionCurrent( object ): - def __init__(self, form_definition_id=None): - self.latest_form_id = form_definition_id + def __init__(self, form_definition=None): + self.latest_form = form_definition class FormValues( object ): - def __init__(self, form_def_id=None, content=None): - self.form_definition_id = form_def_id + def __init__(self, form_def=None, content=None): + self.form_definition = form_def 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=None, user=None, + form_values=None, library=None): self.name = name self.desc = desc - self.request_type_id = request_type_id - self.form_values_id = form_values_id - self.user_id = user_id - self.library_id = library_id + self.type = request_type + self.values = form_values + self.user = user + self.library = library class RequestType( object ): - def __init__(self, request_form_id=None, sample_form_id=None): - self.request_form_id = request_form_id - self.sample_form_id = sample_form_id + def __init__(self, request_form=None, sample_form=None): + self.request_form = request_form + self.sample_form = sample_form class Sample( object ): - def __init__(self, name=None, desc=None, request_id=None, form_values_id=None): + def __init__(self, name=None, desc=None, request=None, form_values=None): self.name = name self.desc = desc - self.request_id = request_id - self.form_values_id = form_values_id + self.request = request + self.values = form_values + + class SampleState( object ): - def __init__(self, name=None, desc=None, request_type_id=None): + def __init__(self, name=None, desc=None, request_type=None): self.name = name self.desc = desc - self.request_type_id = request_type_id + self.request_type = request_type class SampleEvent( object ): - def __init__(self, sample_id=None, sample_state_id=None, comment=''): - self.sample_id = sample_id - self.sample_state_id = sample_state_id + def __init__(self, sample=None, sample_state=None, comment=''): + self.sample = sample + self.state = sample_state self.comment = comment diff -r dd5f1fe8f5e9 -r 079bf1a8422b lib/galaxy/model/mapping.py --- a/lib/galaxy/model/mapping.py Wed Jul 15 14:11:35 2009 -0400 +++ b/lib/galaxy/model/mapping.py Thu Jul 16 09:45:43 2009 -0400 @@ -613,7 +613,10 @@ primaryjoin=( Sample.table.c.request_id == Request.table.c.id ) ), ) ) -assign_mapper( context, FormValues, FormValues.table, properties=None) +assign_mapper( context, FormValues, FormValues.table, + properties=dict( form_definition=relation( FormDefinition, + primaryjoin=( FormValues.table.c.form_definition_id == FormDefinition.table.c.id ) ) + ) ) assign_mapper( context, Request, Request.table, properties=dict( values=relation( FormValues, @@ -723,9 +726,7 @@ 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) ), + order_by=desc(History.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 dd5f1fe8f5e9 -r 079bf1a8422b lib/galaxy/web/controllers/admin.py --- a/lib/galaxy/web/controllers/admin.py Wed Jul 15 14:11:35 2009 -0400 +++ b/lib/galaxy/web/controllers/admin.py Thu Jul 16 09:45:43 2009 -0400 @@ -2185,8 +2185,8 @@ 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 )) - rt.sample_form_id = int(util.restore_text( params.sample_form_id )) + 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() @@ -2196,7 +2196,7 @@ 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 )) - ss = trans.app.model.SampleState(name, desc, rt.id) + ss = trans.app.model.SampleState(name, desc, rt) ss.flush() msg = "The new sample type named '%s' with %s state(s) has been created" % (rt.name, num_states) return rt, msg diff -r dd5f1fe8f5e9 -r 079bf1a8422b lib/galaxy/web/controllers/requests.py --- a/lib/galaxy/web/controllers/requests.py Wed Jul 15 14:11:35 2009 -0400 +++ b/lib/galaxy/web/controllers/requests.py Thu Jul 16 09:45:43 2009 -0400 @@ -236,11 +236,11 @@ 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_type.request_form.id, values) + form_values = trans.app.model.FormValues(request_type.request_form, values) form_values.flush() - request = trans.app.model.Request(name, desc, request_type.id, - trans.user.id, form_values.id, - library_id) + request = trans.app.model.Request(name, desc, request_type, + trans.user, form_values, + trans.app.model.Library.get(library_id)) request.flush() else: # TODO editing @@ -252,7 +252,7 @@ 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) + form_values = request.values else: form_values = None # list of widgets to be rendered on the request form @@ -278,7 +278,8 @@ widget=lib_list, helptext='Associated library where the resultant \ dataset will be stored')) - widgets = self.__create_form(trans, request_type.request_form_id, widgets, form_values, **kwd) + 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_type.request_form_id, @@ -336,7 +337,7 @@ 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) + form_values = sample.values else: form_values = None # list of widgets to be rendered on the request form @@ -349,7 +350,8 @@ widget=TextField('desc', 40, util.restore_text( params.get( 'desc', '' ) )), helptext='(Optional)')) - widgets = self.__create_form(trans, request.type.sample_form_id, widgets, form_values, **kwd) + 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=request.type.sample_form_id, @@ -393,13 +395,13 @@ 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(request.type.sample_form.id, values) + form_values = trans.app.model.FormValues(request.type.sample_form, values) form_values.flush() - sample = trans.app.model.Sample(name, desc, request.id, form_values.id) + sample = trans.app.model.Sample(name, desc, request, form_values) 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() - event = trans.app.model.SampleEvent(sample.id, state.id) + event = trans.app.model.SampleEvent(sample, state) event.flush() else: form_data.content = values diff -r dd5f1fe8f5e9 -r 079bf1a8422b lib/galaxy/web/controllers/requests_admin.py --- a/lib/galaxy/web/controllers/requests_admin.py Wed Jul 15 14:11:35 2009 -0400 +++ b/lib/galaxy/web/controllers/requests_admin.py Thu Jul 16 09:45:43 2009 -0400 @@ -242,15 +242,13 @@ return trans.fill_template( '/admin/samples/view_sample.mako', sample_details=sample_details) def __get_all_states(self, trans, sample): - request = trans.app.model.Request.get(sample.request_id) - request_type = trans.app.model.RequestType.get(request.request_type_id) 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) - states_list = trans.app.model.SampleState.filter(trans.app.model.SampleState.table.c.request_type_id == request_type.id) + curr_state = all_states[len(all_states)-1].state + states_list = trans.app.model.SampleState.filter(trans.app.model.SampleState.table.c.request_type_id == sample.request.type.id) return states_list def __get_curr_state(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 def change_state(self, trans, sample_id_list): sample = trans.app.model.Sample.get(sample_id_list[0]) @@ -280,35 +278,33 @@ sample_id_list = util.string_to_object(util.restore_text( params.sample_id_list )) comments = util.restore_text( params.comment ) sample = trans.app.model.Sample.get(sample_id_list[0]) - request = trans.app.model.Request.get(sample.request_id) selected_state = util.restore_text( params.select_state ) - new_state = trans.app.model.SampleState.filter(trans.app.model.SampleState.table.c.request_type_id == request.request_type_id + new_state = trans.app.model.SampleState.filter(trans.app.model.SampleState.table.c.request_type_id == sample.request.type.id and trans.app.model.SampleState.table.c.name == selected_state)[0] - for sample_id in sample_id_list: - event = trans.app.model.SampleEvent(sample_id, new_state.id, comments) + for id in sample_id_list: + s = trans.app.model.Sample.get(id) + event = trans.app.model.SampleEvent(s, new_state, comments) event.flush() return trans.response.send_redirect( web.url_for( controller='requests_admin', action='list', operation='samples', - id=trans.security.encode_id(request.id)) ) + id=trans.security.encode_id(sample.request.id)) ) @web.expose @web.require_admin def show_events(self, trans, sample_id): sample = trans.app.model.Sample.get(sample_id) - request = trans.app.model.Request.get(sample.request_id) events_list = [] 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 ): last_update = '%s hours' % int( delta.seconds / 60 / 60 ) else: last_update = '%s minutes' % int( delta.seconds / 60 ) - events_list.append((state.name, state.desc, last_update, event.comment)) + events_list.append((event.state.name, event.state.desc, last_update, event.comment)) return trans.fill_template( '/admin/samples/events.mako', events_list=events_list, - sample_name=sample.name, user=trans.app.model.User.get(request.user_id), - request=request.name) + sample_name=sample.name, user=sample.request.user, + request=sample.request.name) \ No newline at end of file diff -r dd5f1fe8f5e9 -r 079bf1a8422b templates/admin/requests/manage_request_types.mako --- a/templates/admin/requests/manage_request_types.mako Wed Jul 15 14:11:35 2009 -0400 +++ b/templates/admin/requests/manage_request_types.mako Thu Jul 16 09:45:43 2009 -0400 @@ -41,18 +41,8 @@ <tr> <td><b><a href="${h.url_for( controller='admin', action='request_type', edit='True', id=request_type.id)}">${request_type.name}</a></b></td> <td><i>${request_type.desc}</i></td> - <% for form in forms: - if form.id == request_type.request_form_id: - form_name = form.name - break - %> - <td><a href="${h.url_for( controller='forms', action='edit', form_id=request_type.request_form_id, read_only=True)}">${form_name}</a></td> - <% for form in forms: - if form.id == request_type.sample_form_id: - form_name = form.name - break - %> - <td><a href="${h.url_for( controller='forms', action='edit', form_id=request_type.sample_form_id, read_only=True)}">${form_name}</a></td> + <td><a href="${h.url_for( controller='forms', action='edit', form_id=request_type.request_form.id, read_only=True)}">${request_type.request_form.name}</a></td> + <td><a href="${h.url_for( controller='forms', action='edit', form_id=request_type.sample_form.id, read_only=True)}">${request_type.sample_form.name}</a></td> </tr> %endfor </tbody>