details: http://www.bx.psu.edu/hg/galaxy/rev/a3e6350ffc57 changeset: 3373:a3e6350ffc57 user: Greg Von Kuster <greg@bx.psu.edu> date: Thu Feb 11 14:26:25 2010 -0500 description: Add the ability to edit library templates and make library template inheritance optional. ¬†Fix another bug in the form builder's CheckboxField.is_checked() method, and clean up some library code. With regard to template inheritance, a LibraryFolder is a special case because if it inherited the template from it's parent,¬†we want to set inheritable to True for it's info_association.¬† This allows for the default¬†inheritance to be False for each level in the Library hierarchy unless we're creating a new¬†level in the hierarchy, in which case we'll inherit the "inheritable" setting from the parent¬†level. diffstat: lib/galaxy/model/__init__.py | 39 +- lib/galaxy/model/mapping.py | 2 + lib/galaxy/model/migrate/versions/0038_add_inheritable_column_to_library_template_assoc_tables.py | 40 + lib/galaxy/tools/actions/upload_common.py | 4 + lib/galaxy/web/controllers/forms.py | 63 +- lib/galaxy/web/controllers/library_admin.py | 50 +- lib/galaxy/web/controllers/library_common.py | 352 ++++++--- lib/galaxy/web/form_builder.py | 4 +- templates/admin/forms/edit_form.mako | 13 +- templates/library/common/browse_library.mako | 77 +- templates/library/common/common.mako | 98 +- templates/library/common/edit_template.mako | 35 + templates/library/common/folder_info.mako | 2 +- templates/library/common/ldda_edit_info.mako | 2 +- templates/library/common/ldda_info.mako | 23 +- templates/library/common/library_dataset_info.mako | 3 +- templates/library/common/library_info.mako | 74 +- templates/library/common/new_folder.mako | 7 +- templates/library/common/select_info_template.mako | 75 -- templates/library/common/select_template.mako | 82 ++ test/base/twilltestcase.py | 41 +- test/functional/test_security_and_libraries.py | 56 +- 22 files changed, 678 insertions(+), 464 deletions(-) diffs (2031 lines): diff -r 4a6bb3b64012 -r a3e6350ffc57 lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py Thu Feb 11 09:25:29 2010 -0500 +++ b/lib/galaxy/model/__init__.py Thu Feb 11 14:26:25 2010 -0500 @@ -755,14 +755,17 @@ self.root_folder = root_folder def get_info_association( self, restrict=False, inherited=False ): if self.info_association: - return self.info_association[0], inherited + if not inherited or self.info_association[0].inheritable: + return self.info_association[0], inherited + else: + return None, inherited return None, inherited def get_template_widgets( self, trans, get_contents=True ): # See if we have any associated templates - the returned value for # inherited is not applicable at the library level. The get_contents # param is passed by callers that are inheriting a template - these # are usually new library datsets for which we want to include template - # fields on the upload form. + # fields on the upload form, but not the contents of the inherited template. info_association, inherited = self.get_info_association() if info_association: template = info_association.template @@ -807,11 +810,14 @@ def get_info_association( self, restrict=False, inherited=False ): # If restrict is True, we will return this folder's info_association, not inheriting. # 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. + # inheritable hierarchy if it is "inheritable". 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 not inherited or self.info_association[0].inheritable: + return self.info_association[0], inherited + else: + return None, inherited if restrict: return None, inherited if self.parent: @@ -1004,19 +1010,22 @@ return [] class LibraryInfoAssociation( object ): - def __init__( self, library, form_definition, info ): + def __init__( self, library, form_definition, info, inheritable=False ): self.library = library self.template = form_definition self.info = info + self.inheritable = inheritable class LibraryFolderInfoAssociation( object ): - def __init__( self, folder, form_definition, info ): + def __init__( self, folder, form_definition, info, inheritable=False ): self.folder = folder self.template = form_definition self.info = info + self.inheritable = inheritable class LibraryDatasetDatasetInfoAssociation( object ): def __init__( self, library_dataset_dataset_association, form_definition, info ): + # TODO: need to figure out if this should be inheritable to the associated LibraryDataset self.library_dataset_dataset_association = library_dataset_dataset_association self.template = form_definition self.info = info @@ -1252,8 +1261,18 @@ else: value = util.restore_text( params.get( field_name, '' ) ) elif contents: - # this field has a saved value - value = str( contents[ index ] ) + try: + # This field has a saved value. + value = str( contents[ index ] ) + except: + # If there was an error getting the saved value, we'll still + # display the widget, but it will be empty. + if field[ 'type' ] == 'CheckboxField': + # Since we do not have contents, set checkbox value to False + value = False + else: + # Set other field types to empty string + value = '' else: # if none of the above, then leave the field empty if field[ 'type' ] == 'CheckboxField': diff -r 4a6bb3b64012 -r a3e6350ffc57 lib/galaxy/model/mapping.py --- a/lib/galaxy/model/mapping.py Thu Feb 11 09:25:29 2010 -0500 +++ b/lib/galaxy/model/mapping.py Thu Feb 11 14:26:25 2010 -0500 @@ -294,6 +294,7 @@ 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( "inheritable", Boolean, index=True, default=False ), Column( "deleted", Boolean, index=True, default=False ) ) LibraryFolderInfoAssociation.table = Table( 'library_folder_info_association', metadata, @@ -301,6 +302,7 @@ 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( "inheritable", Boolean, index=True, default=False ), Column( "deleted", Boolean, index=True, default=False ) ) LibraryDatasetDatasetInfoAssociation.table = Table( 'library_dataset_dataset_info_association', metadata, diff -r 4a6bb3b64012 -r a3e6350ffc57 lib/galaxy/model/migrate/versions/0038_add_inheritable_column_to_library_template_assoc_tables.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/galaxy/model/migrate/versions/0038_add_inheritable_column_to_library_template_assoc_tables.py Thu Feb 11 14:26:25 2010 -0500 @@ -0,0 +1,40 @@ +""" +Migration script to add an inheritable column to the following tables: +library_info_association, library_folder_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( "inheritable", Boolean, index=True, default=False ) + c.create( LibraryInfoAssociation_table ) + assert c is LibraryInfoAssociation_table.c.inheritable + cmd = "UPDATE library_info_association SET inheritable = false" + try: + db_session.execute( cmd ) + except Exception, e: + log.debug( "Setting value of column inheritable to false in library_info_association failed: %s" % ( str( e ) ) ) + + LibraryFolderInfoAssociation_table = Table( "library_folder_info_association", metadata, autoload=True ) + c = Column( "inheritable", Boolean, index=True, default=False ) + c.create( LibraryFolderInfoAssociation_table ) + assert c is LibraryFolderInfoAssociation_table.c.inheritable + cmd = "UPDATE library_folder_info_association SET inheritable = false" + try: + db_session.execute( cmd ) + except Exception, e: + log.debug( "Setting value of column inheritable to false in library_folder_info_association failed: %s" % ( str( e ) ) ) + +def downgrade(): + pass diff -r 4a6bb3b64012 -r a3e6350ffc57 lib/galaxy/tools/actions/upload_common.py --- a/lib/galaxy/tools/actions/upload_common.py Thu Feb 11 09:25:29 2010 -0500 +++ b/lib/galaxy/tools/actions/upload_common.py Thu Feb 11 14:26:25 2010 -0500 @@ -191,6 +191,8 @@ trans.sa_session.add( form_values ) trans.sa_session.flush() # Create a new info_association between the current ldda and form_values + # TODO: Currently info_associations at the ldda level are not inheritable to the associated LibraryDataset, + # we need to figure out if this is optimal info_association = trans.app.model.LibraryDatasetDatasetInfoAssociation( ldda, library_bunch.template, form_values ) trans.sa_session.add( info_association ) trans.sa_session.flush() @@ -235,6 +237,8 @@ trans.sa_session.add( form_values ) trans.sa_session.flush() # Create a new info_association between the current ldda and form_values + # TODO: Currently info_associations at the ldda level are not inheritable to the associated LibraryDataset, + # we need to figure out if this is optimal info_association = trans.app.model.LibraryDatasetDatasetInfoAssociation( data, library_bunch.template, form_values ) trans.sa_session.add( info_association ) trans.sa_session.flush() diff -r 4a6bb3b64012 -r a3e6350ffc57 lib/galaxy/web/controllers/forms.py --- a/lib/galaxy/web/controllers/forms.py Thu Feb 11 09:25:29 2010 -0500 +++ b/lib/galaxy/web/controllers/forms.py Thu Feb 11 14:26:25 2010 -0500 @@ -92,7 +92,7 @@ elif operation == "undelete": return self.__undelete( trans, **kwd ) elif operation == "edit": - return self.__edit( trans, **kwd ) + return self.edit( trans, **kwd ) return self.forms_grid( trans, **kwd ) def __view(self, trans, **kwd): try: @@ -141,13 +141,11 @@ self.__get_saved_form( fd ) if self.__imported_from_file: return trans.response.send_redirect( web.url_for( controller='forms', - action='manage', - operation='edit', + action='edit', id=trans.security.encode_id(fd.current.id)) ) else: return trans.response.send_redirect( web.url_for( controller='forms', - action='manage', - operation='edit', + action='edit', id=trans.security.encode_id(fd.current.id), add_field_button='Add field', name=fd.name, @@ -197,10 +195,13 @@ action='manage', message='%i form(s) is undeleted.' % len(id_list), status='done') ) - def __edit( self, trans, **kwd ): + @web.expose + def edit( self, trans, response_redirect=None, **kwd ): ''' - This callback method is for handling all the editing functions like - renaming fields, adding/deleting fields, changing fields attributes. + This callback method is for handling form editing. The value of response_redirect + should be an URL that is defined by the caller. This allows for redirecting as desired + when the form changes have been saved. For an example of how this works, see the + edit_template() method in the library_common controller. ''' params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) @@ -223,13 +224,16 @@ if not fd_new: current_form = self.__get_form( trans, **kwd ) return self.__show( trans=trans, form=fd, current_form=current_form, - msg=msg, messagetype='error', **kwd ) - # everything went fine. form saved successfully. Show the saved form + msg=msg, messagetype='error', response_redirect=response_redirect, **kwd ) + # everything went fine. form saved successfully. Show the saved form or redirect + # to response_redirect if appropriate. + if response_redirect: + return trans.response.send_redirect( response_redirect ) fd = fd_new current_form = self.__get_saved_form( fd ) msg = "The form '%s' has been updated with the changes." % fd.name return self.__show( trans=trans, form=fd, current_form=current_form, - msg=msg, messagetype=messagetype, **kwd ) + msg=msg, messagetype=messagetype, response_redirect=response_redirect, **kwd ) # # Add a layout grid # @@ -238,7 +242,7 @@ current_form['layout'].append('') # show the form again return self.__show( trans=trans, form=fd, current_form=current_form, - msg=msg, messagetype=messagetype, **kwd ) + msg=msg, messagetype=messagetype, response_redirect=response_redirect, **kwd ) # # Delete a layout grid # @@ -247,7 +251,7 @@ index = int( kwd[ 'remove_layout_grid_button' ].split( ' ' )[2] ) - 1 del current_form['layout'][index] return self.__show( trans=trans, form=fd, current_form=current_form, - msg=msg, messagetype=messagetype, **kwd ) + msg=msg, messagetype=messagetype, response_redirect=response_redirect, **kwd ) # # Add a field # @@ -256,7 +260,7 @@ current_form['fields'].append( self.empty_field ) # show the form again with one empty field return self.__show( trans=trans, form=fd, current_form=current_form, - msg=msg, messagetype=messagetype, **kwd ) + msg=msg, messagetype=messagetype, response_redirect=response_redirect, **kwd ) # # Delete a field # @@ -266,33 +270,33 @@ index = int( kwd[ 'remove_button' ].split( ' ' )[2] ) - 1 del current_form['fields'][index] return self.__show( trans=trans, form=fd, current_form=current_form, - msg=msg, messagetype=messagetype, **kwd ) + msg=msg, messagetype=messagetype, response_redirect=response_redirect, **kwd ) # # Add SelectField option # elif 'Add' in kwd.values(): - return self.__add_selectbox_option(trans, fd, msg, messagetype, **kwd) + return self.__add_selectbox_option(trans, fd, msg, messagetype, response_redirect=response_redirect, **kwd) # # Remove SelectField option # elif 'Remove' in kwd.values(): - return self.__remove_selectbox_option(trans, fd, msg, messagetype, **kwd) + return self.__remove_selectbox_option(trans, fd, msg, messagetype, response_redirect=response_redirect, **kwd) # # Refresh page # elif params.get( 'refresh', False ): current_form = self.__get_form( trans, **kwd ) return self.__show( trans=trans, form=fd, current_form=current_form, - msg=msg, messagetype=messagetype, **kwd ) + msg=msg, messagetype=messagetype, response_redirect=response_redirect, **kwd ) # # Show the form for editing # else: current_form = self.__get_saved_form( fd ) return self.__show( trans=trans, form=fd, current_form=current_form, - msg=msg, messagetype=messagetype, **kwd ) + msg=msg, messagetype=messagetype, response_redirect=response_redirect, **kwd ) - def __add_selectbox_option( self, trans, fd, msg, messagetype, **kwd ): + def __add_selectbox_option( self, trans, fd, msg, messagetype, response_redirect=None, **kwd ): ''' This method adds a selectbox option. The kwd dict searched for the field index which needs to be removed @@ -309,12 +313,12 @@ # something wrong happened return self.__show( trans=trans, form=fd, current_form=current_form, msg='Error in adding selectfield option', - messagetype='error', **kwd ) + messagetype='error', response_redirect=response_redirect, **kwd ) # add an empty option current_form[ 'fields' ][ index ][ 'selectlist' ].append( '' ) return self.__show( trans=trans, form=fd, current_form=current_form, - msg=msg, messagetype=messagetype, **kwd ) - def __remove_selectbox_option( self, trans, fd, msg, messagetype, **kwd ): + msg=msg, messagetype=messagetype, response_redirect=response_redirect, **kwd ) + def __remove_selectbox_option( self, trans, fd, msg, messagetype, response_redirect=None, **kwd ): ''' This method removes a selectbox option. The kwd dict searched for the field index and option index which needs to be removed @@ -332,11 +336,11 @@ # something wrong happened return self.__show( trans=trans, form=fd, current_form=current_form, msg='Error in removing selectfield option', - messagetype='error', **kwd ) + messagetype='error', response_redirect=response_redirect, **kwd ) # remove the option del current_form[ 'fields' ][ index ][ 'selectlist' ][ option ] return self.__show( trans=trans, form=fd, current_form=current_form, - msg=msg, messagetype=messagetype, **kwd ) + msg=msg, messagetype=messagetype, response_redirect=response_redirect, **kwd ) def __get_field(self, index, **kwd): @@ -597,7 +601,7 @@ def label(self): return str(self.index)+'.'+self.label - def __show( self, trans, form, current_form, msg='', messagetype='done', **kwd ): + def __show( self, trans, form, current_form, msg='', messagetype='done', response_redirect=None, **kwd ): ''' This method displays the form and any of the changes made to it, The empty_form param allows for this method to simulate clicking @@ -606,9 +610,11 @@ ''' params = util.Params( kwd ) # name & description + # TODO: RC, I've changed Type to be a hidden field since it should not be displayed on the edit_form.mako + # template. Make sure this is the optimal solution for this problem. See my additional TODO in edit_form.mako. form_details = [ ( 'Name', TextField( 'name', 40, current_form[ 'name' ] ) ), ( 'Description', TextField( 'description', 40, current_form[ 'desc' ] ) ), - ( 'Type', self.__form_types_widget(trans, selected=current_form[ 'type' ]) ) ] + ( 'Type', HiddenField( 'form_type_selectbox', current_form['type']) ) ] form_layout = [] if current_form[ 'type' ] == trans.app.model.FormDefinition.types.SAMPLE: for index, lg in enumerate(current_form[ 'layout' ]): @@ -629,7 +635,8 @@ msg=msg, messagetype=messagetype, current_form_type=current_form[ 'type' ], - layout_grids=form_layout ) + layout_grids=form_layout, + response_redirect=response_redirect ) # Common methods for all components that use forms def get_all_forms( trans, all_versions=False, filter=None, form_type='All' ): diff -r 4a6bb3b64012 -r a3e6350ffc57 lib/galaxy/web/controllers/library_admin.py --- a/lib/galaxy/web/controllers/library_admin.py Thu Feb 11 09:25:29 2010 -0500 +++ b/lib/galaxy/web/controllers/library_admin.py Thu Feb 11 14:26:25 2010 -0500 @@ -162,7 +162,7 @@ status='done' ) ) @web.expose @web.require_admin - def delete_library_item( self, trans, library_id, library_item_id, library_item_type, **kwd ): + def delete_library_item( self, trans, library_id, item_id, 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 @@ -171,24 +171,24 @@ # 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 } - if library_item_type not in library_item_types: - msg = 'Bad library_item_type specified: %s' % str( library_item_type ) + item_types = { 'library': trans.app.model.Library, + 'folder': trans.app.model.LibraryFolder, + 'library_dataset': trans.app.model.LibraryDataset } + if item_type not in item_types: + msg = 'Bad item_type specified: %s' % str( item_type ) messagetype = 'error' else: - if library_item_type == 'library_dataset': - library_item_desc = 'Dataset' + if item_type == 'library_dataset': + item_desc = 'Dataset' else: - library_item_desc = library_item_type.capitalize() - library_item = trans.sa_session.query( library_item_types[ library_item_type ] ).get( trans.security.decode_id( library_item_id ) ) + item_desc = item_type.capitalize() + library_item = trans.sa_session.query( item_types[ item_type ] ).get( trans.security.decode_id( item_id ) ) library_item.deleted = True trans.sa_session.add( library_item ) trans.sa_session.flush() - msg = util.sanitize_text( "%s '%s' has been marked deleted" % ( library_item_desc, library_item.name ) ) + msg = util.sanitize_text( "%s '%s' has been marked deleted" % ( item_desc, library_item.name ) ) messagetype = 'done' - if library_item_type == 'library': + if item_type == 'library': return self.browse_libraries( trans, message=msg, status=messagetype ) else: return trans.response.send_redirect( web.url_for( controller='library_common', @@ -200,31 +200,31 @@ messagetype=messagetype ) ) @web.expose @web.require_admin - def undelete_library_item( self, trans, library_id, library_item_id, library_item_type, **kwd ): + def undelete_library_item( self, trans, library_id, item_id, 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 } - if library_item_type not in library_item_types: - msg = 'Bad library_item_type specified: %s' % str( library_item_type ) + item_types = { 'library': trans.app.model.Library, + 'folder': trans.app.model.LibraryFolder, + 'library_dataset': trans.app.model.LibraryDataset } + if item_type not in item_types: + msg = 'Bad item_type specified: %s' % str( item_type ) status = ERROR else: - if library_item_type == 'library_dataset': - library_item_desc = 'Dataset' + if item_type == 'library_dataset': + item_desc = 'Dataset' else: - library_item_desc = library_item_type.capitalize() - library_item = trans.sa_session.query( library_item_types[ library_item_type ] ).get( trans.security.decode_id( library_item_id ) ) + item_desc = item_type.capitalize() + library_item = trans.sa_session.query( item_types[ item_type ] ).get( trans.security.decode_id( item_id ) ) if library_item.purged: - msg = '%s %s has been purged, so it cannot be undeleted' % ( library_item_desc, library_item.name ) + msg = '%s %s has been purged, so it cannot be undeleted' % ( item_desc, library_item.name ) status = ERROR else: library_item.deleted = False trans.sa_session.add( library_item ) trans.sa_session.flush() - msg = util.sanitize_text( "%s '%s' has been marked undeleted" % ( library_item_desc, library_item.name ) ) + msg = util.sanitize_text( "%s '%s' has been marked undeleted" % ( item_desc, library_item.name ) ) status = SUCCESS - if library_item_type == 'library': + if item_type == 'library': return self.browse_libraries( trans, message=msg, status=status ) else: return trans.response.send_redirect( web.url_for( controller='library_common', diff -r 4a6bb3b64012 -r a3e6350ffc57 lib/galaxy/web/controllers/library_common.py --- a/lib/galaxy/web/controllers/library_common.py Thu Feb 11 09:25:29 2010 -0500 +++ b/lib/galaxy/web/controllers/library_common.py Thu Feb 11 14:26:25 2010 -0500 @@ -6,7 +6,7 @@ from galaxy.util.json import to_json_string from galaxy.tools.actions import upload_common from galaxy.web.controllers.forms import get_all_forms -from galaxy.web.form_builder import SelectField +from galaxy.web.form_builder import SelectField, CheckboxField from galaxy.model.orm import * from galaxy.util.streamball import StreamBall import logging, tempfile, zipfile, tarfile, os, sys @@ -126,6 +126,7 @@ library_id = params.get( 'id', None ) library = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( library_id ) ) # See if we have any associated templates + info_association, inherited = library.get_info_association() 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 ) ) @@ -158,6 +159,8 @@ widgets=widgets, current_user_roles=current_user_roles, show_deleted=show_deleted, + info_association=info_association, + inherited=inherited, msg=msg, messagetype=messagetype ) @web.expose @@ -202,8 +205,8 @@ 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: + parent_folder = trans.sa_session.query( trans.app.model.LibraryFolder ).get( trans.security.decode_id( parent_id ) ) + if not parent_folder: msg = "Invalid parent folder id (%s) specified" % str( parent_id ) return trans.response.send_redirect( web.url_for( controller='library_common', action='browse_library', @@ -212,19 +215,41 @@ show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='error' ) ) - if params.new == 'submitted': + if params.get( 'new_folder_button', False ): new_folder = trans.app.model.LibraryFolder( name=util.restore_text( params.name ), description=util.restore_text( params.description ) ) # We are associating the last used genome build with folders, so we will always # initialize a new folder with the first dbkey in util.dbnames which is currently # ? unspecified (?) new_folder.genome_build = util.dbnames.default_value - folder.add_folder( new_folder ) + parent_folder.add_folder( new_folder ) trans.sa_session.add( new_folder ) trans.sa_session.flush() # New folders default to having the same permissions as their parent folder - trans.app.security_agent.copy_library_permissions( folder, new_folder ) - msg = "New folder named '%s' has been added to the library" % new_folder.name + trans.app.security_agent.copy_library_permissions( parent_folder, new_folder ) + # If we have an inheritable template, redirect to the folder_info page so information + # can be filled in immediately. + widgets = [] + info_association, inherited = new_folder.get_info_association() + if info_association and ( not( inherited ) or info_association.inheritable ): + widgets = new_folder.get_template_widgets( trans ) + if info_association: + current_user_roles = trans.get_current_user_roles() + msg = "The new folder named '%s' has been added to the data library. " % new_folder.name + msg += "Additional information about this folder may be added using the inherited template." + return trans.fill_template( '/library/common/folder_info.mako', + cntrller=cntrller, + folder=new_folder, + library_id=library_id, + widgets=widgets, + current_user_roles=current_user_roles, + show_deleted=show_deleted, + info_association=info_association, + inherited=inherited, + msg=msg, + messagetype='done' ) + # If not inheritable info_association, redirect to the library. + msg = "The new folder named '%s' has been added to the library" % new_folder.name return trans.response.send_redirect( web.url_for( controller='library_common', action='browse_library', cntrller=cntrller, @@ -232,10 +257,12 @@ show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype='done' ) ) + # We do not render any template widgets on creation pages since saving the info_association + # cannot occur before the associated item is saved. return trans.fill_template( '/library/common/new_folder.mako', cntrller=cntrller, library_id=library_id, - folder=folder, + folder=parent_folder, show_deleted=show_deleted, msg=msg, messagetype=messagetype ) @@ -248,7 +275,10 @@ 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 - widgets = folder.get_template_widgets( trans ) + widgets = [] + info_association, inherited = folder.get_info_association() + if info_association and ( not( inherited ) or info_association.inheritable ): + widgets = folder.get_template_widgets( trans ) if params.get( 'rename_folder_button', False ): if cntrller=='library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, folder ): old_name = folder.name @@ -274,6 +304,8 @@ widgets=widgets, current_user_roles=current_user_roles, show_deleted=show_deleted, + info_association=info_association, + inherited=inherited, msg=msg, messagetype=messagetype ) @web.expose @@ -354,7 +386,10 @@ file_formats = [ dtype_name for dtype_name, dtype_value in trans.app.datatypes_registry.datatypes_by_extension.iteritems() if dtype_value.allow_datatype_change ] file_formats.sort() # See if we have any associated templates - widgets = ldda.get_template_widgets( trans ) + widgets = [] + info_association, inherited = ldda.get_info_association() + if info_association and ( not( inherited ) or info_association.inheritable ): + widgets = ldda.get_template_widgets( trans ) if params.get( 'change', False ): # The user clicked the Save button on the 'Change data type' form if cntrller=='library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, ldda ): @@ -369,16 +404,6 @@ else: msg = "You are not authorized to change the data type of dataset '%s'" % ldda.name messagetype = 'error' - return trans.fill_template( "/library/common/ldda_edit_info.mako", - cntrller=cntrller, - ldda=ldda, - library_id=library_id, - 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 ): # The user clicked the Save button on the 'Edit Attributes' form if cntrller=='library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, ldda ): @@ -411,16 +436,6 @@ else: msg = "You are not authorized to edit the attributes of dataset '%s'" % ldda.name messagetype = 'error' - return trans.fill_template( "/library/common/ldda_edit_info.mako", - cntrller=cntrller, - ldda=ldda, - library_id=library_id, - 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 ): # The user clicked the Auto-detect button on the 'Edit Attributes' form if cntrller=='library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, ldda ): @@ -437,16 +452,6 @@ else: msg = "You are not authorized to edit the attributes of dataset '%s'" % ldda.name messagetype = 'error' - return trans.fill_template( "/library/common/ldda_edit_info.mako", - cntrller=cntrller, - ldda=ldda, - library_id=library_id, - 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 ): if "dbkey" in ldda.datatype.metadata_spec and not ldda.metadata.dbkey: # Copy dbkey into metadata, for backwards compatability @@ -463,10 +468,12 @@ widgets=widgets, current_user_roles=current_user_roles, show_deleted=show_deleted, + info_association=info_association, + inherited=inherited, msg=msg, messagetype=messagetype ) @web.expose - def ldda_display_info( self, trans, cntrller, library_id, folder_id, id, **kwd ): + def ldda_info( self, trans, cntrller, library_id, folder_id, id, **kwd ): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) @@ -483,7 +490,10 @@ messagetype='error' ) ) library = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( library_id ) ) # See if we have any associated templates - widgets = ldda.get_template_widgets( trans ) + widgets = [] + info_association, inherited = ldda.get_info_association() + if info_association and ( not( inherited ) or info_association.inheritable ): + widgets = ldda.get_template_widgets( trans ) current_user_roles = trans.get_current_user_roles() return trans.fill_template( '/library/common/ldda_info.mako', cntrller=cntrller, @@ -492,6 +502,8 @@ show_deleted=show_deleted, widgets=widgets, current_user_roles=current_user_roles, + info_association=info_association, + inherited=inherited, msg=msg, messagetype=messagetype ) @web.expose @@ -656,7 +668,7 @@ if not error: # See if we have any inherited templates, but do not inherit contents. info_association, inherited = folder.get_info_association( inherited=True ) - if info_association: + if info_association and info_association.inheritable: template_id = str( info_association.template.id ) widgets = folder.get_template_widgets( trans, get_contents=False ) else: @@ -718,7 +730,11 @@ msg=util.sanitize_text( msg ), messagetype=messagetype ) ) # See if we have any inherited templates, but do not inherit contents. - widgets = folder.get_template_widgets( trans, get_contents=False ) + info_association, inherited = folder.get_info_association( inherited=True ) + if info_association and info_association.inheritable: + widgets = folder.get_template_widgets( trans, get_contents=False ) + else: + widgets = [] upload_option = params.get( 'upload_option', 'upload_file' ) # No dataset(s) specified, so display the upload form. Send list of data formats to the form # so the "extension" select list can be populated dynamically @@ -1071,6 +1087,11 @@ msg=util.sanitize_text( msg ), messagetype='error' ) ) current_user_roles = trans.get_current_user_roles() + # See if we have any associated templates + widgets = [] + info_association, inherited = library_dataset.library_dataset_dataset_association.get_info_association() + if info_association and ( not( inherited ) or info_association.inheritable ): + widgets = library_dataset.library_dataset_dataset_association.get_template_widgets( trans ) if params.get( 'edit_attributes_button', False ): if cntrller=='library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, library_dataset ): if params.get( 'edit_attributes_button', False ): @@ -1095,6 +1116,9 @@ library_dataset=library_dataset, library_id=library_id, current_user_roles=current_user_roles, + info_association=info_association, + inherited=inherited, + widgets=widgets, show_deleted=show_deleted, msg=msg, messagetype=messagetype ) @@ -1280,63 +1304,83 @@ show_deleted=show_deleted, msg=util.sanitize_text( msg ), messagetype=messagetype ) ) + def get_item_and_stuff( self, trans, item_type, library_id, folder_id, ldda_id ): + # Return an item, description, action and an id based on the item_type. + if item_type == 'library': + item = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( library_id ) ) + 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 ) ) + 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 ) ) + item_desc = 'dataset' + action = 'ldda_edit_info' + id = ldda_id + else: + msg = "Invalid library item type ( %s )" % 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' ) ) + return item, item_desc, action, id @web.expose - 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. + def add_template( self, trans, cntrller, item_type, library_id, folder_id=None, ldda_id=None, **kwd ): + # Template can only be added to a Library, Folder or LibraryDatasetDatasetAssociation. forms = get_all_forms( trans, filter=dict( deleted=False ), form_type=trans.app.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE ) if not forms: - msg = "There are no forms on which to base the template, so create a form and try to add the template again." + msg = "There are no forms on which to base the template, so create a form and then add the template." trans.response.send_redirect( web.url_for( controller='forms', action='new', 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 = trans.sa_session.query( trans.app.model.FormDefinition ).get( trans.security.decode_id( params.form_id ) ) - form_values = trans.app.model.FormValues( form, [] ) - trans.sa_session.add( form_values ) - trans.sa_session.flush() - 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 = 'A 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=action, - cntrller=cntrller, - library_id=library_id, - folder_id=folder_id, - id=id, - show_deleted=show_deleted, - msg=msg, - messagetype='done' ) ) + else: + 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' ) + item, item_desc, action, id = self.get_item_and_stuff( trans, item_type, library_id, folder_id, ldda_id ) + # If the inheritable checkbox is checked, the param will be in the request + inheritable = CheckboxField.is_checked( params.get( 'inheritable', '' ) ) + if params.get( 'add_template_button', False ): + form_id = params.get( 'form_id', 'none' ) + if form_id not in [ None, 'None', 'none' ]: + form = trans.sa_session.query( trans.app.model.FormDefinition ).get( trans.security.decode_id( form_id ) ) + form_values = trans.app.model.FormValues( form, [] ) + trans.sa_session.add( form_values ) + trans.sa_session.flush() + if item_type == 'library': + assoc = trans.app.model.LibraryInfoAssociation( item, form, form_values, inheritable=inheritable ) + elif item_type == 'folder': + assoc = trans.app.model.LibraryFolderInfoAssociation( item, form, form_values, inheritable=inheritable ) + elif item_type == 'ldda': + assoc = trans.app.model.LibraryDatasetDatasetInfoAssociation( item, form, form_values ) + trans.sa_session.add( assoc ) + trans.sa_session.flush() + msg = 'A template based on the form "%s" has been added to this %s.' % ( form.name, item_desc ) + 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=msg, + messagetype='done' ) ) + else: + msg = "Select a form on which to base the template." + messagetype = "error" def generate_template_stuff( trans, forms, form_id ): # Returns the following: # - a list of template ids @@ -1367,10 +1411,10 @@ template_ids, widgets, template_select_list = generate_template_stuff( trans, forms, kwd.get( 'form_id' ) ) else: template_ids, widgets, template_select_list = generate_template_stuff( trans, forms, 'none' ) - return trans.fill_template( '/library/common/select_info_template.mako', + return trans.fill_template( '/library/common/select_template.mako', cntrller=cntrller, - library_item_name=item.name, - library_item_desc=library_item_desc, + item_name=item.name, + item_desc=item_desc, item_type=item_type, library_id=library_id, folder_id=folder_id, @@ -1378,37 +1422,85 @@ template_ids=template_ids, widgets=widgets, template_select_list=template_select_list, + inheritable_checked=inheritable, show_deleted=show_deleted, msg=msg, messagetype=messagetype ) @web.expose - def edit_template_info( self, trans, cntrller, item_type, library_id, num_widgets, folder_id=None, ldda_id=None, **kwd ): + def manage_template_inheritance( self, trans, cntrller, item_type, library_id, 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' ) - 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 ) + item, item_desc, action, id = self.get_item_and_stuff( trans, item_type, library_id, folder_id, ldda_id ) + info_association, inherited = item.get_info_association( restrict=True ) + if info_association: + if info_association.inheritable: + msg = "The template for this %s will no longer be inherited to contained folders and datasets." % item_desc + else: + msg = "The template for this %s will now be inherited to contained folders and datasets." % item_desc + info_association.inheritable = not( info_association.inheritable ) + trans.sa_session.add( info_association ) + trans.sa_session.flush() + 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='done' ) ) + @web.expose + def edit_template( self, trans, cntrller, item_type, library_id, folder_id=None, ldda_id=None, edited=False, **kwd ): + # Edit the template itself, keeping existing field contents, if any. + 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' ) + item, item_desc, action, id = self.get_item_and_stuff( trans, item_type, library_id, folder_id, ldda_id ) + # An info_association must exist at this point + info_association, inherited = item.get_info_association( restrict=True ) + template = info_association.template + info = info_association.info + form_values = trans.sa_session.query( trans.app.model.FormValues ).get( info.id ) + if edited: + # The form on which the template is based has been edited, so we need to update the + # info_association with the current form + fdc = trans.sa_session.query( trans.app.model.FormDefinitionCurrent ).get( template.form_definition_current_id ) + info_association.template = fdc.latest_form + trans.sa_session.add( info_association ) + trans.sa_session.flush() + msg = "The template for this %s has been updated with your changes." % item_desc return trans.response.send_redirect( web.url_for( controller='library_common', - action='browse_library', + action=action, cntrller=cntrller, - id=library_id, + library_id=library_id, + folder_id=folder_id, + id=id, show_deleted=show_deleted, msg=util.sanitize_text( msg ), - messagetype='error' ) ) + messagetype='done' ) ) + # "template" is a FormDefinition, so since we're changing it, we need to use the latest version of it. + vars = dict( id=trans.security.encode_id( template.form_definition_current_id ), + response_redirect=web.url_for( controller='library_common', + action='edit_template', + cntrller=cntrller, + item_type=item_type, + library_id=library_id, + folder_id=folder_id, + ldda_id=ldda_id, + edited=True, + **kwd ) ) + return trans.response.send_redirect( web.url_for( controller='forms', action='edit', **vars ) ) + @web.expose + def edit_template_info( self, trans, cntrller, item_type, library_id, num_widgets, folder_id=None, ldda_id=None, **kwd ): + # Edit the contents of the template fields without altering the template itself. + 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' ) + item, item_desc, action, id = self.get_item_and_stuff( trans, item_type, library_id, folder_id, ldda_id ) # Save updated template field contents field_contents = [] for index in range( int( num_widgets ) ): @@ -1439,10 +1531,17 @@ trans.sa_session.flush() # Create a new info_association between the current library item and form_values if item_type == 'folder': - info_association = trans.app.model.LibraryFolderInfoAssociation( item, template, form_values ) + # A LibraryFolder is a special case because if it inherited the template from it's parent, + # we want to set inheritable to True for it's info_association. This allows for the default + # inheritance to be False for each level in the Library hierarchy unless we're creating a new + # level in the hierarchy, in which case we'll inherit the "inheritable" setting from the parent + # level. + info_association = trans.app.model.LibraryFolderInfoAssociation( item, template, form_values, inheritable=inherited ) trans.sa_session.add( info_association ) trans.sa_session.flush() elif item_type == 'ldda': + # TODO: Currently info_associations at teh ldda level are not inheritable to the associated LibraryDataset. + # We need to figure out if this is optimal. info_association = trans.app.model.LibraryDatasetDatasetInfoAssociation( item, template, form_values ) trans.sa_session.add( info_association ) trans.sa_session.flush() @@ -1457,35 +1556,14 @@ 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 ): + def delete_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' ) ) + item, item_desc, action, id = self.get_item_and_stuff( trans, item_type, library_id, folder_id, ldda_id ) info_association, inherited = item.get_info_association() if not info_association: msg = "There is no template for this %s" % item_type diff -r 4a6bb3b64012 -r a3e6350ffc57 lib/galaxy/web/form_builder.py --- a/lib/galaxy/web/form_builder.py Thu Feb 11 09:25:29 2010 -0500 +++ b/lib/galaxy/web/form_builder.py Thu Feb 11 14:26:25 2010 -0500 @@ -101,7 +101,9 @@ @staticmethod def is_checked( value ): if value == True: - return value + return True + if isinstance( value, basestring ) and value.lower() in ( "yes", "true", "on" ): + return True # This may look strange upon initial inspection, but see the comments in the get_html() method # above for clarification. Basically, if value is not True, then it will always be a list with # 2 input fields ( a checkbox and a hidden field ) if the checkbox is checked. If it is not diff -r 4a6bb3b64012 -r a3e6350ffc57 templates/admin/forms/edit_form.mako --- a/templates/admin/forms/edit_form.mako Thu Feb 11 09:25:29 2010 -0500 +++ b/templates/admin/forms/edit_form.mako Thu Feb 11 14:26:25 2010 -0500 @@ -96,7 +96,6 @@ </div> </div> </div> - </%def> <%def name="render_layout( index, widget )"> @@ -111,10 +110,18 @@ <div class="toolForm"> <div class="toolFormTitle">Edit form definition "${form.name}"</div> - <form id="edit_form" name="edit_form" action="${h.url_for( controller='forms', action='manage', operation="Edit", id=trans.security.encode_id(form.current.id) )}" method="post" > + <form id="edit_form" name="edit_form" action="${h.url_for( controller='forms', action='edit', id=trans.security.encode_id(form.current.id) )}" method="post" > + %if response_redirect: + <input type="hidden" name="response_redirect" value="${response_redirect}" size="40" /> + %endif %for label, input in form_details: <div class="form-row"> - <label>${label}</label> + ## TODO: RC, this will keep the form type select list label + ## from being displayed here. At this point, the select list is a hidden field. + ## Make sure this is the best solution to this problem. + %if label != 'Type': + <label>${label}</label> + %endif <div style="float: left; width: 250px; margin-right: 10px;"> ${input.get_html()} </div> diff -r 4a6bb3b64012 -r a3e6350ffc57 templates/library/common/browse_library.mako --- a/templates/library/common/browse_library.mako Thu Feb 11 09:25:29 2010 -0500 +++ b/templates/library/common/browse_library.mako Thu Feb 11 14:26:25 2010 -0500 @@ -158,8 +158,8 @@ if ldda == library_dataset.library_dataset_dataset_association: current_version = True if cntrller in [ 'library', 'requests' ]: - can_modify_library_dataset = trans.app.security_agent.can_modify_library_item( current_user_roles, library_dataset ) - can_manage_library_dataset = trans.app.security_agent.can_manage_library_item( current_user_roles, library_dataset ) + can_modify = trans.app.security_agent.can_modify_library_item( current_user_roles, library_dataset ) + can_manage = trans.app.security_agent.can_manage_library_item( current_user_roles, library_dataset ) else: current_version = False if current_version and ldda.state not in ( 'ok', 'error', 'empty', 'deleted', 'discarded' ): @@ -182,27 +182,28 @@ %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> + <a href="${h.url_for( controller='library_common', action='ldda_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 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> + %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and ( cntrller == 'library_admin' or can_modify ): + <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 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 ), show_deleted=show_deleted )}">View this dataset's information</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_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 information</a> %endif - %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 a template to this dataset</a> + %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and ( ( cntrller == 'library_admin' or can_modify ) and not info_association ): + <a class="action-button" href="${h.url_for( controller='library_common', action='add_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</a> %endif - %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> + %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and ( ( cntrller == 'library_admin' or can_modify ) and info_association ): + <a class="action-button" href="${h.url_for( controller='library_common', action='edit_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 )}">Edit template</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='delete_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 template</a> %endif - %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> + %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and ( cntrller == 'library_admin' or can_manage ): + <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 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 ): + %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and ( cntrller == 'library_admin' or can_modify ): <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: @@ -211,9 +212,9 @@ %endif %if cntrller in [ 'library_admin', 'requests_admin' ]: %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> + <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 ), item_id=trans.security.encode_id( library_dataset.id ), 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> + <a class="action-button" href="${h.url_for( controller='library_admin', action='undelete_library_item', library_id=trans.security.encode_id( library.id ), item_id=trans.security.encode_id( library_dataset.id ), item_type='library_dataset', show_deleted=show_deleted )}">Undelete this dataset</a> %endif %endif </div> @@ -284,27 +285,28 @@ %endif <a id="folder_img-${folder.id}-popup" class="popup-arrow" style="display: none;">▼</a> <div popupmenu="folder_img-${folder.id}-popup"> - %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> + %if not branch_deleted( folder ) and ( cntrller == 'library_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</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 )}">Add sub-folder</a> %endif - %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> + %if not branch_deleted( folder ) and ( cntrller == 'library_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 information</a> %endif - %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 a template to this folder</a> + %if not branch_deleted( folder ) and ( ( cntrller == 'library_admin' or can_modify ) and not info_association ): + <a class="action-button" href="${h.url_for( controller='library_common', action='add_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</a> %endif - %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> + %if not branch_deleted( folder ) and ( ( cntrller == 'library_admin' or can_modify ) and info_association ): + <a class="action-button" href="${h.url_for( controller='library_common', action='edit_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 )}">Edit template</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='delete_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 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> + %if not branch_deleted( folder ) and ( cntrller == 'library_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 permissions</a> %endif %if cntrller in [ 'library_admin', 'requests_admin' ]: %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> + <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, item_id=trans.security.encode_id( folder.id ), item_type='folder', show_deleted=show_deleted )}">Delete this folder</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> + <a class="action-button" href="${h.url_for( controller='library_admin', action='undelete_library_item', library_id=library_id, item_id=trans.security.encode_id( folder.id ), item_type='folder', show_deleted=show_deleted )}">Undelete this folder</a> %endif %endif </div> @@ -376,22 +378,19 @@ %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 ), 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 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> + %if ( cntrller == 'library_admin' or can_modify ) and not library.info_association: + <a class="action-button" href="${h.url_for( controller='library_common', action='add_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> + %if ( cntrller == 'library_admin' or can_modify ) and info_association: + <a class="action-button" href="${h.url_for( controller='library_common', action='edit_template', cntrller=cntrller, item_type='library', library_id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}">Edit template</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='delete_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 ), 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> + <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 ), item_id=trans.security.encode_id( library.id ), item_type='library' )}">Delete this data library</a> %endif %if show_deleted: <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=False )}">Hide deleted items</a> @@ -399,7 +398,9 @@ <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=True )}">Show deleted items</a> %endif %elif cntrller == 'library_admin' and not library.purged: - <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.id ), library_item_type='library' )}">Undelete this data library</a> + <a class="action-button" href="${h.url_for( controller='library_admin', action='undelete_library_item', library_id=trans.security.encode_id( library.id ), item_id=trans.security.encode_id( library.id ), item_type='library' )}">Undelete this data library</a> + %elif library.purged: + <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 )}">This data library has been purged</a> %endif </div> </th> diff -r 4a6bb3b64012 -r a3e6350ffc57 templates/library/common/common.mako --- a/templates/library/common/common.mako Thu Feb 11 09:25:29 2010 -0500 +++ b/templates/library/common/common.mako Thu Feb 11 14:26:25 2010 -0500 @@ -1,4 +1,4 @@ -<%def name="render_template_info( cntrller, item_type, library_id, widgets, folder_id=None, ldda_id=None, editable=True )"> +<%def name="render_template_info( cntrller, item_type, library_id, widgets, info_association, inherited, folder_id=None, ldda_id=None, editable=True )"> <% if item_type == 'library': item = trans.sa_session.query( trans.app.model.Library ).get( trans.security.decode_id( library_id ) ) @@ -8,12 +8,35 @@ 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() + can_modify = trans.app.security_agent.can_modify_library_item( current_user_roles, item ) %> %if widgets: - %if editable and ( cntrller=='library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, item ) ): - <p/> - <div class="toolForm"> - <div class="toolFormTitle">Other information about ${item.name}</div> + <p/> + <div class="toolForm"> + %if editable and ( cntrller=='library_admin' or trans.app.security_agent.can_modify_library_item( current_user_roles, item ) ): + <div class="toolFormTitle"> + %if inherited: + Other information <i>- this is an inherited template and is not required to be used with this ${item_type}</i> + %else: + Other information + %endif + %if info_association and not inherited and ( cntrller == 'library_admin' or can_modify ): + ## "inherited" will be true only if the info_association is not associated with the current item, + ## in which case we do not want to render the following popup menu. + <a id="item-${item.id}-popup" class="popup-arrow" style="display: none;">▼</a> + <div popupmenu="item-${item.id}-popup"> + <a class="action-button" href="${h.url_for( controller='library_common', action='edit_template', cntrller=cntrller, item_type=item_type, library_id=library_id, folder_id=folder_id, ldda_id=ldda_id, show_deleted=show_deleted )}">Edit template</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='delete_template', cntrller=cntrller, item_type=item_type, library_id=library_id, folder_id=folder_id, ldda_id=ldda_id, show_deleted=show_deleted )}">Delete template</a> + %if item_type not in [ 'ldda', 'library_dataset' ]: + %if info_association.inheritable: + <a class="action-button" href="${h.url_for( controller='library_common', action='manage_template_inheritance', cntrller=cntrller, item_type=item_type, library_id=library_id, folder_id=folder_id, ldda_id=ldda_id, show_deleted=show_deleted )}">Dis-inherit template</a> + %else: + <a class="action-button" href="${h.url_for( controller='library_common', action='manage_template_inheritance', cntrller=cntrller, item_type=item_type, library_id=library_id, folder_id=folder_id, ldda_id=ldda_id, show_deleted=show_deleted )}">Inherit template</a> + %endif + %endif + </div> + %endif + </div> <div class="toolFormBody"> <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 ): @@ -31,36 +54,36 @@ </div> </form> </div> - </div> - %else: - <% contents = False %> - %for i, field in enumerate( widgets ): - %if field[ 'widget' ].value: - <% - contents = True - break - %> + %else: + <% contents = False %> + %for i, field in enumerate( widgets ): + %if field[ 'widget' ].value: + <% + contents = True + break + %> + %endif + %endfor + %if contents: + <div class="toolForm"> + <div class="toolFormTitle">Other information about ${item.name}</div> + <div class="toolFormBody"> + %for i, field in enumerate( widgets ): + %if field[ 'widget' ].value: + <div class="form-row"> + <label>${field[ 'label' ]}</label> + <pre>${field[ 'widget' ].value}</pre> + <div class="toolParamHelp" style="clear: both;"> + ${field[ 'helptext' ]} + </div> + <div style="clear: both"></div> + </div> + %endif + %endfor + </div> %endif - %endfor - %if contents: - <div class="toolForm"> - <div class="toolFormTitle">Other information about ${item.name}</div> - <div class="toolFormBody"> - %for i, field in enumerate( widgets ): - %if field[ 'widget' ].value: - <div class="form-row"> - <label>${field[ 'label' ]}</label> - <pre>${field[ 'widget' ].value}</pre> - <div class="toolParamHelp" style="clear: both;"> - ${field[ 'helptext' ]} - </div> - <div style="clear: both"></div> - </div> - %endif - %endfor - </div> %endif - %endif + </div> %endif </%def> @@ -85,7 +108,7 @@ %if replace_dataset not in [ None, 'None' ]: <input type="hidden" name="replace_id" value="${trans.security.encode_id( replace_dataset.id )}"/> <div class="form-row"> - You are currently selecting a new file to replace '<a href="${h.url_for( controller='library_common', action='ldda_display_info', cntrller=cntrller, library_id=library_id, folder_id=folder_id, id=trans.security.encode_id( replace_dataset.library_dataset_dataset_association.id ) )}">${replace_dataset.name}</a>'. + You are currently selecting a new file to replace '<a href="${h.url_for( controller='library_common', action='ldda_info', cntrller=cntrller, library_id=library_id, folder_id=folder_id, id=trans.security.encode_id( replace_dataset.library_dataset_dataset_association.id ) )}">${replace_dataset.name}</a>'. <div style="clear: both"></div> </div> %endif @@ -277,7 +300,10 @@ ${field[ 'widget' ].get_html()} </div> <div class="toolParamHelp" style="clear: both;"> - ${field[ 'helptext' ]}, leave blank to add a different template to this dataset after upload. + %if field[ 'helptext' ]: + ${field[ 'helptext' ]}<br/> + %endif + *Inherited template field </div> <div style="clear: both"></div> </div> @@ -307,7 +333,7 @@ %if replace_dataset not in [ None, 'None' ]: <input type="hidden" name="replace_id" value="${trans.security.encode_id( replace_dataset.id )}"/> <div class="form-row"> - You are currently selecting a new file to replace '<a href="${h.url_for( controller='library_common', action='ldda_display_info', cntrller=cntrller, library_id=library_id, folder_id=folder_id, id=trans.security.encode_id( replace_dataset.library_dataset_dataset_association.id ) )}">${replace_dataset.name}</a>'. + You are currently selecting a new file to replace '<a href="${h.url_for( controller='library_common', action='ldda_info', cntrller=cntrller, library_id=library_id, folder_id=folder_id, id=trans.security.encode_id( replace_dataset.library_dataset_dataset_association.id ) )}">${replace_dataset.name}</a>'. <div style="clear: both"></div> </div> %endif diff -r 4a6bb3b64012 -r a3e6350ffc57 templates/library/common/edit_template.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/library/common/edit_template.mako Thu Feb 11 14:26:25 2010 -0500 @@ -0,0 +1,35 @@ +<%inherit file="/base.mako"/> +<%namespace file="/message.mako" import="render_msg" /> + +<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, show_deleted=show_deleted )}"><span>Browse this data library</span></a> + </li> +</ul> + +%if msg: + ${render_msg( msg, messagetype )} +%endif + +<div class="toolForm"> + <div class="toolFormTitle">Edit the template for the ${item_desc} '${item_name}'</div> + <form id="edit_template" name="edit_template" action="${h.url_for( controller='library_common', action='edit_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"> + %for i, field in enumerate( widgets ): + <div class="form-row"> + <label>${field[ 'label' ]}</label> + ${field[ 'widget' ].get_html()} + <div class="toolParamHelp" style="clear: both;"> + ${field[ 'helptext' ]} + </div> + <div style="clear: both"></div> + </div> + %endfor + <div style="clear: both"></div> + <div class="form-row"> + <input type="submit" name="edit_template_button" value="Save"/> + </div> + </div> + </form> +</div> diff -r 4a6bb3b64012 -r a3e6350ffc57 templates/library/common/folder_info.mako --- a/templates/library/common/folder_info.mako Thu Feb 11 09:25:29 2010 -0500 +++ b/templates/library/common/folder_info.mako Thu Feb 11 14:26:25 2010 -0500 @@ -47,5 +47,5 @@ </div> </div> %if widgets: - ${render_template_info( cntrller=cntrller, item_type='folder', library_id=library_id, widgets=widgets, folder_id=trans.security.encode_id( folder.id ) )} + ${render_template_info( cntrller=cntrller, item_type='folder', library_id=library_id, widgets=widgets, info_association=info_association, inherited=inherited, folder_id=trans.security.encode_id( folder.id ) )} %endif diff -r 4a6bb3b64012 -r a3e6350ffc57 templates/library/common/ldda_edit_info.mako --- a/templates/library/common/ldda_edit_info.mako Thu Feb 11 09:25:29 2010 -0500 +++ b/templates/library/common/ldda_edit_info.mako Thu Feb 11 14:26:25 2010 -0500 @@ -161,5 +161,5 @@ </div> %endif %if 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 ) )} + ${render_template_info( cntrller=cntrller, item_type='ldda', library_id=library_id, widgets=widgets, info_association=info_association, inherited=inherited, folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), ldda_id=trans.security.encode_id( ldda.id ) )} %endif diff -r 4a6bb3b64012 -r a3e6350ffc57 templates/library/common/ldda_info.mako --- a/templates/library/common/ldda_info.mako Thu Feb 11 09:25:29 2010 -0500 +++ b/templates/library/common/ldda_info.mako Thu Feb 11 14:26:25 2010 -0500 @@ -13,7 +13,9 @@ uploaded_by = ldda.user.email else: uploaded_by = 'anonymous' - info_association, inherited = ldda.get_info_association( restrict=True ) + if cntrller in [ 'library', 'requests' ]: + can_modify = trans.app.security_agent.can_modify_library_item( current_user_roles, ldda.library_dataset ) + can_manage = trans.app.security_agent.can_manage_library_item( current_user_roles, ldda.library_dataset ) %> %if current_version: @@ -39,18 +41,19 @@ %if not library.deleted and not branch_deleted( ldda.library_dataset.folder ) and not ldda.library_dataset.deleted: <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 ), show_deleted=show_deleted )}">Edit this dataset's information</a> + %if cntrller=='library_admin' or can_modify: + <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 information</a> %if 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( ldda.library_dataset.folder.id ), ldda_id=trans.security.encode_id( ldda.id ), show_deleted=show_deleted )}">Add a template to this dataset</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='add_template', cntrller=cntrller, item_type='ldda', library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), ldda_id=trans.security.encode_id( ldda.id ), show_deleted=show_deleted )}">Add template</a> %else: - <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( ldda.library_dataset.folder.id ), ldda_id=trans.security.encode_id( ldda.id ), show_deleted=show_deleted )}">Delete this dataset's template</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='edit_template', cntrller=cntrller, item_type='ldda', library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), ldda_id=trans.security.encode_id( ldda.id ), show_deleted=show_deleted )}">Edit template</a> + <a class="action-button" href="${h.url_for( controller='library_common', action='delete_template', cntrller=cntrller, item_type='ldda', library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( ldda.library_dataset.folder.id ), ldda_id=trans.security.encode_id( ldda.id ), show_deleted=show_deleted )}">Delete template</a> %endif %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', 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 permissions</a> + %if cntrller=='library_admin' or can_manage: + <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( ldda.library_dataset.folder.id ), id=trans.security.encode_id( ldda.id ), show_deleted=show_deleted )}">Edit 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 ) ): + %if current_version and ( cntrller=='library_admin' or can_modify ): <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: @@ -100,7 +103,7 @@ </div> </div> %if 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 ), editable=False )} + ${render_template_info( cntrller=cntrller, item_type='ldda', library_id=library_id, widgets=widgets, info_association=info_association, inherited=inherited, 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 ] %> @@ -108,7 +111,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 ), show_deleted=show_deleted )}">${expired_ldda.name}</a> + <a href="${h.url_for( controller='library_common', action='ldda_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 4a6bb3b64012 -r a3e6350ffc57 templates/library/common/library_dataset_info.mako --- a/templates/library/common/library_dataset_info.mako Thu Feb 11 09:25:29 2010 -0500 +++ b/templates/library/common/library_dataset_info.mako Thu Feb 11 14:26:25 2010 -0500 @@ -62,5 +62,6 @@ %endif %if widgets: - ${render_template_info( cntrller, library_dataset, library_id, '', widgets )} + ## Templates are not currently supported for library_datasets, only the associated ldda. + ${render_template_info( cntrller, 'library_dataset', library_id, widgets, info_association=None, inherited=False, editable=False )} %endif diff -r 4a6bb3b64012 -r a3e6350ffc57 templates/library/common/library_info.mako --- a/templates/library/common/library_info.mako Thu Feb 11 09:25:29 2010 -0500 +++ b/templates/library/common/library_info.mako Thu Feb 11 14:26:25 2010 -0500 @@ -7,7 +7,6 @@ can_add = trans.app.security_agent.can_add_library_item( current_user_roles, library ) 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 ) - info_association, inherited = library.get_info_association() %> <br/><br/> @@ -21,10 +20,32 @@ ${render_msg( msg, messagetype )} %endif -%if cntrller == 'library_admin' or can_modify: - <div class="toolForm"> - <div class="toolFormTitle">Change library name and description</div> - <div class="toolFormBody"> +<div class="toolForm"> + %if cntrller == 'library_admin' or can_add or can_modify or can_manage: + <div class="toolFormTitle"> + <a href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}"><b>${library.name[:50]}</b></a> + <a id="library-${library.id}-popup" class="popup-arrow" style="display: none;">▼</a> + <div popupmenu="library-${library.id}-popup"> + %if not library.deleted: + %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_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' 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 ), 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 ), item_id=trans.security.encode_id( library.id ), item_type='library' )}">Delete this data library</a> + %endif + %elif cntrller == 'library_admin' and not library.purged: + <a class="action-button" href="${h.url_for( controller='library_admin', action='undelete_library_item', library_id=trans.security.encode_id( library.id ), item_id=trans.security.encode_id( library.id ), item_type='library' )}">Undelete this data library</a> + %elif library.purged: + <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 )}">This data library has been purged</a> + %endif + </div> + </div> + %endif + <div class="toolFormBody"> + %if not library.deleted and ( cntrller == 'library_admin' or can_modify ): <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> @@ -44,42 +65,7 @@ <input type="submit" name="rename_library_button" value="Save"/> </div> </form> - </div> - </div> - <p/> -%else: - <div class="toolForm"> - <div class="toolFormTitle"> - %if cntrller == 'library_admin' or can_add or can_manage: - <th style="padding-left: 42px;"> - <a href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}"><b>${library.name[:50]}</b></a> - <a id="library-${library.id}-popup" class="popup-arrow" style="display: none;">▼</a> - <div popupmenu="library-${library.id}-popup"> - %if not library.deleted: - %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 ), 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> - %endif - %elif cntrller == 'library_admin' and not library.purged: - <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.id ), library_item_type='library' )}">Undelete this data library</a> - %endif - </div> - </th> - %else: - <th style="padding-left: 42px;"> - <a href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ), show_deleted=show_deleted )}"><b>${library.name[:50]}</b></a> - </th> - %endif - </div> - <div class="toolFormBody"> + %else: <div class="form-row"> <label>Name:</label> ${library.name} @@ -90,10 +76,10 @@ ${library.description} </div> <div style="clear: both"></div> - </div> + %endif </div> -%endif +</div> %if widgets: - ${render_template_info( cntrller=cntrller, item_type='library', library_id=trans.security.encode_id( library.id ), widgets=widgets )} + ${render_template_info( cntrller=cntrller, item_type='library', library_id=trans.security.encode_id( library.id ), widgets=widgets, info_association=info_association, inherited=inherited, editable=not( library.deleted ) )} %endif diff -r 4a6bb3b64012 -r a3e6350ffc57 templates/library/common/new_folder.mako --- a/templates/library/common/new_folder.mako Thu Feb 11 09:25:29 2010 -0500 +++ b/templates/library/common/new_folder.mako Thu Feb 11 14:26:25 2010 -0500 @@ -1,5 +1,6 @@ <%inherit file="/base.mako"/> <%namespace file="/message.mako" import="render_msg" /> +<%namespace file="/library/common/common.mako" import="render_template_info" /> <br/<br/> <ul class="manage-table-actions"> @@ -31,12 +32,6 @@ <div style="clear: both"></div> </div> <div class="form-row"> - <div style="float: left; width: 250px; margin-right: 10px;"> - <input type="hidden" name="new" value="submitted" size="40"/> - </div> - <div style="clear: both"></div> - </div> - <div class="form-row"> <input type="submit" name="new_folder_button" value="Create"/> </div> </form> diff -r 4a6bb3b64012 -r a3e6350ffc57 templates/library/common/select_info_template.mako --- a/templates/library/common/select_info_template.mako Thu Feb 11 09:25:29 2010 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -<%inherit file="/base.mako"/> -<%namespace file="/message.mako" import="render_msg" /> - -<script type="text/javascript"> -$( function() { - $( "select[refresh_on_change='true']").change( function() { - var refresh = false; - var refresh_on_change_values = $( this )[0].attributes.getNamedItem( 'refresh_on_change_values' ) - if ( refresh_on_change_values ) { - refresh_on_change_values = refresh_on_change_values.value.split( ',' ); - var last_selected_value = $( this )[0].attributes.getNamedItem( 'last_selected_value' ); - for( i= 0; i < refresh_on_change_values.length; i++ ) { - if ( $( this )[0].value == refresh_on_change_values[i] || ( last_selected_value && last_selected_value.value == refresh_on_change_values[i] ) ){ - refresh = true; - break; - } - } - } - else { - refresh = true; - } - if ( refresh ){ - $( "#select_info_template" ).submit(); - } - }); -}); -</script> - -<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, show_deleted=show_deleted )}"><span>Browse this data library</span></a> - </li> -</ul> - -%if msg: - ${render_msg( msg, messagetype )} -%endif - -<div class="toolForm"> - <div class="toolFormTitle">Select a template for the ${library_item_desc} '${library_item_name}'</div> - <form id="select_info_template" name="select_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"> - <table class="grid"> - <tr> - <div class="form-row"> - <td> - <input type="hidden" name="refresh" value="true" size="40"/> - <label>Template:</label> - ${template_select_list.get_html()} - </td> - <td> - <input type="submit" name="add_info_template_button" value="Add template to ${library_item_desc}"/> - </td> - </div> - </tr> - </table> - %if template_select_list.get_selected() != ('Select one', 'none'): - <div style="clear: both"></div> - <div class="form-row"> - %for i, field in enumerate( widgets ): - <div class="form-row"> - <label>${field[ 'label' ]}</label> - ${field[ 'widget' ].get_html()} - <div class="toolParamHelp" style="clear: both;"> - ${field[ 'helptext' ]} - </div> - <div style="clear: both"></div> - </div> - %endfor - </div> - %endif - </div> - </form> -</div> diff -r 4a6bb3b64012 -r a3e6350ffc57 templates/library/common/select_template.mako --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/library/common/select_template.mako Thu Feb 11 14:26:25 2010 -0500 @@ -0,0 +1,82 @@ +<%inherit file="/base.mako"/> +<%namespace file="/message.mako" import="render_msg" /> + +<script type="text/javascript"> +$( function() { + $( "select[refresh_on_change='true']").change( function() { + var refresh = false; + var refresh_on_change_values = $( this )[0].attributes.getNamedItem( 'refresh_on_change_values' ) + if ( refresh_on_change_values ) { + refresh_on_change_values = refresh_on_change_values.value.split( ',' ); + var last_selected_value = $( this )[0].attributes.getNamedItem( 'last_selected_value' ); + for( i= 0; i < refresh_on_change_values.length; i++ ) { + if ( $( this )[0].value == refresh_on_change_values[i] || ( last_selected_value && last_selected_value.value == refresh_on_change_values[i] ) ){ + refresh = true; + break; + } + } + } + else { + refresh = true; + } + if ( refresh ){ + $( "#select_template" ).submit(); + } + }); +}); +</script> + +<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, show_deleted=show_deleted )}"><span>Browse this data library</span></a> + </li> +</ul> + +%if msg: + ${render_msg( msg, messagetype )} +%endif + +<div class="toolForm"> + <div class="toolFormTitle">Select a template for the ${item_desc} '${item_name}'</div> + <div class="toolFormBody"> + <form id="select_template" name="select_template" action="${h.url_for( controller='library_common', action='add_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="form-row"> + <input type="hidden" name="refresh" value="true" size="40"/> + <label>Template:</label> + ${template_select_list.get_html()} + </div> + % if item_type in [ 'library', 'folder' ]: + <div class="form-row"> + <label>Inherit template to contained folders and datasets?</label> + %if inheritable_checked: + <input type="checkbox" name="inheritable" value="yes" checked/>Yes + %else: + <input type="checkbox" name="inheritable" value="yes"/>Yes + %endif + <div class="toolParamHelp" style="clear: both;"> + Check if you want this template to be used by other folders and datasets contained within this ${item_desc} + </div> + </div> + %endif + <div class="form-row"> + <input type="submit" name="add_template_button" value="Add template to ${item_desc}"/> + </div> + </form> + %if template_select_list.get_selected() != ('Select one', 'none'): + <div style="clear: both"></div> + <div class="form-row"> + %for i, field in enumerate( widgets ): + <div class="form-row"> + <label>${field[ 'label' ]}</label> + ${field[ 'widget' ].get_html()} + <div class="toolParamHelp" style="clear: both;"> + ${field[ 'helptext' ]} + </div> + <div style="clear: both"></div> + </div> + %endfor + </div> + %endif + </div> +</div> diff -r 4a6bb3b64012 -r a3e6350ffc57 test/base/twilltestcase.py --- a/test/base/twilltestcase.py Thu Feb 11 09:25:29 2010 -0500 +++ b/test/base/twilltestcase.py Thu Feb 11 14:26:25 2010 -0500 @@ -1384,7 +1384,7 @@ """Rename a library""" self.home() self.visit_url( "%s/library_common/library_info?id=%s&cntrller=%s" % ( self.url, library_id, controller ) ) - self.check_page_for_string( 'Change library name and description' ) + self.check_page_for_string( old_name ) # Since twill barfs on the form submisson, we ar forced to simulate it url = "%s/library_common/library_info?id=%s&cntrller=%s&rename_library_button=Save&description=%s&name=%s" % \ ( self.url, library_id, controller, description.replace( ' ', '+' ), name.replace( ' ', '+' ) ) @@ -1393,19 +1393,20 @@ check_str = "Library '%s' has been renamed to '%s'" % ( old_name, name ) self.check_page_for_string( check_str ) self.home() - def add_info_template( self, cntrller, item_type, library_id, form_id, form_name, folder_id=None, ldda_id=None ): + def add_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() 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 ) + url = "%s/library_common/add_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 ) + url = "%s/library_common/add_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 ) + url = "%s/library_common/add_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 template for the" ) tc.fv( '1', 'form_id', form_id ) - tc.submit( 'add_info_template_button' ) + tc.fv( '1', 'inherit', '1' ) + tc.submit( 'add_template_button' ) self.check_page_for_string = 'A 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' ): @@ -1670,28 +1671,28 @@ errmsg += 'Unpacked archive remains in: %s\n' % tmpd raise AssertionError( errmsg ) shutil.rmtree( tmpd ) - def delete_library_item( self, library_id, library_item_id, library_item_name, library_item_type='library_dataset' ): + def delete_library_item( self, library_id, item_id, item_name, item_type='library_dataset' ): """Mark a library item as deleted""" self.home() - self.visit_url( "%s/library_admin/delete_library_item?library_id=%s&library_item_id=%s&library_item_type=%s" \ - % ( self.url, library_id, library_item_id, library_item_type ) ) - if library_item_type == 'library_dataset': - library_item_desc = 'Dataset' + self.visit_url( "%s/library_admin/delete_library_item?library_id=%s&item_id=%s&item_type=%s" \ + % ( self.url, library_id, item_id, item_type ) ) + if item_type == 'library_dataset': + item_desc = 'Dataset' else: - library_item_desc = library_item_type.capitalize() - check_str = "%s '%s' has been marked deleted" % ( library_item_desc, library_item_name ) + item_desc = item_type.capitalize() + check_str = "%s '%s' has been marked deleted" % ( item_desc, item_name ) self.check_page_for_string( check_str ) self.home() - def undelete_library_item( self, library_id, library_item_id, library_item_name, library_item_type='library_dataset' ): + def undelete_library_item( self, library_id, item_id, item_name, item_type='library_dataset' ): """Mark a library item as deleted""" self.home() - self.visit_url( "%s/library_admin/undelete_library_item?library_id=%s&library_item_id=%s&library_item_type=%s" \ - % ( self.url, library_id, library_item_id, library_item_type ) ) - if library_item_type == 'library_dataset': - library_item_desc = 'Dataset' + self.visit_url( "%s/library_admin/undelete_library_item?library_id=%s&item_id=%s&item_type=%s" \ + % ( self.url, library_id, item_id, item_type ) ) + if item_type == 'library_dataset': + item_desc = 'Dataset' else: - library_item_desc = library_item_type.capitalize() - check_str = "%s '%s' has been marked undeleted" % ( library_item_desc, library_item_name ) + item_desc = item_type.capitalize() + check_str = "%s '%s' has been marked undeleted" % ( item_desc, item_name ) self.check_page_for_string( check_str ) self.home() def purge_library( self, library_id, library_name ): diff -r 4a6bb3b64012 -r a3e6350ffc57 test/functional/test_security_and_libraries.py --- a/test/functional/test_security_and_libraries.py Thu Feb 11 09:25:29 2010 -0500 +++ b/test/functional/test_security_and_libraries.py Thu Feb 11 14:26:25 2010 -0500 @@ -579,11 +579,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_info_template( 'library_admin', - 'library', - self.security.encode_id( library_one.id ), - self.security.encode_id( form_one.id ), - form_one.name ) + self.add_template( 'library_admin', + 'library', + self.security.encode_id( library_one.id ), + self.security.encode_id( 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 @@ -1327,7 +1327,7 @@ raise AssertionError( 'ldda.dataset "%s" actions "%s" != ldda.dataset "%s" actions "%s"' \ % ( ldda_six.name, str( ldda_six.dataset.actions ), ldda_six_version_two.name, str( ldda_six_version_two.dataset.actions ) ) ) # Check the previous version - self.visit_url( "%s/library_common/ldda_display_info?cntrller=library_admin&library_id=%s&folder_id=%s&id=%s" % \ + self.visit_url( "%s/library_common/ldda_info?cntrller=library_admin&library_id=%s&folder_id=%s&id=%s" % \ ( self.url, self.security.encode_id( library_one.id ), self.security.encode_id( subfolder_one.id ), self.security.encode_id( ldda_six.id ) ) ) self.check_page_for_string( 'This is an expired version of this library dataset' ) self.home() @@ -1378,7 +1378,7 @@ tc.submit( 'edit_info_button' ) self.check_page_for_string( 'The information has been updated.' ) self.check_page_for_string( template_contents ) - self.visit_url( "%s/library_common/ldda_display_info?cntrller=library_admin&library_id=%s&folder_id=%s&id=%s" % \ + self.visit_url( "%s/library_common/ldda_info?cntrller=library_admin&library_id=%s&folder_id=%s&id=%s" % \ ( self.url, self.security.encode_id( library_one.id ), self.security.encode_id( subfolder_one.id ), self.security.encode_id( ldda_six_version_five.id ) ) ) check_str = 'Expired versions of %s' % ldda_six_version_five.name self.check_page_for_string( check_str ) @@ -1396,7 +1396,7 @@ raise AssertionError( 'ldda.dataset "%s" actions "%s" != ldda.dataset "%s" actions "%s"' \ % ( ldda_six.name, str( ldda_six.dataset.actions ), ldda_six_version_five.name, str( ldda_six_version_five.dataset.actions ) ) ) # Check the previous version - self.visit_url( "%s/library_common/ldda_display_info?cntrller=library_admin&library_id=%s&folder_id=%s&id=%s" % \ + self.visit_url( "%s/library_common/ldda_info?cntrller=library_admin&library_id=%s&folder_id=%s&id=%s" % \ ( self.url, self.security.encode_id( library_one.id ), self.security.encode_id( subfolder_one.id ), self.security.encode_id( ldda_six_version_two.id ) ) ) self.check_page_for_string( 'This is an expired version of this library dataset' ) self.home() @@ -1631,7 +1631,7 @@ self.delete_library_item( self.security.encode_id( library_one.id ), self.security.encode_id( ldda_two.library_dataset.id ), ldda_two.name, - library_item_type='library_dataset' ) + item_type='library_dataset' ) self.home() self.visit_page( 'library_common/browse_library?cntrller=library_admin&id=%s' % ( self.security.encode_id( library_one.id ) ) ) try: @@ -1668,7 +1668,7 @@ self.delete_library_item( self.security.encode_id( library_one.id ), self.security.encode_id( folder_two.id ), folder_two.name, - library_item_type='folder' ) + item_type='folder' ) self.home() self.visit_page( 'library_common/browse_library?cntrller=library_admin&id=%s' % ( self.security.encode_id( library_one.id ) ) ) try: @@ -1684,7 +1684,7 @@ self.undelete_library_item( self.security.encode_id( library_one.id ), self.security.encode_id( folder_two.id ), folder_two.name, - library_item_type='folder' ) + item_type='folder' ) self.home() self.visit_page( 'library_common/browse_library?cntrller=library_admin&id=%s' % ( self.security.encode_id( library_one.id ) ) ) self.check_page_for_string( folder_two.name ) @@ -1704,11 +1704,11 @@ self.delete_library_item( self.security.encode_id( library_one.id ), self.security.encode_id( folder_two.id ), folder_two.name, - library_item_type='folder' ) + item_type='folder' ) self.delete_library_item( self.security.encode_id( library_one.id ), self.security.encode_id( library_one.id ), library_one.name, - library_item_type='library' ) + item_type='library' ) self.home() self.visit_page( 'library_admin/browse_libraries?sort=name&f-description=All&f-name=All&f-deleted=False' ) try: @@ -1727,7 +1727,7 @@ self.undelete_library_item( self.security.encode_id( library_one.id ), self.security.encode_id( library_one.id ), library_one.name, - library_item_type='library' ) + item_type='library' ) self.home() self.visit_page( 'library_admin/browse_libraries?sort=name&f-description=All&f-name=All&f-deleted=False' ) self.check_page_for_string( library_one.name ) @@ -1854,7 +1854,7 @@ self.delete_library_item( self.security.encode_id( library_one.id ), self.security.encode_id( library_one.id ), library_one.name, - library_item_type='library' ) + item_type='library' ) self.purge_library( self.security.encode_id( library_one.id ), library_one.name ) # Make sure the library was purged sa_session.refresh( library_one ) @@ -1928,7 +1928,7 @@ self.delete_library_item( self.security.encode_id( library_two.id ), self.security.encode_id( library_two.id ), library_two.name, - library_item_type='library' ) + item_type='library' ) self.purge_library( self.security.encode_id( library_two.id ), library_two.name ) self.home() def test_260_library_permissions( self ): @@ -1995,12 +1995,12 @@ .first() # Add an information template to the folder template_name = 'Folder Template 1' - 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 ) ) + self.add_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" @@ -2038,11 +2038,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_info_template( 'library', - 'library', - self.security.encode_id( library_three.id ), - self.security.encode_id( form_one.id ), - form_one.name ) + self.add_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 ) ) ) @@ -2069,7 +2069,7 @@ self.delete_library_item( self.security.encode_id( library_three.id ), self.security.encode_id( library_three.id ), library_three.name, - library_item_type='library' ) + item_type='library' ) self.purge_library( self.security.encode_id( library_three.id ), library_three.name ) ################## # Eliminate all non-private roles