From 2cd2c865ad1ff71fc38f5cde67a0a95a1d57dcd0 Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Sun, 20 Sep 2009 11:48:51 -0400 Subject: [PATCH] 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. --- lib/galaxy/model/__init__.py | 25 ++++++++++++++---- lib/galaxy/web/controllers/library.py | 26 ++++++++++++++++--- lib/galaxy/web/controllers/library_admin.py | 14 +++++++++- lib/galaxy/web/controllers/library_dataset.py | 12 ++++++--- templates/library/browse_library.mako | 12 ++++----- templates/library/new_dataset.mako | 15 ++++++++--- .../functional/test_security_and_libraries.py | 2 +- 7 files changed, 83 insertions(+), 23 deletions(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index fd38e7214c7..e17a096f385 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -693,7 +693,10 @@ class Library( object ): 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 @@ class LibraryFolder( object ): 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 @@ class LibraryDatasetDatasetAssociation( DatasetInstance ): 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 --git a/lib/galaxy/web/controllers/library.py b/lib/galaxy/web/controllers/library.py index f748e380c2f..c3a82f4a320 100644 --- a/lib/galaxy/web/controllers/library.py +++ b/lib/galaxy/web/controllers/library.py @@ -717,11 +717,21 @@ class Library( BaseController ): 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 @@ class Library( BaseController ): 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 @@ class Library( BaseController ): 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 --git a/lib/galaxy/web/controllers/library_admin.py b/lib/galaxy/web/controllers/library_admin.py index 31dd842fb39..319c2563581 100644 --- a/lib/galaxy/web/controllers/library_admin.py +++ b/lib/galaxy/web/controllers/library_admin.py @@ -429,11 +429,21 @@ class LibraryAdmin( BaseController ): 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 @@ class LibraryAdmin( BaseController ): 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 --git a/lib/galaxy/web/controllers/library_dataset.py b/lib/galaxy/web/controllers/library_dataset.py index 60e1caa157c..eb9e6e62c45 100644 --- a/lib/galaxy/web/controllers/library_dataset.py +++ b/lib/galaxy/web/controllers/library_dataset.py @@ -203,16 +203,20 @@ class UploadLibraryDataset( BaseController ): 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 --git a/templates/library/browse_library.mako b/templates/library/browse_library.mako index 06f1d78d690..a9b6ed1c50b 100644 --- a/templates/library/browse_library.mako +++ b/templates/library/browse_library.mako @@ -226,15 +226,15 @@ class RowCounter( object ):

Data Library “${library.name}”

<% -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 ) %>