details: http://www.bx.psu.edu/hg/galaxy/rev/ebf68a725c09 changeset: 2730:ebf68a725c09 user: Greg Von Kuster <greg@bx.psu.edu> date: Sun Sep 20 11:48:51 2009 -0400 description: Template fixes: get current FormDefinition when inheriting templates, and use filter then retrieving FormDeinition for library templates. A few other miscellaneous bug fixes as well. Functional tests should now pass. 7 file(s) affected in this change: lib/galaxy/model/__init__.py lib/galaxy/web/controllers/library.py lib/galaxy/web/controllers/library_admin.py lib/galaxy/web/controllers/library_dataset.py templates/library/browse_library.mako templates/library/new_dataset.mako test/functional/test_security_and_libraries.py diffs (247 lines): diff -r 8cbdd73ab68c -r ebf68a725c09 lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py Sat Sep 19 00:25:14 2009 -0400 +++ b/lib/galaxy/model/__init__.py Sun Sep 20 11:48:51 2009 -0400 @@ -693,7 +693,10 @@ return None, inherited def get_template_widgets( self, trans, get_contents=True ): # See if we have any associated templates - the returned value for - # inherited is not applicable at the library level + # inherited is not applicable at the library level. The get_contents + # param is passed by callers that are inheriting a template - these + # are usually new library datsets for which we want to include template + # fields on the upload form. info_association, inherited = self.get_info_association() if info_association: template = info_association.template @@ -738,10 +741,16 @@ return self.library_root[0].get_info_association( inherited=True ) return None, inherited def get_template_widgets( self, trans, get_contents=True ): - # See if we have any associated templates + # See if we have any associated templates. The get_contents + # param is passed by callers that are inheriting a template - these + # are usually new library datsets for which we want to include template + # fields on the upload form. info_association, inherited = self.get_info_association() if info_association: - template = info_association.template + if inherited: + template = info_association.template.current.latest_form + else: + template = info_association.template # See if we have any field contents, but only if the info_association was # not inherited ( we do not want to display the inherited contents ). if not inherited and get_contents: @@ -881,10 +890,16 @@ return None, inherited return self.library_dataset.folder.get_info_association( inherited=True ) def get_template_widgets( self, trans, get_contents=True ): - # See if we have any associated templates + # See if we have any associated templatesThe get_contents + # param is passed by callers that are inheriting a template - these + # are usually new library datsets for which we want to include template + # fields on the upload form. info_association, inherited = self.get_info_association() if info_association: - template = info_association.template + if inherited: + template = info_association.template.current.latest_form + else: + template = info_association.template # See if we have any field contents, but only if the info_association was # not inherited ( we do not want to display the inherited contents ). if not inherited and get_contents: diff -r 8cbdd73ab68c -r ebf68a725c09 lib/galaxy/web/controllers/library.py --- a/lib/galaxy/web/controllers/library.py Sat Sep 19 00:25:14 2009 -0400 +++ b/lib/galaxy/web/controllers/library.py Sun Sep 20 11:48:51 2009 -0400 @@ -717,11 +717,21 @@ if trans.app.security_agent.can_add_library_item( user, roles, folder ) or \ ( replace_dataset and trans.app.security_agent.can_modify_library_item( user, roles, replace_dataset ) ): if params.get( 'new_dataset_button', False ): + # See if we have any inherited templates, but do not inherit contents. + info_association, inherited = folder.get_info_association( inherited=True ) + if info_association: + template_id = str( info_association.template.id ) + widgets = folder.get_template_widgets( trans, get_contents=False ) + else: + template_id = None + widgets = [] upload_option = params.get( 'upload_option', 'upload_file' ) created_ldda_ids = trans.webapp.controllers[ 'library_dataset' ].upload_dataset( trans, controller='library', library_id=library_id, folder_id=folder_id, + template_id=template_id, + widgets=widgets, replace_dataset=replace_dataset, **kwd ) if created_ldda_ids: @@ -1049,6 +1059,17 @@ library_item_desc = 'library' response_action = 'browse_library' response_id = library_id + forms = get_all_forms( trans, + filter=dict( deleted=False ), + form_type=trans.app.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE ) + 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 + trans.response.send_redirect( web.url_for( controller='forms', + action='new', + new=True, + msg=msg, + messagetype='done' ) ) if params.get( 'add', False ): if params.get( 'add_info_template_button', False ): form = trans.app.model.FormDefinition.get( int( kwd[ 'form_id' ] ) ) @@ -1068,14 +1089,13 @@ id=response_id, msg=msg, message_type='done' ) ) - return trans.fill_template( '/library/select_info_template.mako', + return trans.fill_template( '/admin/library/select_info_template.mako', library_item_name=library_item.name, library_item_desc=library_item_desc, library_id=library_id, folder_id=folder_id, ldda_id=ldda_id, - forms=get_all_forms( trans, filter=dict(deleted=False), - form_type=trans.app.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE ), + forms=forms, msg=msg, messagetype=messagetype ) @web.expose diff -r 8cbdd73ab68c -r ebf68a725c09 lib/galaxy/web/controllers/library_admin.py --- a/lib/galaxy/web/controllers/library_admin.py Sat Sep 19 00:25:14 2009 -0400 +++ b/lib/galaxy/web/controllers/library_admin.py Sun Sep 20 11:48:51 2009 -0400 @@ -429,11 +429,21 @@ ldatatypes = [ dtype_name for dtype_name, dtype_value in trans.app.datatypes_registry.datatypes_by_extension.iteritems() if dtype_value.allow_datatype_change ] ldatatypes.sort() if params.get( 'new_dataset_button', False ): + # See if we have any inherited templates, but do not inherit contents. + info_association, inherited = folder.get_info_association( inherited=True ) + if info_association: + template_id = str( info_association.template.id ) + widgets = folder.get_template_widgets( trans, get_contents=False ) + else: + template_id = None + widgets = [] upload_option = params.get( 'upload_option', 'upload_file' ) created_ldda_ids = trans.webapp.controllers[ 'library_dataset' ].upload_dataset( trans, controller='library_admin', library_id=library_id, folder_id=folder_id, + template_id=template_id, + widgets=widgets, replace_dataset=replace_dataset, **kwd ) if created_ldda_ids: @@ -915,7 +925,9 @@ library_item_desc = 'library' response_action = 'browse_library' response_id = library_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 ) 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 diff -r 8cbdd73ab68c -r ebf68a725c09 lib/galaxy/web/controllers/library_dataset.py --- a/lib/galaxy/web/controllers/library_dataset.py Sat Sep 19 00:25:14 2009 -0400 +++ b/lib/galaxy/web/controllers/library_dataset.py Sun Sep 20 11:48:51 2009 -0400 @@ -203,16 +203,20 @@ err_redirect = False # See if we have any template field contents template_field_contents = [] - template = None + template_id = params.get( 'template_id', None ) folder = trans.app.model.LibraryFolder.get( folder_id ) - info_association, inherited = folder.get_info_association() - if info_association: - template = info_association.template + # We are inheriting the folder's info_association, so we did not + # receive any inherited contents, but we may have redirected here + # after the user entered template contents ( due to errors ). + if template_id: + template = trans.app.model.FormDefinition.get( template_id ) for field_index in range( len( template.fields ) ): field_name = 'field_%i' % field_index if params.get( field_name, False ): field_value = util.restore_text( params.get( field_name, '' ) ) template_field_contents.append( field_value ) + else: + template = None if upload_option == 'upload_file' and data_file == '' and url_paste == '': msg = 'Select a file, enter a URL or enter text' err_redirect = True diff -r 8cbdd73ab68c -r ebf68a725c09 templates/library/browse_library.mako --- a/templates/library/browse_library.mako Sat Sep 19 00:25:14 2009 -0400 +++ b/templates/library/browse_library.mako Sun Sep 20 11:48:51 2009 -0400 @@ -226,15 +226,15 @@ <h2>Data Library “${library.name}”</h2> <% -can_add = trans.app.security_agent.can_add_library_item( user, roles, library ) -can_modify = trans.app.security_agent.can_modify_library_item( user, roles, library ) -can_manage = trans.app.security_agent.can_manage_library_item( user, roles, library ) + can_add = trans.app.security_agent.can_add_library_item( user, roles, library ) + can_modify = trans.app.security_agent.can_modify_library_item( user, roles, library ) + can_manage = trans.app.security_agent.can_manage_library_item( user, roles, library ) %> <ul class="manage-table-actions"> - %if can_add and not_deleted: + %if can_add: <li> - <a class="action-button" href="${h.url_for( controller='library', action='library_dataset_dataset_association', library_id=library.id, folder_id=library.root_folder.id )}"><span>Add datasets to this library</span></a> + <a class="action-button" href="${h.url_for( controller='library', action='library_dataset_dataset_association', library_id=library.id, folder_id=library.root_folder.id )}"><span>Add datasets to this data library</span></a> </li> <li> <a class="action-button" href="${h.url_for( controller='library', action='folder', new=True, id=library.root_folder.id, library_id=library.id )}">Add a folder to this library</a> @@ -246,7 +246,7 @@ <li><a class="action-button" href="${h.url_for( controller='library', action='library', information=True, id=library.id )}">View this library's information</a></li> %endif %if can_add and forms and not library.info_association: - <a class="action-button" href="${h.url_for( controller='library', action='info_template', library_id=library.id, add=True )}">Add an information template to this library</a> + <a class="action-button" href="${h.url_for( controller='library', action='info_template', library_id=library.id, add=True )}">Add an information template to this data library</a> %endif %if can_manage: <li><a class="action-button" href="${h.url_for( controller='library', action='library', permissions=True, id=library.id )}">Edit this library's permissions</a></li> diff -r 8cbdd73ab68c -r ebf68a725c09 templates/library/new_dataset.mako --- a/templates/library/new_dataset.mako Sat Sep 19 00:25:14 2009 -0400 +++ b/templates/library/new_dataset.mako Sun Sep 20 11:48:51 2009 -0400 @@ -169,9 +169,18 @@ </div> </div> <div style="clear: both"></div> - <% folder = trans.app.model.LibraryFolder.get( folder_id ) %> - %if upload_option == 'upload_file' and widgets: - ${render_template_info( folder, library_id, widgets )} + %if widgets: + <p/> + %for i, field in enumerate( widgets ): + <div class="form-row"> + <label>${field[ 'label' ]}</label> + ${field[ 'widget' ].get_html()} + <div class="toolParamHelp" style="clear: both;"> + ${field[ 'helptext' ]} + </div> + <div style="clear: both"></div> + </div> + %endfor %endif <div class="form-row"> <input type="submit" class="primary-button" name="new_dataset_button" value="Upload to library"/> diff -r 8cbdd73ab68c -r ebf68a725c09 test/functional/test_security_and_libraries.py --- a/test/functional/test_security_and_libraries.py Sat Sep 19 00:25:14 2009 -0400 +++ b/test/functional/test_security_and_libraries.py Sun Sep 20 11:48:51 2009 -0400 @@ -488,7 +488,7 @@ .order_by( galaxy.model.FormDefinitionCurrent.table.c.create_time.desc() ) \ .all() for fdc in fdcs: - if form_name == fdc.latest_form.name: + if form_name == fdc.latest_form.name and form_type == fdc.latest_form.type: form_one = fdc.latest_form break assert form_one is not None, 'Problem retrieving form named (%s) from the database' % form_name