[hg] galaxy 3305: Fixes for library templates: add the ability t...
details: http://www.bx.psu.edu/hg/galaxy/rev/8b7d2cc963fd changeset: 3305:8b7d2cc963fd user: Greg Von Kuster <greg@bx.psu.edu> date: Sat Jan 30 07:48:39 2010 -0500 description: Fixes for library templates: add the ability to add a template to a librry dataset in addition to a library and a folder, add the ability to delete templates from library items. Fixes for displaying and hiding deleted library folders and datasets. diffstat: lib/galaxy/model/__init__.py | 8 +- lib/galaxy/model/mapping.py | 15 +- lib/galaxy/model/migrate/versions/0036_add_deleted_column_to_library_template_assoc_tables.py | 50 + lib/galaxy/web/controllers/library_admin.py | 8 +- lib/galaxy/web/controllers/library_common.py | 614 +++++---- templates/library/common/browse_library.mako | 120 +- templates/library/common/common.mako | 33 +- templates/library/common/folder_info.mako | 6 +- templates/library/common/folder_permissions.mako | 4 +- templates/library/common/ldda_edit_info.mako | 11 +- templates/library/common/ldda_info.mako | 18 +- templates/library/common/ldda_permissions.mako | 4 +- templates/library/common/library_dataset_info.mako | 4 +- templates/library/common/library_dataset_permissions.mako | 4 +- templates/library/common/library_info.mako | 6 +- templates/library/common/library_permissions.mako | 4 +- templates/library/common/new_folder.mako | 4 +- templates/library/common/select_info_template.mako | 15 +- templates/library/common/upload.mako | 12 +- test/base/twilltestcase.py | 23 +- test/functional/test_security_and_libraries.py | 29 +- 21 files changed, 555 insertions(+), 437 deletions(-) diffs (1908 lines): diff -r f1cc27efc29e -r 8b7d2cc963fd lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py Fri Jan 29 17:10:34 2010 -0500 +++ b/lib/galaxy/model/__init__.py Sat Jan 30 07:48:39 2010 -0500 @@ -954,10 +954,10 @@ return self.dataset.get_access_roles( trans ) def get_info_association( self, restrict=False, inherited=False ): # If restrict is True, we will return this ldda's info_association whether it - # exists or not. If restrict is False, we'll return the next available info_association - # in the inheritable hierarchy. True is also returned if the info_association was inherited, - # and False if not. This enables us to eliminate displaying the any contents of the inherited - # template. + # exists or not ( in which case None will be returned ). If restrict is False, + # we'll return the next available info_association in the inheritable hierarchy. + # True is also returned if the info_association was inherited, and False if not. + # This enables us to eliminate displaying any contents of the inherited template. if self.info_association: return self.info_association[0], inherited if restrict: diff -r f1cc27efc29e -r 8b7d2cc963fd lib/galaxy/model/mapping.py --- a/lib/galaxy/model/mapping.py Fri Jan 29 17:10:34 2010 -0500 +++ b/lib/galaxy/model/mapping.py Sat Jan 30 07:48:39 2010 -0500 @@ -293,19 +293,22 @@ Column( "id", Integer, primary_key=True ), Column( "library_id", Integer, ForeignKey( "library.id" ), index=True ), Column( "form_definition_id", Integer, ForeignKey( "form_definition.id" ), index=True ), - Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ) ) + Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ), + Column( "deleted", Boolean, index=True, default=False ) ) LibraryFolderInfoAssociation.table = Table( 'library_folder_info_association', metadata, Column( "id", Integer, primary_key=True ), Column( "library_folder_id", Integer, ForeignKey( "library_folder.id" ), nullable=True, index=True ), Column( "form_definition_id", Integer, ForeignKey( "form_definition.id" ), index=True ), - Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ) ) + Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ), + Column( "deleted", Boolean, index=True, default=False ) ) LibraryDatasetDatasetInfoAssociation.table = Table( 'library_dataset_dataset_info_association', metadata, Column( "id", Integer, primary_key=True ), Column( "library_dataset_dataset_association_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), nullable=True, index=True ), Column( "form_definition_id", Integer, ForeignKey( "form_definition.id" ), index=True ), - Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ) ) + Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ), + Column( "deleted", Boolean, index=True, default=False ) ) Job.table = Table( "job", metadata, Column( "id", Integer, primary_key=True ), @@ -1080,7 +1083,7 @@ assign_mapper( context, LibraryInfoAssociation, LibraryInfoAssociation.table, properties=dict( library=relation( Library, - primaryjoin=( LibraryInfoAssociation.table.c.library_id == Library.table.c.id ), backref="info_association" ), + primaryjoin=( ( LibraryInfoAssociation.table.c.library_id == Library.table.c.id ) & ( not_( LibraryInfoAssociation.table.c.deleted ) ) ), backref="info_association" ), template=relation( FormDefinition, primaryjoin=( LibraryInfoAssociation.table.c.form_definition_id == FormDefinition.table.c.id ) ), info=relation( FormValues, @@ -1108,7 +1111,7 @@ assign_mapper( context, LibraryFolderInfoAssociation, LibraryFolderInfoAssociation.table, properties=dict( folder=relation( LibraryFolder, - primaryjoin=( LibraryFolderInfoAssociation.table.c.library_folder_id == LibraryFolder.table.c.id ), backref="info_association" ), + primaryjoin=( ( LibraryFolderInfoAssociation.table.c.library_folder_id == LibraryFolder.table.c.id ) & ( not_( LibraryFolderInfoAssociation.table.c.deleted ) ) ), backref="info_association" ), template=relation( FormDefinition, primaryjoin=( LibraryFolderInfoAssociation.table.c.form_definition_id == FormDefinition.table.c.id ) ), info=relation( FormValues, @@ -1147,7 +1150,7 @@ assign_mapper( context, LibraryDatasetDatasetInfoAssociation, LibraryDatasetDatasetInfoAssociation.table, properties=dict( library_dataset_dataset_association=relation( LibraryDatasetDatasetAssociation, - primaryjoin=( LibraryDatasetDatasetInfoAssociation.table.c.library_dataset_dataset_association_id == LibraryDatasetDatasetAssociation.table.c.id ), backref="info_association" ), + primaryjoin=( ( LibraryDatasetDatasetInfoAssociation.table.c.library_dataset_dataset_association_id == LibraryDatasetDatasetAssociation.table.c.id ) & ( not_( LibraryDatasetDatasetInfoAssociation.table.c.deleted ) ) ), backref="info_association" ), template=relation( FormDefinition, primaryjoin=( LibraryDatasetDatasetInfoAssociation.table.c.form_definition_id == FormDefinition.table.c.id ) ), info=relation( FormValues, diff -r f1cc27efc29e -r 8b7d2cc963fd lib/galaxy/model/migrate/versions/0036_add_deleted_column_to_library_template_assoc_tables.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/galaxy/model/migrate/versions/0036_add_deleted_column_to_library_template_assoc_tables.py Sat Jan 30 07:48:39 2010 -0500 @@ -0,0 +1,50 @@ +""" +Migration script to add a deleted column to the following tables: +library_info_association, library_folder_info_association, library_dataset_dataset_info_association. +""" + +from sqlalchemy import * +from migrate import * +from migrate.changeset import * + +import logging +log = logging.getLogger( __name__ ) + +metadata = MetaData( migrate_engine ) + +def upgrade(): + print __doc__ + metadata.reflect() + + LibraryInfoAssociation_table = Table( "library_info_association", metadata, autoload=True ) + c = Column( "deleted", Boolean, index=True, default=False ) + c.create( LibraryInfoAssociation_table ) + assert c is LibraryInfoAssociation_table.c.deleted + cmd = "UPDATE library_info_association SET deleted = false" + try: + db_session.execute( cmd ) + except Exception, e: + log.debug( "deleted to false in library_info_association failed: %s" % ( str( e ) ) ) + + LibraryFolderInfoAssociation_table = Table( "library_folder_info_association", metadata, autoload=True ) + c = Column( "deleted", Boolean, index=True, default=False ) + c.create( LibraryFolderInfoAssociation_table ) + assert c is LibraryFolderInfoAssociation_table.c.deleted + cmd = "UPDATE library_folder_info_association SET deleted = false" + try: + db_session.execute( cmd ) + except Exception, e: + log.debug( "deleted to false in library_folder_info_association failed: %s" % ( str( e ) ) ) + + LibraryDatasetDatasetInfoAssociation_table = Table( "library_dataset_dataset_info_association", metadata, autoload=True ) + c = Column( "deleted", Boolean, index=True, default=False ) + c.create( LibraryDatasetDatasetInfoAssociation_table ) + assert c is LibraryDatasetDatasetInfoAssociation_table.c.deleted + cmd = "UPDATE library_dataset_dataset_info_association SET deleted = false" + try: + db_session.execute( cmd ) + except Exception, e: + log.debug( "deleted to false in library_dataset_dataset_info_association failed: %s" % ( str( e ) ) ) + +def downgrade(): + pass diff -r f1cc27efc29e -r 8b7d2cc963fd lib/galaxy/web/controllers/library_admin.py --- a/lib/galaxy/web/controllers/library_admin.py Fri Jan 29 17:10:34 2010 -0500 +++ b/lib/galaxy/web/controllers/library_admin.py Sat Jan 30 07:48:39 2010 -0500 @@ -171,7 +171,7 @@ status='done' ) ) @web.expose @web.require_admin - def delete_library_item( self, trans, library_id, library_item_id, library_item_type ): + def delete_library_item( self, trans, library_id, library_item_id, library_item_type, **kwd ): # This action will handle deleting all types of library items. State is saved for libraries and # folders ( i.e., if undeleted, the state of contents of the library or folder will remain, so previously # deleted / purged contents will have the same state ). When a library or folder has been deleted for @@ -179,6 +179,7 @@ # contents will be purged. The association between this method and the cleanup_datasets.py script # enables clean maintenance of libraries and library dataset disk files. This is also why the following # 3 objects, and not any of the associations ( the cleanup_datasets.py scipot handles everything else ). + show_deleted = util.string_as_bool( kwd.get( 'show_deleted', False ) ) library_item_types = { 'library': trans.app.model.Library, 'folder': trans.app.model.LibraryFolder, 'library_dataset': trans.app.model.LibraryDataset } @@ -203,12 +204,14 @@ action='browse_library', cntrller='library_admin', id=library_id, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) ) @web.expose @web.require_admin - def undelete_library_item( self, trans, library_id, library_item_id, library_item_type ): + def undelete_library_item( self, trans, library_id, library_item_id, library_item_type, **kwd ): # This action will handle undeleting all types of library items + show_deleted = util.string_as_bool( kwd.get( 'show_deleted', False ) ) library_item_types = { 'library': trans.app.model.Library, 'folder': trans.app.model.LibraryFolder, 'library_dataset': trans.app.model.LibraryDataset } @@ -237,6 +240,7 @@ action='browse_library', cntrller='library_admin', id=library_id, + show_deleted=show_deleted, msg=msg, messagetype=status ) ) @web.expose diff -r f1cc27efc29e -r 8b7d2cc963fd lib/galaxy/web/controllers/library_common.py --- a/lib/galaxy/web/controllers/library_common.py Fri Jan 29 17:10:34 2010 -0500 +++ b/lib/galaxy/web/controllers/library_common.py Sat Jan 30 07:48:39 2010 -0500 @@ -84,41 +84,39 @@ if not library_id: # To handle bots msg = "You must specify a library id." - return trans.response.send_redirect( web.url_for( controller=cntrller, - action='browse_libraries', - default_action=params.get( 'default_action', None ), - msg=util.sanitize_text( msg ), - messagetype='error' ) ) + messagetype = 'error' library = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( library_id ) ) if not library: # To handle bots msg = "Invalid library id ( %s )." % str( library_id ) - return trans.response.send_redirect( web.url_for( controller=cntrller, - action='browse_libraries', - default_action=params.get( 'default_action', None ), - msg=util.sanitize_text( msg ), - messagetype='error' ) ) - show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) - created_ldda_ids = params.get( 'created_ldda_ids', '' ) - hidden_folder_ids = util.listify( params.get( 'hidden_folder_ids', '' ) ) - current_user_roles = trans.get_current_user_roles() - if created_ldda_ids and not msg: - msg = "%d datasets are uploading in the background to the library '%s' (each is selected). " % \ - ( len( created_ldda_ids.split( ',' ) ), library.name ) - msg += "Don't navigate away from Galaxy or use the browser's \"stop\" or \"reload\" buttons (on this tab) until the " - msg += "message \"This dataset is uploading\" is cleared from the \"Information\" column below for each selected dataset." - messagetype = "info" - return trans.fill_template( '/library/common/browse_library.mako', - cntrller=cntrller, - library=library, - created_ldda_ids=created_ldda_ids, - hidden_folder_ids=hidden_folder_ids, - default_action=params.get( 'default_action', None ), - show_deleted=show_deleted, - comptypes=comptypes, - current_user_roles=current_user_roles, - msg=msg, - messagetype=messagetype ) + messagetype = 'error' + else: + show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) + created_ldda_ids = params.get( 'created_ldda_ids', '' ) + hidden_folder_ids = util.listify( params.get( 'hidden_folder_ids', '' ) ) + current_user_roles = trans.get_current_user_roles() + if created_ldda_ids and not msg: + msg = "%d datasets are uploading in the background to the library '%s' (each is selected). " % \ + ( len( created_ldda_ids.split( ',' ) ), library.name ) + msg += "Don't navigate away from Galaxy or use the browser's \"stop\" or \"reload\" buttons (on this tab) until the " + msg += "message \"This job is running\" is cleared from the \"Information\" column below for each selected dataset." + messagetype = "info" + return trans.fill_template( '/library/common/browse_library.mako', + cntrller=cntrller, + library=library, + created_ldda_ids=created_ldda_ids, + hidden_folder_ids=hidden_folder_ids, + default_action=params.get( 'default_action', None ), + show_deleted=show_deleted, + comptypes=comptypes, + current_user_roles=current_user_roles, + msg=msg, + messagetype=messagetype ) + return trans.response.send_redirect( web.url_for( controller=cntrller, + action='browse_libraries', + default_action=params.get( 'default_action', None ), + msg=util.sanitize_text( msg ), + messagetype=messagetype ) ) @web.expose def library_info( self, trans, cntrller, **kwd ): params = util.Params( kwd ) @@ -129,6 +127,7 @@ # See if we have any associated templates widgets = library.get_template_widgets( trans ) current_user_roles = trans.get_current_user_roles() + show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) if params.get( 'rename_library_button', False ): old_name = library.name new_name = util.restore_text( params.name ) @@ -149,6 +148,7 @@ action='library_info', cntrller=cntrller, id=trans.security.encode_id( library.id ), + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='done' ) ) return trans.fill_template( '/library/common/library_info.mako', @@ -156,6 +156,7 @@ library=library, widgets=widgets, current_user_roles=current_user_roles, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) @web.expose @@ -166,6 +167,7 @@ library_id = params.get( 'id', None ) library = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( library_id ) ) current_user_roles = trans.get_current_user_roles() + show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) if params.get( 'update_roles_button', False ): # The user clicked the Save button on the 'Associate With Roles' form permissions = {} @@ -181,6 +183,7 @@ action='library_permissions', cntrller=cntrller, id=trans.security.encode_id( library.id ), + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='done' ) ) roles = trans.app.security_agent.get_legitimate_roles( trans, library ) @@ -189,6 +192,7 @@ library=library, current_user_roles=current_user_roles, roles=roles, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) @web.expose @@ -196,6 +200,7 @@ params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) + show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) folder = trans.sa_session.query( trans.app.model.LibraryFolder ).get( trans.security.decode_id( parent_id ) ) if not folder: msg = "Invalid parent folder id (%s) specified" % str( parent_id ) @@ -203,6 +208,7 @@ action='browse_library', cntrller=cntrller, id=library_id, + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='error' ) ) if params.new == 'submitted': @@ -222,12 +228,14 @@ action='browse_library', cntrller=cntrller, id=library_id, + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='done' ) ) return trans.fill_template( '/library/common/new_folder.mako', cntrller=cntrller, library_id=library_id, folder=folder, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) @web.expose @@ -235,6 +243,7 @@ params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) + show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) folder = trans.sa_session.query( trans.app.model.LibraryFolder ).get( trans.security.decode_id( id ) ) current_user_roles = trans.get_current_user_roles() # See if we have any associated templates @@ -263,13 +272,15 @@ library_id=library_id, widgets=widgets, current_user_roles=current_user_roles, - msg=util.sanitize_text( msg ), + show_deleted=show_deleted, + msg=msg, messagetype=messagetype ) @web.expose def folder_permissions( self, trans, cntrller, id, library_id, **kwd ): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) + show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) folder = trans.sa_session.query( trans.app.model.LibraryFolder ).get( trans.security.decode_id( id ) ) if not folder: msg = "Invalid folder specified, id: %s" % str( id ) @@ -277,6 +288,7 @@ action='browse_library', cntrller=cntrller, id=library_id, + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='error' ) ) current_user_roles = trans.get_current_user_roles() @@ -302,6 +314,7 @@ cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=library_id, + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype=messagetype ) ) # If the library is public all roles are legitimate, but if the library is restricted, only those @@ -314,6 +327,7 @@ library_id=library_id, current_user_roles=current_user_roles, roles=roles, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) @web.expose @@ -321,6 +335,7 @@ params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) + show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) ldda = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( id ) ) if not ldda: msg = "Invalid LibraryDatasetDatasetAssociation specified, id: %s" % str( id ) @@ -328,6 +343,7 @@ action='browse_library', cntrller=cntrller, id=library_id, + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='error' ) ) dbkey = params.get( 'dbkey', '?' ) @@ -359,6 +375,7 @@ file_formats=file_formats, widgets=widgets, current_user_roles=current_user_roles, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) elif params.get( 'save', False ): @@ -400,6 +417,7 @@ file_formats=file_formats, widgets=widgets, current_user_roles=current_user_roles, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) elif params.get( 'detect', False ): @@ -425,6 +443,7 @@ file_formats=file_formats, widgets=widgets, current_user_roles=current_user_roles, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) if cntrller=='library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, ldda ): @@ -442,6 +461,7 @@ file_formats=file_formats, widgets=widgets, current_user_roles=current_user_roles, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) @web.expose @@ -457,6 +477,7 @@ action='browse_library', cntrller=cntrller, id=library_id, + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='error' ) ) library = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( library_id ) ) @@ -470,6 +491,7 @@ show_deleted=show_deleted, widgets=widgets, current_user_roles=current_user_roles, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) @web.expose @@ -477,6 +499,7 @@ params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) + show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) ids = util.listify( id ) lddas = [] for id in [ trans.security.decode_id( id ) for id in ids ]: @@ -487,6 +510,7 @@ action='browse_library', cntrller=cntrller, id=library_id, + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='error' ) ) lddas.append( ldda ) @@ -544,6 +568,7 @@ lddas=lddas, library_id=library_id, roles=roles, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) if len( ids ) > 1: @@ -568,6 +593,7 @@ action='browse_library', cntrller=cntrller, id=library_id, + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='error' ) ) # Display permission form, permissions will be updated for all lddas simultaneously. @@ -576,6 +602,7 @@ lddas=lddas, library_id=library_id, roles=roles, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) @web.expose @@ -674,7 +701,8 @@ cntrller=cntrller, id=library_id, default_action=default_action, - created_ldda_ids=",".join( ldda_id_list ), + created_ldda_ids=",".join( ldda_id_list ), + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='done' ) ) @@ -686,6 +714,7 @@ cntrller=cntrller, id=library_id, created_ldda_ids=",".join( [ str( v.id ) for v in created_outputs.values() ] ), + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype=messagetype ) ) # See if we have any inherited templates, but do not inherit contents. @@ -708,7 +737,7 @@ history = trans.get_history() trans.sa_session.refresh( history ) # If we're using nginx upload, override the form action - action = web.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller ) + action = web.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, show_deleted=show_deleted ) if upload_option == 'upload_file' and trans.app.config.nginx_upload_path: # url_for is intentionally not used on the base URL here - # nginx_upload_path is expected to include the proxy prefix if the @@ -731,6 +760,7 @@ roles=roles, history=history, widgets=widgets, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) def upload_dataset( self, trans, cntrller, library_id, folder_id, replace_dataset=None, **kwd ): @@ -884,18 +914,10 @@ @web.expose def add_history_datasets_to_library( self, trans, cntrller, library_id, folder_id, hda_ids='', **kwd ): params = util.Params( kwd ) + show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) - try: - folder = trans.sa_session.query( trans.app.model.LibraryFolder ).get( trans.security.decode_id( folder_id ) ) - except: - msg = "Invalid folder id: %s" % str( folder_id ) - return trans.response.send_redirect( web.url_for( controller='library_common', - action='browse_library', - cntrller=cntrller, - id=library_id, - msg=util.sanitize_text( msg ), - messagetype='error' ) ) + folder = trans.sa_session.query( trans.app.model.LibraryFolder ).get( trans.security.decode_id( folder_id ) ) replace_id = params.get( 'replace_id', None ) if replace_id: replace_dataset = trans.sa_session.query( trans.app.model.LibraryDataset ).get( trans.security.decode_id( replace_id ) ) @@ -910,6 +932,7 @@ action='browse_library', cntrller=cntrller, id=library_id, + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='error' ) ) if params.get( 'add_history_datasets_to_library_button', False ): @@ -936,6 +959,7 @@ action='browse_library', cntrller=cntrller, id=library_id, + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='error' ) ) if created_ldda_ids: @@ -970,6 +994,7 @@ cntrller=cntrller, id=library_id, created_ldda_ids=created_ldda_ids, + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='done' ) ) else: @@ -998,44 +1023,43 @@ roles=roles, history=history, widgets=[], + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) @web.expose def download_dataset_from_folder( self, trans, cntrller, id, library_id=None, **kwd ): """Catches the dataset id and displays file contents as directed""" - # id must refer to a LibraryDatasetDatasetAssociation object - ldda = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( id ) + show_deleted = util.string_as_bool( kwd.get( 'show_deleted', False ) ) + ldda = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( id ) ) if not ldda.dataset: msg = 'Invalid LibraryDatasetDatasetAssociation id %s received for file downlaod' % str( id ) - return trans.response.send_redirect( web.url_for( controller='library_common', - action='browse_library', - cntrller=cntrller, - id=library_id, - msg=util.sanitize_text( msg ), - messagetype='error' ) ) - mime = trans.app.datatypes_registry.get_mimetype_by_extension( ldda.extension.lower() ) - trans.response.set_content_type( mime ) - fStat = os.stat( ldda.file_name ) - trans.response.headers[ 'Content-Length' ] = int( fStat.st_size ) - valid_chars = '.,^_-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' - fname = ldda.name - fname = ''.join( c in valid_chars and c or '_' for c in fname )[ 0:150 ] - trans.response.headers[ "Content-Disposition" ] = "attachment; filename=GalaxyLibraryDataset-%s-[%s]" % ( str( id ), fname ) - try: - return open( ldda.file_name ) - except: - msg = 'This dataset contains no content' - return trans.response.send_redirect( web.url_for( controller='library_common', - action='browse_library', - cntrller=cntrller, - id=library_id, - msg=util.sanitize_text( msg ), - messagetype='error' ) ) + messagetype = 'error' + else: + mime = trans.app.datatypes_registry.get_mimetype_by_extension( ldda.extension.lower() ) + trans.response.set_content_type( mime ) + fStat = os.stat( ldda.file_name ) + trans.response.headers[ 'Content-Length' ] = int( fStat.st_size ) + valid_chars = '.,^_-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + fname = ldda.name + fname = ''.join( c in valid_chars and c or '_' for c in fname )[ 0:150 ] + trans.response.headers[ "Content-Disposition" ] = "attachment; filename=GalaxyLibraryDataset-%s-[%s]" % ( str( id ), fname ) + try: + return open( ldda.file_name ) + except: + msg = 'This dataset contains no content' + return trans.response.send_redirect( web.url_for( controller='library_common', + action='browse_library', + cntrller=cntrller, + id=library_id, + show_deleted=show_deleted, + msg=util.sanitize_text( msg ), + messagetype='error' ) ) @web.expose def library_dataset_info( self, trans, cntrller, id, library_id, **kwd ): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) + show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) library_dataset = trans.sa_session.query( trans.app.model.LibraryDataset ).get( trans.security.decode_id( id ) ) if not library_dataset: msg = "Invalid library dataset specified, id: %s" %str( id ) @@ -1043,6 +1067,7 @@ action='browse_library', cntrller=cntrller, id=library_id, + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='error' ) ) current_user_roles = trans.get_current_user_roles() @@ -1070,6 +1095,7 @@ library_dataset=library_dataset, library_id=library_id, current_user_roles=current_user_roles, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) @web.expose @@ -1077,6 +1103,7 @@ params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) + show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) library_dataset = trans.sa_session.query( trans.app.model.LibraryDataset ).get( id ) if not library_dataset: msg = "Invalid library dataset specified, id: %s" %str( id ) @@ -1084,6 +1111,7 @@ action='browse_library', cntrller=cntrller, id=library_id, + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='error' ) ) current_user_roles = trans.get_current_user_roles() @@ -1117,6 +1145,7 @@ library_id=library_id, roles=roles, current_user_roles=current_user_roles, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) @web.expose @@ -1126,176 +1155,135 @@ params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) + show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) if not ldda_ids: msg = "You must select at least one dataset" - return trans.response.send_redirect( web.url_for( controller='library_common', - action='browse_library', - cntrller=cntrller, - id=library_id, - msg=util.sanitize_text( msg ), - messagetype='error' ) ) - if not params.do_action: + messagetype = 'error' + elif not params.do_action: msg = "You must select an action to perform on selected datasets" - return trans.response.send_redirect( web.url_for( controller='library_common', - action='browse_library', - cntrller=cntrller, - id=library_id, - msg=util.sanitize_text( msg ), - messagetype='error' ) ) - ldda_ids = util.listify( ldda_ids ) - if params.do_action == 'add': - history = trans.get_history() - total_imported_lddas = 0 - msg = '' - messagetype = 'done' - for ldda_id in ldda_ids: - ldda = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( ldda_id ) ) - if ldda.dataset.state in [ 'new', 'upload', 'queued', 'running', 'empty', 'discarded' ]: - msg += "Cannot import dataset (%s) since it's state is (%s). " % ( ldda.name, ldda.dataset.state ) + messagetype = 'error' + else: + ldda_ids = util.listify( ldda_ids ) + if params.do_action == 'add': + history = trans.get_history() + total_imported_lddas = 0 + msg = '' + messagetype = 'done' + for ldda_id in ldda_ids: + ldda = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( ldda_id ) ) + if ldda.dataset.state in [ 'new', 'upload', 'queued', 'running', 'empty', 'discarded' ]: + msg += "Cannot import dataset (%s) since it's state is (%s). " % ( ldda.name, ldda.dataset.state ) + messagetype = 'error' + elif ldda.dataset.state in [ 'ok', 'error' ]: + hda = ldda.to_history_dataset_association( target_history=history, add_to_history=True ) + total_imported_lddas += 1 + if total_imported_lddas: + trans.sa_session.add( history ) + trans.sa_session.flush() + msg += "%i dataset(s) have been imported into your history. " % total_imported_lddas + elif params.do_action == 'manage_permissions': + # We need the folder containing the LibraryDatasetDatasetAssociation(s) + ldda = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( ldda_ids[0] ) ) + trans.response.send_redirect( web.url_for( controller='library_common', + action='ldda_permissions', + cntrller=cntrller, + library_id=library_id, + folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), + id=",".join( ldda_ids ), + show_deleted=show_deleted, + msg=util.sanitize_text( msg ), + messagetype=messagetype ) ) + elif params.do_action == 'delete': + for ldda_id in ldda_ids: + ldda = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( ldda_id ) ) + ldda.deleted = True + trans.sa_session.add( ldda ) + trans.sa_session.flush() + msg = "The selected datasets have been removed from this data library" + else: + error = False + try: + if params.do_action == 'zip': + # Can't use mkstemp - the file must not exist first + tmpd = tempfile.mkdtemp() + tmpf = os.path.join( tmpd, 'library_download.' + params.do_action ) + if ziptype == '64': + archive = zipfile.ZipFile( tmpf, 'w', zipfile.ZIP_DEFLATED, True ) + else: + archive = zipfile.ZipFile( tmpf, 'w', zipfile.ZIP_DEFLATED ) + archive.add = lambda x, y: archive.write( x, y.encode('CP437') ) + elif params.do_action == 'tgz': + archive = util.streamball.StreamBall( 'w|gz' ) + elif params.do_action == 'tbz': + archive = util.streamball.StreamBall( 'w|bz2' ) + except (OSError, zipfile.BadZipFile): + error = True + log.exception( "Unable to create archive for download" ) + msg = "Unable to create archive for download, please report this error" messagetype = 'error' - elif ldda.dataset.state in [ 'ok', 'error' ]: - hda = ldda.to_history_dataset_association( target_history=history, add_to_history=True ) - total_imported_lddas += 1 - if total_imported_lddas: - trans.sa_session.add( history ) - trans.sa_session.flush() - msg += "%i dataset(s) have been imported into your history. " % total_imported_lddas - return trans.response.send_redirect( web.url_for( controller='library_common', - action='browse_library', - cntrller=cntrller, - id=library_id, - msg=util.sanitize_text( msg ), - messagetype=messagetype ) ) - elif params.do_action == 'manage_permissions': - # We need the folder containing the LibraryDatasetDatasetAssociation(s) - ldda = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( ldda_ids[0] ) ) - trans.response.send_redirect( web.url_for( controller='library_common', - action='ldda_permissions', - cntrller=cntrller, - library_id=library_id, - folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), - id=",".join( ldda_ids ), - msg=util.sanitize_text( msg ), - messagetype=messagetype ) ) - elif params.do_action == 'delete': - for ldda_id in ldda_ids: - ldda = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( ldda_id ) ) - ldda.deleted = True - trans.sa_session.add( ldda ) - trans.sa_session.flush() - msg = "The selected datasets have been removed from this data library" - trans.response.send_redirect( web.url_for( controller='library_common', - action='browse_library', - cntrller=cntrller, - id=library_id, - show_deleted=False, - msg=util.sanitize_text( msg ), - messagetype='done' ) ) - else: - try: - if params.do_action == 'zip': - # Can't use mkstemp - the file must not exist first - tmpd = tempfile.mkdtemp() - tmpf = os.path.join( tmpd, 'library_download.' + params.do_action ) - if ziptype == '64': - archive = zipfile.ZipFile( tmpf, 'w', zipfile.ZIP_DEFLATED, True ) - else: - archive = zipfile.ZipFile( tmpf, 'w', zipfile.ZIP_DEFLATED ) - archive.add = lambda x, y: archive.write( x, y.encode('CP437') ) - elif params.do_action == 'tgz': - archive = util.streamball.StreamBall( 'w|gz' ) - elif params.do_action == 'tbz': - archive = util.streamball.StreamBall( 'w|bz2' ) - except (OSError, zipfile.BadZipFile): - log.exception( "Unable to create archive for download" ) - msg = "Unable to create archive for download, please report this error" - return trans.response.send_redirect( web.url_for( controller='library_common', - action='browse_library', - cntrller=cntrller, - id=library_id, - msg=util.sanitize_text( msg ), - messagetype='error' ) ) - seen = [] - current_user_roles = trans.get_current_user_roles() - for ldda_id in ldda_ids: - ldda = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( ldda_id ) ) - if not ldda \ - or not trans.app.security_agent.can_access_dataset( current_user_roles, ldda.dataset ) \ - or ldda.dataset.state in [ 'new', 'upload', 'queued', 'running', 'empty', 'discarded' ]: - continue - path = "" - parent_folder = ldda.library_dataset.folder - while parent_folder is not None: - # Exclude the now-hidden "root folder" - if parent_folder.parent is None: - path = os.path.join( parent_folder.library_root[0].name, path ) - break - path = os.path.join( parent_folder.name, path ) - parent_folder = parent_folder.parent - path += ldda.name - while path in seen: - path += '_' - seen.append( path ) - try: - archive.add( ldda.dataset.file_name, path ) - except IOError: - log.exception( "Unable to write to temporary library download archive" ) - msg = "Unable to create archive for download, please report this error" - return trans.response.send_redirect( web.url_for( controller='library_common', - action='browse_library', - cntrller=cntrller, - id=library_id, - msg=util.sanitize_text( msg ), - messagetype='error' ) ) - if params.do_action == 'zip': - archive.close() - tmpfh = open( tmpf ) - # clean up now - try: - os.unlink( tmpf ) - os.rmdir( tmpd ) - except OSError: - log.exception( "Unable to remove temporary library download archive and directory" ) - msg = "Unable to create archive for download, please report this error" - return trans.response.send_redirect( web.url_for( controller='library_common', - action='browse_library', - cntrller=cntrller, - id=library_id, - msg=util.sanitize_text( msg ), - messagetype='error' ) ) - trans.response.set_content_type( "application/x-zip-compressed" ) - trans.response.headers[ "Content-Disposition" ] = "attachment; filename=GalaxyLibraryFiles.%s" % params.do_action - return tmpfh - else: - trans.response.set_content_type( "application/x-tar" ) - trans.response.headers[ "Content-Disposition" ] = "attachment; filename=GalaxyLibraryFiles.%s" % params.do_action - archive.wsgi_status = trans.response.wsgi_status() - archive.wsgi_headeritems = trans.response.wsgi_headeritems() - return archive.stream + if not error: + seen = [] + current_user_roles = trans.get_current_user_roles() + for ldda_id in ldda_ids: + ldda = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( ldda_id ) ) + if not ldda \ + or not trans.app.security_agent.can_access_dataset( current_user_roles, ldda.dataset ) \ + or ldda.dataset.state in [ 'new', 'upload', 'queued', 'running', 'empty', 'discarded' ]: + continue + path = "" + parent_folder = ldda.library_dataset.folder + while parent_folder is not None: + # Exclude the now-hidden "root folder" + if parent_folder.parent is None: + path = os.path.join( parent_folder.library_root[0].name, path ) + break + path = os.path.join( parent_folder.name, path ) + parent_folder = parent_folder.parent + path += ldda.name + while path in seen: + path += '_' + seen.append( path ) + try: + archive.add( ldda.dataset.file_name, path ) + except IOError: + error = True + log.exception( "Unable to write to temporary library download archive" ) + msg = "Unable to create archive for download, please report this error" + messagetype = 'error' + if not error: + if params.do_action == 'zip': + archive.close() + tmpfh = open( tmpf ) + # clean up now + try: + os.unlink( tmpf ) + os.rmdir( tmpd ) + except OSError: + error = True + log.exception( "Unable to remove temporary library download archive and directory" ) + msg = "Unable to create archive for download, please report this error" + messagetype = 'error' + if not error: + trans.response.set_content_type( "application/x-zip-compressed" ) + trans.response.headers[ "Content-Disposition" ] = "attachment; filename=GalaxyLibraryFiles.%s" % params.do_action + return tmpfh + else: + trans.response.set_content_type( "application/x-tar" ) + trans.response.headers[ "Content-Disposition" ] = "attachment; filename=GalaxyLibraryFiles.%s" % params.do_action + archive.wsgi_status = trans.response.wsgi_status() + archive.wsgi_headeritems = trans.response.wsgi_headeritems() + return archive.stream + return trans.response.send_redirect( web.url_for( controller='library_common', + action='browse_library', + cntrller=cntrller, + id=library_id, + show_deleted=show_deleted, + msg=util.sanitize_text( msg ), + messagetype=messagetype ) ) @web.expose - def info_template( self, trans, cntrller, library_id, response_action='library_info', id=None, folder_id=None, ldda_id=None, **kwd ): - # Only adding a new template to a library or folder is currently allowed. Editing an existing template is - # a future enhancement. The response_action param is the name of the method to which this method will redirect - # if a new template is being added to a library or folder. - params = util.Params( kwd ) - msg = util.restore_text( params.get( 'msg', '' ) ) - messagetype = params.get( 'messagetype', 'done' ) - if id: - library_item = trans.sa_session.query( trans.app.model.FormDefinition ).get( int( id ) ) - library_item_desc = 'information template' - response_id = id - elif folder_id: - library_item = trans.sa_session.query( trans.app.model.LibraryFolder ).get( trans.security.decode_id( folder_id ) ) - library_item_desc = 'folder' - response_id = folder_id - elif ldda_id: - library_item = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( ldda_id ) ) - library_item_desc = 'library dataset' - response_id = ldda_id - else: - library_item = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( library_id ) ) - library_item_desc = 'library' - response_id = library_id + def add_info_template( self, trans, cntrller, item_type, library_id, folder_id=None, ldda_id=None, **kwd ): + # Only adding a new template to a Library, Folder or LibraryDatasetDatasetAssociation is currently allowed. Editing an existing + # template is a future enhancement. forms = get_all_forms( trans, filter=dict( deleted=False ), form_type=trans.app.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE ) @@ -1307,65 +1295,88 @@ msg=msg, messagetype='done', form_type=trans.app.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE ) ) + params = util.Params( kwd ) + show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) + msg = util.restore_text( params.get( 'msg', '' ) ) + action = '' + messagetype = params.get( 'messagetype', 'done' ) + if item_type == 'library': + item = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( library_id ) ) + library_item_desc = 'data library' + action = 'library_info' + id = library_id + elif item_type == 'folder': + item = trans.sa_session.query( trans.app.model.LibraryFolder ).get( trans.security.decode_id( folder_id ) ) + library_item_desc = 'folder' + action = 'folder_info' + id = folder_id + elif item_type == 'ldda': + item = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( ldda_id ) ) + library_item_desc = 'dataset' + action = 'ldda_edit_info' + id = ldda_id if params.get( 'add_info_template_button', False ): - form_id = params.get( 'form_id', None ) - # TODO: add error handling here - form = trans.sa_session.query( trans.app.model.FormDefinition ).get( int( form_id ) ) - #fields = list( copy.deepcopy( form.fields ) ) + form = trans.sa_session.query( trans.app.model.FormDefinition ).get( int( params.form_id ) ) form_values = trans.app.model.FormValues( form, [] ) trans.sa_session.add( form_values ) trans.sa_session.flush() - if folder_id: - assoc = trans.app.model.LibraryFolderInfoAssociation( library_item, form, form_values ) - elif ldda_id: - assoc = trans.app.model.LibraryDatasetDatasetInfoAssociation( library_item, form, form_values ) - else: - assoc = trans.app.model.LibraryInfoAssociation( library_item, form, form_values ) + if item_type == 'library': + assoc = trans.app.model.LibraryInfoAssociation( item, form, form_values ) + elif item_type == 'folder': + assoc = trans.app.model.LibraryFolderInfoAssociation( item, form, form_values ) + elif item_type == 'ldda': + assoc = trans.app.model.LibraryDatasetDatasetInfoAssociation( item, form, form_values ) trans.sa_session.add( assoc ) trans.sa_session.flush() msg = 'An information template based on the form "%s" has been added to this %s.' % ( form.name, library_item_desc ) trans.response.send_redirect( web.url_for( controller='library_common', - action=response_action, + action=action, cntrller=cntrller, - id=response_id, library_id=library_id, + folder_id=folder_id, + id=id, + show_deleted=show_deleted, msg=msg, messagetype='done' ) ) return trans.fill_template( '/library/common/select_info_template.mako', cntrller=cntrller, - library_item_name=library_item.name, + library_item_name=item.name, library_item_desc=library_item_desc, library_id=library_id, + item_type=item_type, + library_id=library_id, folder_id=folder_id, ldda_id=ldda_id, - id=response_id, forms=forms, + show_deleted=show_deleted, msg=msg, messagetype=messagetype ) @web.expose - def edit_template_info( self, trans, cntrller, library_id, response_action, num_widgets, library_item_id=None, library_item_type=None, **kwd ): + def edit_template_info( self, trans, cntrller, item_type, library_id, num_widgets, folder_id=None, ldda_id=None, **kwd ): params = util.Params( kwd ) + show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) - folder_id = None - if library_item_type == 'library': - library_item = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( library_id ) ) - # Make sure library_item_id is encoded if we have a library - library_item_id = library_id - elif library_item_type == 'library_dataset': - library_item = trans.sa_session.query( trans.app.model.LibraryDataset ).get( trans.security.decode_id( library_item_id ) ) - elif library_item_type == 'folder': - library_item = trans.sa_session.query( trans.app.model.LibraryFolder ).get( trans.security.decode_id( library_item_id ) ) - elif library_item_type == 'library_dataset_dataset_association': - library_item = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( library_item_id ) ) - # This response_action method requires a folder_id - folder_id = trans.security.encode_id( library_item.library_dataset.folder.id ) + if item_type == 'library': + item = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( library_id ) ) + action = 'library_info' + id = library_id + elif item_type == 'folder': + item = trans.sa_session.query( trans.app.model.LibraryFolder ).get( trans.security.decode_id( folder_id ) ) + action = 'folder_info' + id = folder_id + elif item_type == 'ldda': + item = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( ldda_id ) ) + action = 'ldda_edit_info' + folder_id = trans.security.encode_id( item.library_dataset.folder.id ) + id = ldda_id else: - msg = "Invalid library item type ( %s ) specified, id ( %s )" % ( str( library_item_type ), str( trans.security.decode_id( library_item_id ) ) ) + msg = "Invalid library item type ( %s ) sent to edit_template_info()" % str( item_type ) return trans.response.send_redirect( web.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id, + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='error' ) ) # Save updated template field contents @@ -1374,11 +1385,11 @@ field_contents.append( util.restore_text( params.get( 'field_%i' % ( index ), '' ) ) ) if field_contents: # Since information templates are inherited, the template fields can be displayed on the information - # page for a folder or library dataset when it has no info_association object. If the user has added + # page for a folder or ldda when it has no info_association object. If the user has added # field contents on an inherited template via a parent's info_association, we'll need to create a new # form_values and info_association for the current object. The value for the returned inherited variable # is not applicable at this level. - info_association, inherited = library_item.get_info_association( restrict=True ) + info_association, inherited = item.get_info_association( restrict=True ) if info_association: template = info_association.template info = info_association.info @@ -1390,30 +1401,80 @@ trans.sa_session.flush() else: # Inherit the next available info_association so we can get the template - info_association, inherited = library_item.get_info_association() + info_association, inherited = item.get_info_association() template = info_association.template # Create a new FormValues object form_values = trans.app.model.FormValues( template, field_contents ) trans.sa_session.add( form_values ) trans.sa_session.flush() # Create a new info_association between the current library item and form_values - if library_item_type == 'folder': - info_association = trans.app.model.LibraryFolderInfoAssociation( library_item, template, form_values ) + if item_type == 'folder': + info_association = trans.app.model.LibraryFolderInfoAssociation( item, template, form_values ) trans.sa_session.add( info_association ) trans.sa_session.flush() - elif library_item_type == 'library_dataset_dataset_association': - info_association = trans.app.model.LibraryDatasetDatasetInfoAssociation( library_item, template, form_values ) + elif item_type == 'ldda': + info_association = trans.app.model.LibraryDatasetDatasetInfoAssociation( item, template, form_values ) trans.sa_session.add( info_association ) trans.sa_session.flush() msg = 'The information has been updated.' return trans.response.send_redirect( web.url_for( controller='library_common', - action=response_action, + action=action, cntrller=cntrller, library_id=library_id, folder_id=folder_id, - id=library_item_id, + id=id, + show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='done' ) ) + @web.expose + def delete_info_template( self, trans, cntrller, item_type, library_id, id=None, folder_id=None, ldda_id=None, **kwd ): + # Only adding a new template to a library or folder is currently allowed. Editing an existing template is + # a future enhancement. + params = util.Params( kwd ) + show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) ) + msg = util.restore_text( params.get( 'msg', '' ) ) + messagetype = params.get( 'messagetype', 'done' ) + if item_type == 'library': + item = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( library_id ) ) + action = 'library_info' + id = library_id + elif item_type == 'folder': + item = trans.sa_session.query( trans.app.model.LibraryFolder ).get( trans.security.decode_id( folder_id ) ) + action = 'folder_info' + id = folder_id + elif item_type == 'ldda': + item = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( ldda_id ) ) + action = 'ldda_edit_info' + folder_id = trans.security.encode_id( item.library_dataset.folder.id ) + id = ldda_id + else: + msg = "Invalid library item type ( %s ) sent to edit_template_info()" % str( item_type ) + return trans.response.send_redirect( web.url_for( controller='library_common', + action='browse_library', + cntrller=cntrller, + id=library_id, + show_deleted=show_deleted, + msg=util.sanitize_text( msg ), + messagetype='error' ) ) + info_association, inherited = item.get_info_association() + if not info_association: + msg = "There is no template for this %s" % item_type + messagetype = 'error' + else: + info_association.deleted = True + trans.sa_session.add( info_association ) + trans.sa_session.flush() + msg = 'The template for this %s has been deleted.' % item_type + messagetype = 'done' + return trans.response.send_redirect( web.url_for( controller='library_common', + action=action, + cntrller=cntrller, + library_id=library_id, + folder_id=folder_id, + id=id, + show_deleted=show_deleted, + msg=util.sanitize_text( msg ), + messagetype=messagetype ) ) # ---- Utility methods ------------------------------------------------------- @@ -1452,3 +1513,10 @@ .order_by( trans.app.model.LibraryDatasetDatasetAssociation.table.c.name ) \ .all() return folders, lddas +def branch_deleted( folder ): + # Return True if a folder belongs to a branc that has been deleted + if folder.deleted: + return True + if folder.parent: + return branch_deleted( folder.parent ) + return False diff -r f1cc27efc29e -r 8b7d2cc963fd templates/library/common/browse_library.mako --- a/templates/library/common/browse_library.mako Fri Jan 29 17:10:34 2010 -0500 +++ b/templates/library/common/browse_library.mako Sat Jan 30 07:48:39 2010 -0500 @@ -4,7 +4,7 @@ <%namespace file="/library/common/common.mako" import="render_actions_on_multiple_items" /> <% from galaxy import util - from galaxy.web.controllers.library_common import active_folders, active_folders_and_lddas, activatable_folders_and_lddas + from galaxy.web.controllers.library_common import active_folders, active_folders_and_lddas, activatable_folders_and_lddas, branch_deleted from time import strftime %> @@ -21,8 +21,7 @@ info_association, inherited = library.get_info_association() can_modify = trans.app.security_agent.can_modify_library_item( current_user_roles, library ) can_manage = trans.app.security_agent.can_manage_library_item( current_user_roles, library ) - elif cntrller in [ 'library_admin', 'requests_admin' ]: - info_association, inherited = library.get_info_association() + info_association, inherited = library.get_info_association() tracked_datasets = {} @@ -167,8 +166,9 @@ current_version = False if current_version and ldda.state not in ( 'ok', 'error', 'empty', 'deleted', 'discarded' ): tracked_datasets[ldda.id] = ldda.state + info_association, inherited = ldda.get_info_association( restrict=True ) %> - %if current_version: + %if current_version and ( not ldda.library_dataset.deleted or show_deleted ): <tr class="datasetRow" %if parent is not None: parent="${parent}" @@ -181,29 +181,41 @@ %else: <input type="checkbox" name="ldda_ids" value="${trans.security.encode_id( ldda.id )}"/> %endif - <a href="${h.url_for( controller='library_common', action='ldda_display_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ) )}"><b>${ldda.name[:50]}</b></a> + %if ldda.library_dataset.deleted: + <span class="libraryItem-error"> + %endif + <a href="${h.url_for( controller='library_common', action='ldda_display_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ), show_deleted=show_deleted )}"><b>${ldda.name[:50]}</b></a> + %if ldda.library_dataset.deleted: + </span> + %endif <a id="dataset-${ldda.id}-popup" class="popup-arrow" style="display: none;">▼</a> <div popupmenu="dataset-${ldda.id}-popup"> - %if cntrller in [ 'library_admin', 'requests_admin' ] or can_modify_library_dataset: - <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_edit_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ) )}">Edit this dataset's information</a> + %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and ( cntrller in [ 'library_admin', 'requests_admin' ] or can_modify_library_dataset ): + <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_edit_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ), show_deleted=show_deleted )}">Edit this dataset's information</a> %else: - <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_display_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ) )}">View this dataset's information</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_display_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ), show_deleted=show_deleted )}">View this dataset's information</a> %endif - %if cntrller in [ 'library_admin', 'requests_admin' ] or can_manage_library_dataset: - <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_permissions', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ) )}">Edit this dataset's permissions</a> + %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and ( ( cntrller in [ 'library_admin', 'requests_admin' ] or can_add ) and not info_association ): + <a class="action-button" href="${h.url_for( controller='library_common', action='add_info_template', cntrller=cntrller, item_type='ldda', library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), ldda_id=trans.security.encode_id( ldda.id ), show_deleted=show_deleted )}">Add template to this dataset</a> %endif - %if cntrller in [ 'library_admin', 'requests_admin' ] or can_modify_library_dataset: - <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), replace_id=trans.security.encode_id( library_dataset.id ) )}">Upload a new version of this dataset</a> + %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and cntrller == 'library_admin' and info_association: + <a class="action-button" href="${h.url_for( controller='library_common', action='delete_info_template', cntrller=cntrller, item_type='ldda', library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), ldda_id=trans.security.encode_id( ldda.id ), show_deleted=show_deleted )}">Delete this dataset's template</a> %endif - %if ldda.has_data: - <a class="action-button" href="${h.url_for( controller='library_common', action='act_on_multiple_datasets', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), ldda_ids=trans.security.encode_id( ldda.id ), do_action='add' )}">Import this dataset into your current history</a> + %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and ( cntrller in [ 'library_admin', 'requests_admin' ] or can_manage_library_dataset ): + <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_permissions', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ), show_deleted=show_deleted )}">Edit this dataset's permissions</a> + %endif + %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and ( cntrller in [ 'library_admin', 'requests_admin' ] or can_modify_library_dataset ): + <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), replace_id=trans.security.encode_id( library_dataset.id ), show_deleted=show_deleted )}">Upload a new version of this dataset</a> + %endif + %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and ldda.has_data: + <a class="action-button" href="${h.url_for( controller='library_common', action='act_on_multiple_datasets', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), ldda_ids=trans.security.encode_id( ldda.id ), do_action='add', show_deleted=show_deleted )}">Import this dataset into your current history</a> <a class="action-button" href="${h.url_for( controller='library_common', action='download_dataset_from_folder', cntrller=cntrller, id=trans.security.encode_id( ldda.id ), library_id=trans.security.encode_id( library.id ) )}">Download this dataset</a> %endif %if cntrller in [ 'library_admin', 'requests_admin' ]: - %if not library.deleted and not folder.deleted and not library_dataset.deleted: - <a class="action-button" confirm="Click OK to delete dataset '${ldda.name}'." href="${h.url_for( controller='library_admin', action='delete_library_item', library_id=trans.security.encode_id( library.id ), library_item_id=trans.security.encode_id( library_dataset.id ), library_item_type='library_dataset' )}">Delete this dataset</a> - %elif not library.deleted and not folder.deleted and library_dataset.deleted: - <a class="action-button" href="${h.url_for( controller='library_admin', action='undelete_library_item', library_id=trans.security.encode_id( library.id ), library_item_id=trans.security.encode_id( library_dataset.id ), library_item_type='library_dataset' )}">Undelete this dataset</a> + %if not library.deleted and not branch_deleted( folder ) and not ldda.library_dataset.deleted: + <a class="action-button" confirm="Click OK to delete dataset '${ldda.name}'." href="${h.url_for( controller='library_admin', action='delete_library_item', library_id=trans.security.encode_id( library.id ), library_item_id=trans.security.encode_id( library_dataset.id ), library_item_type='library_dataset', show_deleted=show_deleted )}">Delete this dataset</a> + %elif not library.deleted and not branch_deleted( folder ) and not ldda.library_dataset.purged and ldda.library_dataset.deleted: + <a class="action-button" href="${h.url_for( controller='library_admin', action='undelete_library_item', library_id=trans.security.encode_id( library.id ), library_item_id=trans.security.encode_id( library_dataset.id ), library_item_type='library_dataset', show_deleted=show_deleted )}">Undelete this dataset</a> %endif %endif </div> @@ -247,14 +259,11 @@ if not can_show: return "" can_add = trans.app.security_agent.can_add_library_item( current_user_roles, folder ) - if can_add: - info_association, inherited = folder.get_info_association( restrict=True ) can_modify = trans.app.security_agent.can_modify_library_item( current_user_roles, folder ) can_manage = trans.app.security_agent.can_manage_library_item( current_user_roles, folder ) - elif cntrller in [ 'library_admin', 'requests_admin' ]: - info_association, inherited = folder.get_info_association( restrict=True ) + info_association, inherited = folder.get_info_association( restrict=True ) %> - %if not root_folder: + %if not root_folder and ( not folder.deleted or show_deleted ): <tr class="folderRow libraryOrFolderRow" %if parent is not None: parent="${parent}" @@ -265,32 +274,39 @@ <span class="expandLink"></span> <input type="checkbox" class="folderCheckbox"/> <span class="rowIcon"></span> + %if folder.deleted: + <span class="libraryItem-error"> + %endif ${folder.name} %if folder.description: <i>- ${folder.description}</i> %endif + %if folder.deleted: + </span> + %endif <a id="folder_img-${folder.id}-popup" class="popup-arrow" style="display: none;">▼</a> <div popupmenu="folder_img-${folder.id}-popup"> - %if cntrller in [ 'library_admin', 'requests_admin' ] or can_add: - <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=library_id, folder_id=trans.security.encode_id( folder.id ) )}">Add datasets to this folder</a> + %if not branch_deleted( folder ) and ( cntrller in [ 'library_admin', 'requests_admin' ] or can_add ): + <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=library_id, folder_id=trans.security.encode_id( folder.id ), show_deleted=show_deleted )}">Add datasets to this folder</a> <a class="action-button" href="${h.url_for( controller='library_common', action='create_folder', cntrller=cntrller, parent_id=trans.security.encode_id( folder.id ), library_id=library_id )}">Create a new sub-folder in this folder</a> %endif - %if cntrller in [ 'library_admin', 'requests_admin' ] or can_modify: - <a class="action-button" href="${h.url_for( controller='library_common', action='folder_info', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=library_id )}">Edit this folder's information</a> - %else: - <a class="action-button" href="${h.url_for( controller='library_common', action='folder_info', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=library_id )}">View this folder's information</a> + %if not branch_deleted( folder ) and ( cntrller in [ 'library_admin', 'requests_admin' ] or can_modify ): + <a class="action-button" href="${h.url_for( controller='library_common', action='folder_info', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=library_id, show_deleted=show_deleted )}">Edit this folder's information</a> %endif - %if ( cntrller in [ 'library_admin', 'requests_admin' ] or can_add ) and not info_association: - <a class="action-button" href="${h.url_for( controller='library_common', action='info_template', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), response_action='folder_info', folder_id=trans.security.encode_id( folder.id ) )}">Add an information template to this folder</a> + %if not branch_deleted( folder ) and ( ( cntrller in [ 'library_admin', 'requests_admin' ] or can_add ) and not info_association ): + <a class="action-button" href="${h.url_for( controller='library_common', action='add_info_template', cntrller=cntrller, item_type='folder', library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), show_deleted=show_deleted )}">Add template to this folder</a> %endif - %if cntrller in [ 'library_admin', 'requests_admin' ] or can_manage: - <a class="action-button" href="${h.url_for( controller='library_common', action='folder_permissions', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=library_id )}">Edit this folder's permissions</a> + %if not branch_deleted( folder ) and cntrller == 'library_admin' and info_association: + <a class="action-button" href="${h.url_for( controller='library_common', action='delete_info_template', cntrller=cntrller, item_type='folder', library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), show_deleted=show_deleted )}">Delete this folder's template</a> + %endif + %if not branch_deleted( folder ) and ( cntrller in [ 'library_admin', 'requests_admin' ] or can_manage ): + <a class="action-button" href="${h.url_for( controller='library_common', action='folder_permissions', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=library_id, show_deleted=show_deleted )}">Edit this folder's permissions</a> %endif %if cntrller in [ 'library_admin', 'requests_admin' ]: - %if not folder.deleted: - <a class="action-button" confirm="Click OK to delete the folder '${folder.name}.'" href="${h.url_for( controller='library_admin', action='delete_library_item', library_id=library_id, library_item_id=trans.security.encode_id( folder.id ), library_item_type='folder' )}">Delete this folder and its contents</a> - %elif folder.deleted and not folder.purged: - <a class="action-button" href="${h.url_for( controller='library_admin', action='undelete_library_item', library_id=library_id, library_item_id=trans.security.encode_id( folder.id ), library_item_type='folder' )}">Undelete this folder</a> + %if not library.deleted and not folder.deleted: + <a class="action-button" confirm="Click OK to delete the folder '${folder.name}.'" href="${h.url_for( controller='library_admin', action='delete_library_item', library_id=library_id, library_item_id=trans.security.encode_id( folder.id ), library_item_type='folder', show_deleted=show_deleted )}">Delete this folder and its contents</a> + %elif not library.deleted and folder.deleted and not folder.purged: + <a class="action-button" href="${h.url_for( controller='library_admin', action='undelete_library_item', library_id=library_id, library_item_id=trans.security.encode_id( folder.id ), library_item_type='folder', show_deleted=show_deleted )}">Undelete this folder</a> %endif %endif </div> @@ -318,11 +334,12 @@ %endif %endfor %elif cntrller == 'library_admin': - %if show_deleted: - <% sub_folders, lddas = activatable_folders_and_lddas( trans, folder ) %> - %else: - <% sub_folders, lddas = active_folders_and_lddas( trans, folder ) %> - %endif + <% + if show_deleted: + sub_folders, lddas = activatable_folders_and_lddas( trans, folder ) + else: + sub_folders, lddas = active_folders_and_lddas( trans, folder ) + %> %for sub_folder in sub_folders: ${render_folder( cntrller, sub_folder, pad, created_ldda_ids, library_id, [], parent=my_row, row_counter=row_counter, show_deleted=show_deleted )} %endfor @@ -340,8 +357,8 @@ <ul class="manage-table-actions"> %if not library.deleted and ( cntrller in [ 'library_admin', 'requests_admin' ] or can_add ): - <li><a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( library.root_folder.id ) )}"><span>Add datasets</span></a></li> - <li><a class="action-button" href="${h.url_for( controller='library_common', action='create_folder', cntrller=cntrller, parent_id=trans.security.encode_id( library.root_folder.id ), library_id=trans.security.encode_id( library.id ) )}">Add folder</a></li> + <li><a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( library.root_folder.id ), show_deleted=show_deleted )}"><span>Add datasets</span></a></li> + <li><a class="action-button" href="${h.url_for( controller='library_common', action='create_folder', cntrller=cntrller, parent_id=trans.security.encode_id( library.root_folder.id ), library_id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}">Add folder</a></li> %endif </ul> @@ -360,19 +377,20 @@ <div popupmenu="library-${library.id}-popup"> %if not library.deleted: %if cntrller == 'library_admin' or can_modify: - <a class="action-button" href="${h.url_for( controller='library_common', action='library_info', cntrller=cntrller, id=trans.security.encode_id( library.id ) )}">Edit information</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='library_info', cntrller=cntrller, id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}">Edit information</a> ## Editing templates disabled until we determine optimal approach to re-linking library item to new version of form definition ##%if library.info_association: ## <% form_id = library.info_association[0].template.id %> - ## <a class="action-button" href="${h.url_for( controller='forms', action='edit', form_id=form_id, show_form=True )}">Edit information template</a> + ## <a class="action-button" href="${h.url_for( controller='forms', action='edit', form_id=form_id, show_form=True )}">Edit template</a> %endif - %if cntrller == 'library_admin' or can_add: - %if not library.info_association: - <a class="action-button" href="${h.url_for( controller='library_common', action='info_template', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), response_action='browse_library' )}">Add template</a> - %endif + %if ( cntrller == 'library_admin' or can_add ) and not library.info_association: + <a class="action-button" href="${h.url_for( controller='library_common', action='add_info_template', cntrller=cntrller, item_type='library', library_id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}">Add template</a> + %endif + %if cntrller == 'library_admin' and info_association: + <a class="action-button" href="${h.url_for( controller='library_common', action='delete_info_template', cntrller=cntrller, item_type='library', library_id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}">Delete template</a> %endif %if cntrller == 'library_admin' or can_manage: - <a class="action-button" href="${h.url_for( controller='library_common', action='library_permissions', cntrller=cntrller, id=trans.security.encode_id( library.id ) )}">Edit permissions</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='library_permissions', cntrller=cntrller, id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}">Edit permissions</a> %endif %if cntrller == 'library_admin': <a class="action-button" confirm="Click OK to delete the library named '${library.name}'." href="${h.url_for( controller='library_admin', action='delete_library_item', library_id=trans.security.encode_id( library.id ), library_item_id=trans.security.encode_id( library.id ), library_item_type='library' )}">Delete this data library and its contents</a> diff -r f1cc27efc29e -r 8b7d2cc963fd templates/library/common/common.mako --- a/templates/library/common/common.mako Fri Jan 29 17:10:34 2010 -0500 +++ b/templates/library/common/common.mako Sat Jan 30 07:48:39 2010 -0500 @@ -1,31 +1,24 @@ -<%def name="render_template_info( cntrller, library_item, library_id, response_action, widgets, editable=True )"> +<%def name="render_template_info( cntrller, item_type, library_id, widgets, folder_id=None, ldda_id=None, editable=True )"> <% - library_item_type = 'unknown type' - library_item_desc = '' - if isinstance( library_item, trans.app.model.Library ): - library_item_type = 'library' - library_item_desc = 'library' - elif isinstance( library_item, trans.app.model.LibraryFolder ): - library_item_type = 'folder' - library_item_desc = 'folder' - elif isinstance( library_item, trans.app.model.LibraryDataset ): - library_item_type = 'library_dataset' - library_item_desc = 'dataset' - elif isinstance( library_item, trans.app.model.LibraryDatasetDatasetAssociation ): - library_item_type = 'library_dataset_dataset_association' - library_item_desc = 'library dataset' + if item_type == 'library': + item_desc = 'library' + item = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( library_id ) ) + elif item_type == 'folder': + item_desc = 'folder' + item = trans.sa_session.query( trans.app.model.LibraryFolder ).get( trans.security.decode_id( folder_id ) ) + elif item_type == 'ldda': + item_desc = 'dataset' + item = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( trans.security.decode_id( ldda_id ) ) if cntrller == 'library': current_user_roles = trans.get_current_user_roles() %> %if widgets: <p/> <div class="toolForm"> - <div class="toolFormTitle">Other information about ${library_item_desc} ${library_item.name}</div> + <div class="toolFormTitle">Other information about ${item_desc} ${item.name}</div> <div class="toolFormBody"> - %if editable and ( cntrller=='library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, library_item ) ): - <form name="edit_info" action="${h.url_for( controller='library_common', action='edit_template_info', cntrller=cntrller, library_id=library_id, response_action=response_action, num_widgets=len( widgets ) )}" method="post"> - <input type="hidden" name="library_item_id" value="${trans.security.encode_id( library_item.id )}"/> - <input type="hidden" name="library_item_type" value="${library_item_type}"/> + %if editable and ( cntrller=='library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, item ) ): + <form name="edit_info" action="${h.url_for( controller='library_common', action='edit_template_info', cntrller=cntrller, item_type=item_type, library_id=library_id, num_widgets=len( widgets ), folder_id=folder_id, ldda_id=ldda_id, show_deleted=show_deleted )}" method="post"> %for i, field in enumerate( widgets ): <div class="form-row"> <label>${field[ 'label' ]}</label> diff -r f1cc27efc29e -r 8b7d2cc963fd templates/library/common/folder_info.mako --- a/templates/library/common/folder_info.mako Fri Jan 29 17:10:34 2010 -0500 +++ b/templates/library/common/folder_info.mako Sat Jan 30 07:48:39 2010 -0500 @@ -5,7 +5,7 @@ <br/><br/> <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id )}"><span>Browse this data library</span></a> + <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id, show_deleted=show_deleted )}"><span>Browse this data library</span></a> </li> </ul> @@ -17,7 +17,7 @@ <div class="toolFormTitle">Edit folder name and description</div> <div class="toolFormBody"> %if cntrller=='library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, folder ): - <form name="folder" action="${h.url_for( controller='library_common', action='folder_info', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=library_id )}" method="post" > + <form name="folder" action="${h.url_for( controller='library_common', action='folder_info', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=library_id, show_deleted=show_deleted )}" method="post" > <div class="form-row"> <label>Name:</label> <input type="text" name="name" value="${folder.name}" size="40"/> @@ -47,5 +47,5 @@ </div> </div> %if widgets: - ${render_template_info( cntrller, folder, library_id, 'folder_info', widgets )} + ${render_template_info( cntrller=cntrller, item_type='folder', library_id=library_id, widgets=widgets, folder_id=trans.security.encode_id( folder.id ) )} %endif diff -r f1cc27efc29e -r 8b7d2cc963fd templates/library/common/folder_permissions.mako --- a/templates/library/common/folder_permissions.mako Fri Jan 29 17:10:34 2010 -0500 +++ b/templates/library/common/folder_permissions.mako Sat Jan 30 07:48:39 2010 -0500 @@ -5,7 +5,7 @@ <br/><br/> <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id )}"><span>Browse this data library</span></a> + <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id, show_deleted=show_deleted )}"><span>Browse this data library</span></a> </li> </ul> @@ -15,5 +15,5 @@ %if cntrller in [ 'library_admin', 'requests_admin' ] or trans.app.security_agent.can_manage_library_item( current_user_roles, folder ): ## LIBRARY_ACCESS is a special permission that is set only at the library level. - ${render_permission_form( folder, folder.name, h.url_for( controller='library_common', action='folder_permissions', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=library_id ), roles, do_not_render=[ 'LIBRARY_ACCESS' ] )} + ${render_permission_form( folder, folder.name, h.url_for( controller='library_common', action='folder_permissions', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=library_id, show_deleted=show_deleted ), roles, do_not_render=[ 'LIBRARY_ACCESS' ] )} %endif diff -r f1cc27efc29e -r 8b7d2cc963fd templates/library/common/ldda_edit_info.mako --- a/templates/library/common/ldda_edit_info.mako Fri Jan 29 17:10:34 2010 -0500 +++ b/templates/library/common/ldda_edit_info.mako Sat Jan 30 07:48:39 2010 -0500 @@ -29,7 +29,7 @@ <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id )}"><span>Browse this data library</span></a> + <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id, show_deleted=show_deleted )}"><span>Browse this data library</span></a> </li> </ul> @@ -53,7 +53,7 @@ <div class="toolForm"> <div class="toolFormTitle">Edit attributes of ${ldda.name}</div> <div class="toolFormBody"> - <form name="edit_attributes" action="${h.url_for( controller='library_common', action='ldda_edit_info', cntrller=cntrller, library_id=library_id, folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ) )}" method="post"> + <form name="edit_attributes" action="${h.url_for( controller='library_common', action='ldda_edit_info', cntrller=cntrller, library_id=library_id, folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), show_deleted=show_deleted, )}" method="post"> <input type="hidden" name="id" value="${trans.security.encode_id( ldda.id )}"/> <div class="form-row"> <label>Name:</label> @@ -90,7 +90,7 @@ <input type="submit" name="save" value="Save"/> </div> </form> - <form name="auto_detect" action="${h.url_for( controller='library_common', action='ldda_edit_info', cntrller=cntrller, library_id=library_id, folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ) )}" method="post"> + <form name="auto_detect" action="${h.url_for( controller='library_common', action='ldda_edit_info', cntrller=cntrller, library_id=library_id, folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), show_deleted=show_deleted, )}" method="post"> <div class="form-row"> <input type="hidden" name="id" value="${trans.security.encode_id( ldda.id )}"/> <input type="submit" name="detect" value="Auto-detect"/> @@ -106,8 +106,7 @@ <div class="toolFormTitle">Change data type</div> <div class="toolFormBody"> %if ldda.datatype.allow_datatype_change: - <form name="change_datatype" action="${h.url_for( controller='library_common', action='ldda_edit_info', cntrller=cntrller, library_id=library_id, folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ) )}" method="post"> - <input type="hidden" name="id" value="${trans.security.encode_id( ldda.id )}"/> + <form name="change_datatype" action="${h.url_for( controller='library_common', action='ldda_edit_info', cntrller=cntrller, library_id=library_id, folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), show_deleted=show_deleted, )}" method="post"> <div class="form-row"> <label>New Type:</label> ${datatype( ldda, file_formats )} @@ -162,5 +161,5 @@ </div> %endif %if widgets: - ${render_template_info( 'library', ldda, library_id, 'ldda_edit_info', widgets )} + ${render_template_info( cntrller=cntrller, item_type='ldda', library_id=library_id, widgets=widgets, folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), ldda_id=trans.security.encode_id( ldda.id ) )} %endif diff -r f1cc27efc29e -r 8b7d2cc963fd templates/library/common/ldda_info.mako --- a/templates/library/common/ldda_info.mako Fri Jan 29 17:10:34 2010 -0500 +++ b/templates/library/common/ldda_info.mako Sat Jan 30 07:48:39 2010 -0500 @@ -19,7 +19,7 @@ <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ) )}"><span>Browse this data library</span></a> + <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}"><span>Browse this data library</span></a> </li> </ul> @@ -41,19 +41,17 @@ <a id="dataset-${ldda.id}-popup" class="popup-arrow" style="display: none;">▼</a> <div popupmenu="dataset-${ldda.id}-popup"> %if cntrller=='library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, ldda.library_dataset ): - <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_edit_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), id=trans.security.encode_id( ldda.id ) )}">Edit this dataset's information</a> - %else: - <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_display_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), id=trans.security.encode_id( ldda.id ) )}">View this dataset's information</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_edit_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), id=trans.security.encode_id( ldda.id ), show_deleted=show_deleted )}">Edit this dataset's information</a> %endif %if cntrller=='library_admin' or trans.app.security_agent.can_manage_dataset( current_user_roles, ldda.dataset ) and trans.app.security_agent.can_manage_library_item( current_user_roles, ldda.library_dataset ): - <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_permissions', library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), id=trans.security.encode_id( ldda.id ) )}">Edit this dataset's permissions</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_permissions', library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), id=trans.security.encode_id( ldda.id ), show_deleted=show_deleted )}">Edit this dataset's permissions</a> %endif %if current_version and ( cntrller=='library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, ldda.library_dataset ) ): - <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), replace_id=trans.security.encode_id( ldda.library_dataset.id ) )}">Upload a new version of this dataset</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), replace_id=trans.security.encode_id( ldda.library_dataset.id ), show_deleted=show_deleted )}">Upload a new version of this dataset</a> %endif %if cntrller=='library' and ldda.has_data: - <a class="action-button" href="${h.url_for( controller='library_common', action='act_on_multiple_datasets', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), ldda_ids=trans.security.encode_id( ldda.id ), do_action='add' )}">Import this dataset into your current history</a> - <a class="action-button" href="${h.url_for( controller='library', action='download_dataset_from_folder', cntrller=cntrller, id=trans.security.encode_id( ldda.id ), library_id=trans.security.encode_id( library.id ) )}">Download this dataset</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='act_on_multiple_datasets', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), ldda_ids=trans.security.encode_id( ldda.id ), do_action='add', show_deleted=show_deleted )}">Import this dataset into your current history</a> + <a class="action-button" href="${h.url_for( controller='library', action='download_dataset_from_folder', cntrller=cntrller, id=trans.security.encode_id( ldda.id ), library_id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}">Download this dataset</a> %endif </div> %endif @@ -97,7 +95,7 @@ %endif </div> %if widgets: - ${render_template_info( 'library_common', ldda, trans.security.encode_id( library.id ), 'ldda_display_info', widgets, editable=False )} + ${render_template_info( cntrller=cntrller, item_type='ldda', library_id=library_id, widgets=widgets, folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), ldda_id=trans.security.encode_id( ldda.id ), editable=False )} %endif %if current_version: <% expired_lddas = [ e_ldda for e_ldda in ldda.library_dataset.expired_datasets ] %> @@ -105,7 +103,7 @@ <div class="toolFormTitle">Expired versions of ${ldda.name}</div> %for expired_ldda in expired_lddas: <div class="form-row"> - <a href="${h.url_for( controller='library_common', action='ldda_display_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( expired_ldda.library_dataset.folder.id ), id=trans.security.encode_id( expired_ldda.id ) )}">${expired_ldda.name}</a> + <a href="${h.url_for( controller='library_common', action='ldda_display_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( expired_ldda.library_dataset.folder.id ), id=trans.security.encode_id( expired_ldda.id ), show_deleted=show_deleted )}">${expired_ldda.name}</a> </div> %endfor %endif diff -r f1cc27efc29e -r 8b7d2cc963fd templates/library/common/ldda_permissions.mako --- a/templates/library/common/ldda_permissions.mako Fri Jan 29 17:10:34 2010 -0500 +++ b/templates/library/common/ldda_permissions.mako Sat Jan 30 07:48:39 2010 -0500 @@ -13,7 +13,7 @@ <br/><br/> <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id )}"><span>Browse this data library</span></a> + <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id, show_deleted=show_deleted )}"><span>Browse this data library</span></a> </li> </ul> @@ -59,4 +59,4 @@ <% ldda_ids = ",".join( [ trans.security.encode_id( d.id ) for d in lddas ] ) %> ## LIBRARY_ACCESS is a special permission that is set only at the library level, ## and DATASET_MANAGE_PERMISSIONS is inherited to the dataset from the ldda. -${render_permission_form( lddas[0], name_str, h.url_for( controller='library_common', action='ldda_permissions', cntrller=cntrller, library_id=library_id, folder_id=trans.security.encode_id( lddas[0].library_dataset.folder.id ), id=ldda_ids ), roles, do_not_render=[ 'LIBRARY_ACCESS', 'DATASET_MANAGE_PERMISSIONS' ] )} +${render_permission_form( lddas[0], name_str, h.url_for( controller='library_common', action='ldda_permissions', cntrller=cntrller, library_id=library_id, folder_id=trans.security.encode_id( lddas[0].library_dataset.folder.id ), id=ldda_ids, show_deleted=show_deleted ), roles, do_not_render=[ 'LIBRARY_ACCESS', 'DATASET_MANAGE_PERMISSIONS' ] )} diff -r f1cc27efc29e -r 8b7d2cc963fd templates/library/common/library_dataset_info.mako --- a/templates/library/common/library_dataset_info.mako Fri Jan 29 17:10:34 2010 -0500 +++ b/templates/library/common/library_dataset_info.mako Sat Jan 30 07:48:39 2010 -0500 @@ -11,7 +11,7 @@ <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id )}"><span>Browse this data library</span></a> + <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id, show_deleted=show_deleted )}"><span>Browse this data library</span></a> </li> </ul> @@ -23,7 +23,7 @@ <div class="toolForm"> <div class="toolFormTitle">Edit attributes of ${library_dataset.name}</div> <div class="toolFormBody"> - <form name="edit_attributes" action="${h.url_for( controller='library_common', action='library_dataset_info', id=trans.security.encode_id( library_dataset.id ), library_id=library_id )}" method="post"> + <form name="edit_attributes" action="${h.url_for( controller='library_common', action='library_dataset_info', id=trans.security.encode_id( library_dataset.id ), library_id=library_id, show_deleted=show_deleted )}" method="post"> <div class="form-row"> <label>Name:</label> <div style="float: left; width: 250px; margin-right: 10px;"> diff -r f1cc27efc29e -r 8b7d2cc963fd templates/library/common/library_dataset_permissions.mako --- a/templates/library/common/library_dataset_permissions.mako Fri Jan 29 17:10:34 2010 -0500 +++ b/templates/library/common/library_dataset_permissions.mako Sat Jan 30 07:48:39 2010 -0500 @@ -11,7 +11,7 @@ <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id )}"><span>Browse this data library</span></a> + <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id, show_deleted=show_deleted )}"><span>Browse this data library</span></a> </li> </ul> @@ -21,5 +21,5 @@ %if cntrller == 'library_admin' or trans.app.security_agent.can_manage_library_item( current_user_roles, library_dataset ): ## LIBRARY_ACCESS is a special permission that is set only at the library level. - ${render_permission_form( library_dataset, library_dataset.name, h.url_for( controller='library_common', action='library_dataset_permissions', cntrller=cntrller, id=trans.security.encode_id( library_dataset.id ), library_id=library_id ), roles, do_not_render=[ 'LIBRARY_ACCESS' ] )} + ${render_permission_form( library_dataset, library_dataset.name, h.url_for( controller='library_common', action='library_dataset_permissions', cntrller=cntrller, id=trans.security.encode_id( library_dataset.id ), library_id=library_id, show_deleted=show_deleted ), roles, do_not_render=[ 'LIBRARY_ACCESS' ] )} %endif diff -r f1cc27efc29e -r 8b7d2cc963fd templates/library/common/library_info.mako --- a/templates/library/common/library_info.mako Fri Jan 29 17:10:34 2010 -0500 +++ b/templates/library/common/library_info.mako Sat Jan 30 07:48:39 2010 -0500 @@ -5,7 +5,7 @@ <br/><br/> <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ) )}"><span>Browse this data library</span></a> + <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}"><span>Browse this data library</span></a> </li> </ul> @@ -17,7 +17,7 @@ <div class="toolForm"> <div class="toolFormTitle">Change library name and description</div> <div class="toolFormBody"> - <form name="library" action="${h.url_for( controller='library_common', action='library_info', id=trans.security.encode_id( library.id ), cntrller=cntrller )}" method="post" > + <form name="library" action="${h.url_for( controller='library_common', action='library_info', id=trans.security.encode_id( library.id ), cntrller=cntrller, show_deleted=show_deleted )}" method="post" > <div class="form-row"> <label>Name:</label> <div style="float: left; width: 250px; margin-right: 10px;"> @@ -52,5 +52,5 @@ %endif %if widgets: - ${render_template_info( cntrller, library, trans.security.encode_id( library.id ), 'library_info', widgets )} + ${render_template_info( cntrller=cntrller, item_type='library', library_id=trans.security.encode_id( library.id ), widgets=widgets )} %endif diff -r f1cc27efc29e -r 8b7d2cc963fd templates/library/common/library_permissions.mako --- a/templates/library/common/library_permissions.mako Fri Jan 29 17:10:34 2010 -0500 +++ b/templates/library/common/library_permissions.mako Sat Jan 30 07:48:39 2010 -0500 @@ -5,7 +5,7 @@ <br/><br/> <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ) )}"><span>Browse this data library</span></a> + <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}"><span>Browse this data library</span></a> </li> </ul> @@ -14,5 +14,5 @@ %endif %if cntrller == 'library_admin' or trans.app.security_agent.can_manage_library_item( current_user_roles, library ): - ${render_permission_form( library, library.name, h.url_for( controller='library_common', action='library_permissions', cntrller=cntrller, id=trans.security.encode_id( library.id ) ), roles )} + ${render_permission_form( library, library.name, h.url_for( controller='library_common', action='library_permissions', cntrller=cntrller, id=trans.security.encode_id( library.id ), show_deleted=show_deleted ), roles )} %endif diff -r f1cc27efc29e -r 8b7d2cc963fd templates/library/common/new_folder.mako --- a/templates/library/common/new_folder.mako Fri Jan 29 17:10:34 2010 -0500 +++ b/templates/library/common/new_folder.mako Sat Jan 30 07:48:39 2010 -0500 @@ -4,7 +4,7 @@ <br/<br/> <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id )}"><span>Browse this data library</span></a> + <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id, show_deleted=show_deleted )}"><span>Browse this data library</span></a> </li> </ul> @@ -15,7 +15,7 @@ <div class="toolForm"> <div class="toolFormTitle">Create a new folder</div> <div class="toolFormBody"> - <form name="folder" action="${h.url_for( controller='library_common', action='create_folder', cntrller=cntrller, parent_id=trans.security.encode_id( folder.id ), library_id=library_id )}" method="post" > + <form name="folder" action="${h.url_for( controller='library_common', action='create_folder', cntrller=cntrller, parent_id=trans.security.encode_id( folder.id ), library_id=library_id, show_deleted=show_deleted )}" method="post" > <div class="form-row"> <label>Name:</label> <div style="float: left; width: 250px; margin-right: 10px;"> diff -r f1cc27efc29e -r 8b7d2cc963fd templates/library/common/select_info_template.mako --- a/templates/library/common/select_info_template.mako Fri Jan 29 17:10:34 2010 -0500 +++ b/templates/library/common/select_info_template.mako Sat Jan 30 07:48:39 2010 -0500 @@ -4,7 +4,7 @@ <br/><br/> <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id )}"><span>Browse this data library</span></a> + <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id, show_deleted=show_deleted )}"><span>Browse this data library</span></a> </li> </ul> @@ -14,20 +14,9 @@ <div class="toolForm"> <div class="toolFormTitle">Select a form on which to base the template for the ${library_item_desc} '${library_item_name}'</div> - <form name="new_info_template" action="${h.url_for( controller='library_common', action='info_template', cntrller=cntrller )}" method="post" > + <form name="new_info_template" action="${h.url_for( controller='library_common', action='add_info_template', cntrller=cntrller, item_type=item_type, library_id=library_id, folder_id=folder_id, ldda_id=ldda_id, show_deleted=show_deleted )}" method="post" > <div class="toolFormBody"> <div class="form-row"> - <input type="hidden" name="library_id" value="${library_id}"/> - %if library_dataset_id: - <input type="hidden" name="library_dataset_id" value="${library_dataset_id}"/> - <input type="hidden" name="response_action" value="ldda_edit_info"/> - %elif folder_id: - <input type="hidden" name="folder_id" value="${folder_id}"/> - <input type="hidden" name="response_action" value="folder"/> - %elif ldda_id: - <input type="hidden" name="ldda_id" value="${ldda_id}"/> - <input type="hidden" name="response_action" value="ldda_edit_info"/> - %endif <label>Template:</label> <select name="form_id"> %for form in forms: diff -r f1cc27efc29e -r 8b7d2cc963fd templates/library/common/upload.mako --- a/templates/library/common/upload.mako Fri Jan 29 17:10:34 2010 -0500 +++ b/templates/library/common/upload.mako Sat Jan 30 07:48:39 2010 -0500 @@ -26,26 +26,26 @@ ## Don't allow multiple datasets to be uploaded when replacing a dataset with a new version <a id="upload-librarydataset--popup" class="popup-arrow" style="display: none;">▼</a> <div popupmenu="upload-librarydataset--popup"> - <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller,library_id=library_id, folder_id=folder_id, replace_id=replace_id, upload_option='upload_file' )}">Upload files</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller,library_id=library_id, folder_id=folder_id, replace_id=replace_id, upload_option='upload_file', show_deleted=show_deleted )}">Upload files</a> %if cntrller == 'library_admin': %if trans.app.config.library_import_dir and os.path.exists( trans.app.config.library_import_dir ): - <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=library_id, folder_id=folder_id, replace_id=replace_id, upload_option='upload_directory' )}">Upload directory of files</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=library_id, folder_id=folder_id, replace_id=replace_id, upload_option='upload_directory', show_deleted=show_deleted )}">Upload directory of files</a> %endif %if trans.app.config.allow_library_path_paste: - <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=library_id, folder_id=folder_id, replace_id=replace_id, upload_option='upload_paths' )}">Upload files from filesystem paths</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=library_id, folder_id=folder_id, replace_id=replace_id, upload_option='upload_paths', show_deleted=show_deleted )}">Upload files from filesystem paths</a> %endif %elif cntrller == 'library': %if trans.app.config.user_library_import_dir and os.path.exists( os.path.join( trans.app.config.user_library_import_dir, trans.user.email ) ): - <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=library_id, folder_id=folder_id, replace_id=replace_id, upload_option='upload_directory' )}">Upload directory of files</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=library_id, folder_id=folder_id, replace_id=replace_id, upload_option='upload_directory', show_deleted=show_deleted )}">Upload directory of files</a> %endif %endif - <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=library_id, folder_id=folder_id, replace_id=replace_id, upload_option='import_from_history' )}">Import datasets from your current history</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=library_id, folder_id=folder_id, replace_id=replace_id, upload_option='import_from_history', show_deleted=show_deleted )}">Import datasets from your current history</a> </div> %endif <br/><br/> <ul class="manage-table-actions"> <li> - <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id )}"><span>Browse this data library</span></a> + <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=library_id, show_deleted=show_deleted )}"><span>Browse this data library</span></a> </li> </ul> diff -r f1cc27efc29e -r 8b7d2cc963fd test/base/twilltestcase.py --- a/test/base/twilltestcase.py Fri Jan 29 17:10:34 2010 -0500 +++ b/test/base/twilltestcase.py Sat Jan 30 07:48:39 2010 -0500 @@ -1379,15 +1379,19 @@ check_str = "Library '%s' has been renamed to '%s'" % ( old_name, name ) self.check_page_for_string( check_str ) self.home() - def add_library_info_template( self, cntrller, library_id, form_id, form_name ): + def add_info_template( self, cntrller, item_type, library_id, form_id, form_name, folder_id=None, ldda_id=None ): """Add a new info template to a library item""" self.home() - url = "%s/library_common/info_template?cntrller=%s&library_id=%s&response_action='browse_library'" % ( self.url, cntrller, library_id ) + if item_type == 'library': + url = "%s/library_common/add_info_template?cntrller=%s&item_type=%s&library_id=%s" % ( self.url, cntrller, item_type, library_id ) + elif item_type == 'folder': + url = "%s/library_common/add_info_template?cntrller=%s&item_type=%s&library_id=%s&folder_id=%s" % ( self.url, cntrller, item_type, library_id, folder_id ) + elif item_type == 'ldda': + url = "%s/library_common/add_info_template?cntrller=%s&item_type=%s&library_id=%s&folder_id=%s&ldda_id=%s" % ( self.url, cntrller, item_type, library_id, folder_id, ldda_id ) self.visit_url( url ) self.check_page_for_string ( "Select a form on which to base the template" ) - tc.fv( '1', 'library_id', library_id ) tc.submit( 'add_info_template_button' ) - self.check_page_for_string = 'An information template based on the form "%s" has been added to this data library.' % form_name + self.check_page_for_string = 'An information template based on the form "%s" has been added to this' % form_name self.home() def library_info( self, library_id, library_name, ele_1_field_name, ele_1_contents, ele_2_field_name, ele_2_contents, controller='library_admin' ): """Add information to a library using an existing template with 2 elements""" @@ -1399,17 +1403,6 @@ tc.fv( '2', ele_2_field_name, ele_2_contents ) tc.submit( 'create_new_info_button' ) self.home() - def add_folder_info_template( self, cntrller, library_id, folder_id, form_id, form_name ): - """Add a new info template to a folder""" - self.home() - url = "%s/library_common/info_template?cntrller=%s&library_id=%s&folder_id=%s&response_action='folder_info'" % \ - ( self.url, cntrller, library_id, folder_id ) - self.visit_url( url ) - self.check_page_for_string ( "Select a form on which to base the template" ) - tc.fv( '1', 'library_id', library_id ) - tc.submit( 'add_info_template_button' ) - self.check_page_for_string = 'An information template based on the form "%s" has been added to this folder.' % form_name - self.home() def add_folder( self, controller, library_id, folder_id, name='Folder One', description='This is Folder One' ): """Create a new folder""" self.home() diff -r f1cc27efc29e -r 8b7d2cc963fd test/functional/test_security_and_libraries.py --- a/test/functional/test_security_and_libraries.py Fri Jan 29 17:10:34 2010 -0500 +++ b/test/functional/test_security_and_libraries.py Sat Jan 30 07:48:39 2010 -0500 @@ -576,10 +576,11 @@ assert form_one is not None, 'Problem retrieving form named (%s) from the database' % form_name # Add a new information template to the library template_name = 'Library Template 1' - self.add_library_info_template( 'library_admin', - self.security.encode_id( library_one.id ), - str( form_one.id ), - form_one.name ) + self.add_info_template( 'library_admin', + 'library', + self.security.encode_id( library_one.id ), + str( form_one.id ), + form_one.name ) # Make sure the template fields are displayed on the library information page field_dict = form_one.fields[ 0 ] global form_one_field_label @@ -1991,11 +1992,12 @@ .first() # Add an information template to the folder template_name = 'Folder Template 1' - self.add_folder_info_template( 'library', - self.security.encode_id( library_one.id ), - self.security.encode_id( folder_x.id ), - self.security.encode_id( form_one.id ), - form_one.name ) + self.add_info_template( 'library', + 'folder', + self.security.encode_id( library_one.id ), + self.security.encode_id( form_one.id ), + form_one.name, + folder_id=self.security.encode_id( folder_x.id ) ) # Modify the folder's information contents = '%s folder contents' % form_one_field_label new_name = "Root Folder's Folder Y" @@ -2033,10 +2035,11 @@ assert ldda_x is not None, 'Problem retrieving ldda_x from the database' # Add an information template to the library template_name = 'Library Template 3' - self.add_library_info_template( 'library', - self.security.encode_id( library_three.id ), - self.security.encode_id( form_one.id ), - form_one.name ) + self.add_info_template( 'library', + 'library', + self.security.encode_id( library_three.id ), + self.security.encode_id( form_one.id ), + form_one.name ) # Add information to the library using the template contents = '%s library contents' % form_one_field_label self.visit_url( '%s/library_common/library_info?cntrller=library&id=%s' % ( self.url, self.security.encode_id( library_three.id ) ) )
participants (1)
-
Greg Von Kuster