[hg] galaxy 2550: Re-introduce library templates which are now b...
details: http://www.bx.psu.edu/hg/galaxy/rev/50ce3d8388f8 changeset: 2550:50ce3d8388f8 user: Greg Von Kuster <greg@bx.psu.edu> date: Fri Aug 07 16:11:14 2009 -0400 description: Re-introduce library templates which are now based on the new Galaxy forms. A library template can be added to a library item ( library, folder, library dataset ), and will be inherited downward in the library hierarchy. A new template can be added to a library item as long as no template field contents have previously been filled in. If template field contents were previously filled in, that template must remain for the current time. More work is needed on for this feature, including additional work on the forms. Functional tests are under way, but much more work is needed here as well. 56 file(s) affected in this change: lib/galaxy/model/__init__.py lib/galaxy/model/mapping.py lib/galaxy/model/migrate/versions/0006_change_qual_datatype.py lib/galaxy/model/migrate/versions/0007_sharing_histories.py lib/galaxy/model/migrate/versions/0008_galaxy_forms.py lib/galaxy/model/migrate/versions/0009_request_table.py lib/galaxy/model/migrate/versions/0010_hda_display_at_authz_table.py lib/galaxy/model/migrate/versions/0011_v0010_mysql_index_fix.py lib/galaxy/model/migrate/versions/0012_user_address.py lib/galaxy/model/migrate/versions/0013_change_lib_item_templates_to_forms.py lib/galaxy/security/__init__.py lib/galaxy/web/controllers/admin.py lib/galaxy/web/controllers/forms.py lib/galaxy/web/controllers/library.py lib/galaxy/web/controllers/library_dataset.py lib/galaxy/web/controllers/requests.py lib/galaxy/web/controllers/requests_admin.py templates/admin/forms/create_form.mako templates/admin/forms/edit_form.mako templates/admin/forms/manage_forms.mako templates/admin/library/browse_library.mako templates/admin/library/common.mako templates/admin/library/create_info_template.mako templates/admin/library/edit_info_template.mako templates/admin/library/folder_info.mako templates/admin/library/info_permissions.mako templates/admin/library/info_template_permissions.mako templates/admin/library/ldda_edit_info.mako templates/admin/library/ldda_info.mako templates/admin/library/library_dataset_info.mako templates/admin/library/library_info.mako templates/admin/library/new_dataset.mako templates/admin/library/new_info.mako templates/admin/library/new_info_template.mako templates/admin/library/select_info_template.mako templates/admin/requests/create_request_type.mako templates/dataset/security_common.mako templates/history/options.mako templates/library/browse_library.mako templates/library/common.mako templates/library/create_info_template.mako templates/library/edit_info_template.mako templates/library/folder_info.mako templates/library/info_permissions.mako templates/library/info_template_permissions.mako templates/library/ldda_edit_info.mako templates/library/ldda_info.mako templates/library/library_dataset_info.mako templates/library/library_info.mako templates/library/new_dataset.mako templates/library/new_info.mako templates/library/new_info_template.mako templates/library/select_info_template.mako templates/mobile/manage_library.mako test/base/twilltestcase.py test/functional/test_security_and_libraries.py diffs (truncated from 5492 to 3000 lines): diff -r eb09beda047d -r 50ce3d8388f8 lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py Fri Aug 07 12:55:07 2009 -0400 +++ b/lib/galaxy/model/__init__.py Fri Aug 07 16:11:14 2009 -0400 @@ -308,30 +308,6 @@ self.library_dataset_dataset_association = library_item else: raise "Invalid LibraryDatasetDatasetAssociation specified: %s" % library_item.__class__.__name__ - self.role = role - -class LibraryItemInfoPermissions( object ): - def __init__( self, action, library_item, role ): - # LIBRARY_ADD -> Not Applicable - # LIBRARY_MODIFY -> Can modify LibraryItemInfoElement.contents - # LIBRARY_MANAGE -> Can change permissions on LibraryItemInfo - self.action = action - if isinstance( library_item, LibraryItemInfo ): - self.library_item_info = library_item - else: - raise "Invalid LibraryItemInfo specified: %s" % library_item.__class__.__name__ - self.role = role - -class LibraryItemInfoTemplatePermissions( object ): - def __init__( self, action, library_item, role ): - # LIBRARY_ADD -> Not Applicable - # LIBRARY_MODIFY -> Can add or delete LibraryItemInfoTemplateElements - # LIBRARY_MANAGE -> Can change permissions on LibraryItemInfoTemplate - self.action = action - if isinstance( library_item, LibraryItemInfoTemplate ): - self.library_item_info_template = library_item - else: - raise "Invalid LibraryItemInfoTemplate specified: %s" % library_item.__class__.__name__ self.role = role class DefaultUserPermissions( object ): @@ -701,12 +677,10 @@ self.name = name or "Unnamed library" self.description = description self.root_folder = root_folder - def get_library_item_info_templates( self, template_list=[], restrict=False ): - # We only want the next available template in the inheritable hierarchy, so we'll only extend - # template_list if it is empty - if not template_list and self.library_info_template_associations: - template_list.extend( [ lita.library_item_info_template for lita in self.library_info_template_associations if lita.library_item_info_template not in template_list ] ) - return template_list + def get_info_association( self, restrict=False ): + if self.info_association: + return self.info_association[0] + return None class LibraryFolder( object ): def __init__( self, name=None, description=None, item_count=0, order_id=None ): @@ -725,18 +699,19 @@ folder.parent_id = self.id folder.order_id = self.item_count self.item_count += 1 - def get_library_item_info_templates( self, template_list=[], restrict=False ): - # If restrict is True, we'll return only those templates directly associated with this Folder - # We only want the next available template in the inheritable hierarchy, so we'll only extend - # template_list if it is empty - if not template_list and self.library_folder_info_template_associations: - template_list.extend( [ lfita.library_item_info_template for lfita in self.library_folder_info_template_associations if lfita.library_item_info_template not in template_list ] ) - if not template_list and restrict not in [ 'True', True ] and self.parent: - self.parent.get_library_item_info_templates( template_list ) - elif not template_list and restrict not in [ 'True', True, 'folder' ] and self.library_root: - for library_root in self.library_root: - library_root.get_library_item_info_templates( template_list ) - return template_list + def get_info_association( self, restrict=False ): + # If restrict is True, we will return this folder's info_association whether it + # exists or not. If restrict is False, we'll return the next available info_association + # in the inheritable hierarchy + if self.info_association: + return self.info_association[0] + if restrict: + return None + if self.parent: + return self.parent.get_info_association() + if self.library_root: + return self.library_root[0].get_info_association() + return None @property def active_components( self ): return list( self.active_folders ) + list( self.active_datasets ) @@ -796,15 +771,6 @@ if not purged and self.purged: raise Exception( "Cannot unpurge once purged" ) purged = property( get_purged, set_purged ) - def get_library_item_info_templates( self, template_list=[], restrict=False ): - # If restrict is True, we'll return only those templates directly associated with this LibraryDataset - # We only want the next available template in the inheritable hierarchy, so we'll only extend - # template_list if it is empty - if not template_list and self.library_dataset_info_template_associations: - template_list.extend( [ ldita.library_item_info_template for ldita in self.library_dataset_info_template_associations if ldita.library_item_info_template not in template_list ] ) - if not template_list and restrict not in [ 'True', True ]: - self.folder.get_library_item_info_templates( template_list, restrict ) - return template_list class LibraryDatasetDatasetAssociation( DatasetInstance ): def __init__( self, @@ -867,105 +833,34 @@ return ldda def clear_associated_files( self, metadata_safe = False, purge = False ): return - def get_library_item_info_templates( self, template_list=[], restrict=False ): - # If restrict is True, we'll return only those templates directly associated with this LibraryDatasetDatasetAssociation - # We only want the next available template in the inheritable hierarchy, so we'll only extend - # template_list if it is empty - if not template_list and self.library_dataset_dataset_info_template_associations: - template_list.extend( [ lddita.library_item_info_template for lddita in self.library_dataset_dataset_info_template_associations if lddita.library_item_info_template not in template_list ] ) - if not template_list: - self.library_dataset.get_library_item_info_templates( template_list, restrict ) - return template_list - -class LibraryInfoTemplateAssociation( object ): - pass - -class LibraryFolderInfoTemplateAssociation( object ): - pass - -class LibraryDatasetInfoTemplateAssociation( object ): - pass - -class LibraryDatasetDatasetInfoTemplateAssociation( object ): - pass - -class LibraryItemInfoTemplate( object ): - def add_element( self, element = None, name = None, description = None ): - if element: - raise "undefined" - else: - new_elem = LibraryItemInfoTemplateElement() - new_elem.name = name - new_elem.description = description - new_elem.order_id = self.item_count - self.item_count += 1 - self.flush() - new_elem.library_item_info_template_id = self.id - new_elem.flush() - return new_elem - -class LibraryItemInfoTemplateElement( object ): - pass + def get_info_association( self, restrict=False ): + # If restrict is True, we will return this ldda's info_association whether it + # exists or not. If restrict is False, we'll return the next available info_association + # in the inheritable hierarchy + if self.info_association: + return self.info_association[0] + if restrict: + return None + return self.library_dataset.folder.get_info_association() class LibraryInfoAssociation( object ): - def __init__( self, user=None ): - self.user = user - def set_library_item( self, library_item ): - if isinstance( library_item, Library ): - self.library = library_item - else: - raise "Invalid Library specified: %s" % library_item.__class__.__name__ + def __init__( self, library, form_definition, info ): + self.library = library + self.template = form_definition + self.info = info class LibraryFolderInfoAssociation( object ): - def __init__( self, user=None ): - self.user = user - def set_library_item( self, library_item ): - if isinstance( library_item, LibraryFolder ): - self.folder = library_item - else: - raise "Invalid Library specified: %s" % library_item.__class__.__name__ - -class LibraryDatasetInfoAssociation( object ): - def __init__( self, user=None ): - self.user = user - def set_library_item( self, library_item ): - if isinstance( library_item, LibraryDataset ): - self.library_dataset = library_item - else: - raise "Invalid Library specified: %s" % library_item.__class__.__name__ + def __init__( self, folder, form_definition, info ): + self.folder = folder + self.template = form_definition + self.info = info class LibraryDatasetDatasetInfoAssociation( object ): - def __init__( self, user=None ): - self.user = user - def set_library_item( self, library_item ): - if isinstance( library_item, LibraryDatasetDatasetAssociation ): - self.library_dataset_dataset_association = library_item - else: - raise "Invalid Library specified: %s" % library_item.__class__.__name__ + def __init__( self, library_dataset_dataset_association, form_definition, info ): + self.library_dataset_dataset_association = library_dataset_dataset_association + self.template = form_definition + self.info = info -class LibraryItemInfo( object ): - def __init__( self, user=None ): - self.user = user - def get_element_by_template_element( self, template_element, create_element=False ): - for element in self.elements: - if element.library_item_info_template_element == template_element: - return element - if create_element: - # Template elements may have been added to the template after the - # library item initially inherited it, so we'll add the additional - # element to the library item - element = LibraryItemInfoElement() - element.library_item_info_template_element = template_element - element.library_item_info = self - element.flush() - self.elements.append( element ) - return element - else: - return None - -class LibraryItemInfoElement( object ): - pass - class ValidationError( object ): def __init__( self, message=None, err_type=None, attributes=None ): self.message = message @@ -1102,8 +997,7 @@ raise # Return filename inside hashed directory return os.path.abspath( os.path.join( path, "metadata_%d.dat" % self.id ) ) - - + class FormDefinition( object ): def __init__(self, name=None, desc=None, fields=[], current_form=None): self.name = name diff -r eb09beda047d -r 50ce3d8388f8 lib/galaxy/model/mapping.py --- a/lib/galaxy/model/mapping.py Fri Aug 07 12:55:07 2009 -0400 +++ b/lib/galaxy/model/mapping.py Fri Aug 07 16:11:14 2009 -0400 @@ -216,22 +216,6 @@ Column( "library_dataset_dataset_association_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), nullable=True, index=True ), Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) ) -LibraryItemInfoPermissions.table = Table( "library_item_info_permissions", metadata, - Column( "id", Integer, primary_key=True ), - Column( "create_time", DateTime, default=now ), - Column( "update_time", DateTime, default=now, onupdate=now ), - Column( "action", TEXT ), - Column( "library_item_info_id", Integer, ForeignKey( "library_item_info.id" ), nullable=True, index=True ), - Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) ) - -LibraryItemInfoTemplatePermissions.table = Table( "library_item_info_template_permissions", metadata, - Column( "id", Integer, primary_key=True ), - Column( "create_time", DateTime, default=now ), - Column( "update_time", DateTime, default=now, onupdate=now ), - Column( "action", TEXT ), - Column( "library_item_info_template_id", Integer, ForeignKey( "library_item_info_template.id" ), nullable=True, index=True ), - Column( "role_id", Integer, ForeignKey( "role.id" ), index=True ) ) - DefaultUserPermissions.table = Table( "default_user_permissions", metadata, Column( "id", Integer, primary_key=True ), Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True ), @@ -299,105 +283,23 @@ Column( "purged", Boolean, index=True, default=False ), Column( "genome_build", TrimmedString( 40 ) ) ) -LibraryItemInfoTemplateElement.table = Table( "library_item_info_template_element", metadata, +LibraryInfoAssociation.table = Table( 'library_info_association', metadata, Column( "id", Integer, primary_key=True ), - Column( "create_time", DateTime, default=now ), - Column( "update_time", DateTime, default=now, onupdate=now ), - Column( "optional", Boolean, index=True, default=True ), - Column( "deleted", Boolean, index=True, default=False ), - Column( "name", TEXT ), - Column( "description", TEXT ), - Column( "type", TEXT, default='string' ), - Column( "order_id", Integer ), - Column( "options", JSONType() ), - Column( "library_item_info_template_id", Integer, ForeignKey( "library_item_info_template.id" ), index=True ) ) - -LibraryItemInfoTemplate.table = Table( "library_item_info_template", metadata, + 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 ) ) + +LibraryFolderInfoAssociation.table = Table( 'library_folder_info_association', metadata, Column( "id", Integer, primary_key=True ), - Column( "create_time", DateTime, default=now ), - Column( "update_time", DateTime, default=now, onupdate=now ), - Column( "optional", Boolean, index=True, default=True ), - Column( "deleted", Boolean, index=True, default=False ), - Column( "name", TEXT ), - Column( "description", TEXT ), - Column( "item_count", Integer, default=0 ) ) + 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 ) ) -LibraryInfoTemplateAssociation.table = Table( "library_info_template_association", metadata, +LibraryDatasetDatasetInfoAssociation.table = Table( 'library_dataset_dataset_info_association', metadata, Column( "id", Integer, primary_key=True ), - Column( "create_time", DateTime, default=now ), - Column( "update_time", DateTime, default=now, onupdate=now ), - Column( "library_id", Integer, ForeignKey( "library.id" ), nullable=True, index=True ), - Column( "library_item_info_template_id", Integer, ForeignKey( "library_item_info_template.id" ), index=True ) ) - -LibraryFolderInfoTemplateAssociation.table = Table( "library_folder_info_template_association", metadata, - Column( "id", Integer, primary_key=True ), - Column( "create_time", DateTime, default=now ), - Column( "update_time", DateTime, default=now, onupdate=now ), - Column( "library_folder_id", Integer, ForeignKey( "library_folder.id" ), nullable=True, index=True ), - Column( "library_item_info_template_id", Integer, ForeignKey( "library_item_info_template.id" ), index=True ) ) - -LibraryDatasetInfoTemplateAssociation.table = Table( "library_dataset_info_template_association", metadata, - Column( "id", Integer, primary_key=True ), - Column( "create_time", DateTime, default=now ), - Column( "update_time", DateTime, default=now, onupdate=now ), - Column( "library_dataset_id", Integer, ForeignKey( "library_dataset.id" ), nullable=True, index=True ), - Column( "library_item_info_template_id", Integer, ForeignKey( "library_item_info_template.id" ), index=True ) ) - -LibraryDatasetDatasetInfoTemplateAssociation.table = Table( "library_dataset_dataset_info_template_association", metadata, - Column( "id", Integer, primary_key=True ), - Column( "create_time", DateTime, default=now ), - Column( "update_time", DateTime, default=now, onupdate=now ), Column( "library_dataset_dataset_association_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), nullable=True, index=True ), - Column( "library_item_info_template_id", Integer, ForeignKey( "library_item_info_template.id" ), index=True ) ) - -LibraryItemInfoElement.table = Table( "library_item_info_element", metadata, - Column( "id", Integer, primary_key=True ), - Column( "create_time", DateTime, default=now ), - Column( "update_time", DateTime, default=now, onupdate=now ), - Column( "contents", JSONType() ), - Column( "library_item_info_id", Integer, ForeignKey( "library_item_info.id" ), index=True ), - Column( "library_item_info_template_element_id", Integer, ForeignKey( "library_item_info_template_element.id" ), index=True ) ) - -LibraryItemInfo.table = Table( "library_item_info", metadata, - Column( "id", Integer, primary_key=True ), - Column( "create_time", DateTime, default=now ), - Column( "update_time", DateTime, default=now, onupdate=now ), - Column( "deleted", Boolean, index=True, default=False ), - Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), nullable=True, index=True ), - Column( "library_item_info_template_id", Integer, ForeignKey( "library_item_info_template.id" ), nullable=True, index=True ) - ) - -LibraryInfoAssociation.table = Table( "library_info_association", metadata, - Column( "id", Integer, primary_key=True ), - Column( "create_time", DateTime, default=now ), - Column( "update_time", DateTime, default=now, onupdate=now ), - Column( "library_id", Integer, ForeignKey( "library.id" ), nullable=True, index=True ), - Column( "library_item_info_id", Integer, ForeignKey( "library_item_info.id" ), index=True ), - Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), nullable=True, index=True ) ) - -LibraryFolderInfoAssociation.table = Table( "library_folder_info_association", metadata, - Column( "id", Integer, primary_key=True ), - Column( "create_time", DateTime, default=now ), - Column( "update_time", DateTime, default=now, onupdate=now ), - Column( "library_folder_id", Integer, ForeignKey( "library_folder.id" ), nullable=True, index=True ), - Column( "library_item_info_id", Integer, ForeignKey( "library_item_info.id" ), index=True ), - Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), nullable=True, index=True ) ) - -LibraryDatasetInfoAssociation.table = Table( "library_dataset_info_association", metadata, - Column( "id", Integer, primary_key=True ), - Column( "create_time", DateTime, default=now ), - Column( "update_time", DateTime, default=now, onupdate=now ), - Column( "library_dataset_id", Integer, ForeignKey( "library_dataset.id" ), nullable=True, index=True ), - Column( "library_item_info_id", Integer, ForeignKey( "library_item_info.id" ), index=True ), - Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), nullable=True, index=True ) ) - -LibraryDatasetDatasetInfoAssociation.table = Table( "library_dataset_dataset_info_association", metadata, - Column( "id", Integer, primary_key=True ), - Column( "create_time", DateTime, default=now ), - Column( "update_time", DateTime, default=now, onupdate=now ), - Column( "library_dataset_dataset_association_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), nullable=True, index=True ), - Column( "library_item_info_id", Integer, ForeignKey( "library_item_info.id" ), index=True ), - Column( "user_id", Integer, ForeignKey( "galaxy_user.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 ) ) Job.table = Table( "job", metadata, Column( "id", Integer, primary_key=True ), @@ -545,7 +447,6 @@ Column( "deleted", Boolean, index=True, default=False ), Column( "purged", Boolean, index=True, default=False ) ) - FormDefinitionCurrent.table = Table('form_definition_current', metadata, Column( "id", Integer, primary_key=True), Column( "create_time", DateTime, default=now ), @@ -553,20 +454,17 @@ Column( "latest_form_id", Integer, ForeignKey( "form_definition.id" ), index=True ), Column( "deleted", Boolean, index=True, default=False )) -# new table to store all the forms which is created by the admin FormDefinition.table = Table('form_definition', metadata, Column( "id", Integer, primary_key=True), Column( "create_time", DateTime, default=now ), Column( "update_time", DateTime, default=now, onupdate=now ), Column( "name", TrimmedString( 255 ), nullable=False ), Column( "desc", TEXT ), - Column( "form_definition_current_id", + Column( "form_definition_current_id", Integer, - ForeignKey( "form_definition_current.id", - name='for_def_form_def_current_id_fk', - use_alter=True), + ForeignKey( "form_definition_current.id", name='for_def_form_def_current_id_fk', use_alter=True ), index=True ), - Column( "fields", JSONType())) + Column( "fields", JSONType() ) ) RequestType.table = Table('request_type', metadata, Column( "id", Integer, primary_key=True), @@ -599,7 +497,7 @@ Column( "deleted", Boolean, index=True, default=False ) ) Sample.table = Table('sample', metadata, - Column( "id", Integer, primary_key=True), + Column( "id", Integer, primary_key=True ), Column( "create_time", DateTime, default=now ), Column( "update_time", DateTime, default=now, onupdate=now ), Column( "name", TrimmedString( 255 ), nullable=False ), @@ -609,10 +507,8 @@ Column( "bar_code", TrimmedString( 255 ), index=True ), Column( "deleted", Boolean, index=True, default=False ) ) -# new table to store all the possible sample states and the sample type it -# belongs to SampleState.table = Table('sample_state', metadata, - Column( "id", Integer, primary_key=True), + Column( "id", Integer, primary_key=True ), Column( "create_time", DateTime, default=now ), Column( "update_time", DateTime, default=now, onupdate=now ), Column( "name", TrimmedString( 255 ), nullable=False ), @@ -620,14 +516,12 @@ Column( "request_type_id", Integer, ForeignKey( "request_type.id" ), index=True ) ) SampleEvent.table = Table('sample_event', metadata, - Column( "id", Integer, primary_key=True), + Column( "id", Integer, primary_key=True ), Column( "create_time", DateTime, default=now ), Column( "update_time", DateTime, default=now, onupdate=now ), Column( "sample_id", Integer, ForeignKey( "sample.id" ), index=True ), Column( "sample_state_id", Integer, ForeignKey( "sample_state.id" ), index=True ), Column( "comment", TEXT ) ) - - # With the tables defined we can define the mappers and setup the # relationships between the model objects. @@ -645,7 +539,8 @@ assign_mapper( context, FormValues, FormValues.table, properties=dict( form_definition=relation( FormDefinition, primaryjoin=( FormValues.table.c.form_definition_id == FormDefinition.table.c.id ) ) - ) ) + ) +) assign_mapper( context, Request, Request.table, properties=dict( values=relation( FormValues, @@ -856,25 +751,20 @@ ) ) -assign_mapper( context, LibraryItemInfoPermissions, LibraryItemInfoPermissions.table, +assign_mapper( context, Library, Library.table, properties=dict( - library_item_info = relation( LibraryItemInfo, backref="actions" ), - role=relation( Role, backref="library_item_info_actions" ) - ) + root_folder=relation( LibraryFolder, backref=backref( "library_root" ) ) + ) ) -assign_mapper( context, LibraryItemInfoTemplatePermissions, LibraryItemInfoTemplatePermissions.table, - properties=dict( - library_item_info_template = relation( LibraryItemInfoTemplate, backref="actions" ), - role=relation( Role, backref="library_item_info_template_actions" ) - ) -) - -assign_mapper( context, Library, Library.table, - properties=dict( - root_folder=relation( LibraryFolder, - backref=backref( "library_root" ) ) - ) ) +assign_mapper( context, LibraryInfoAssociation, LibraryInfoAssociation.table, + properties=dict( library=relation( Library, + primaryjoin=( LibraryInfoAssociation.table.c.library_id == Library.table.c.id ), backref="info_association" ), + template=relation( FormDefinition, + primaryjoin=( LibraryInfoAssociation.table.c.form_definition_id == FormDefinition.table.c.id ) ), + info=relation( FormValues, + primaryjoin=( LibraryInfoAssociation.table.c.form_values_id == FormValues.table.c.id ) ) + ) ) assign_mapper( context, LibraryFolder, LibraryFolder.table, properties=dict( @@ -893,6 +783,15 @@ lazy=False, viewonly=True ) ) ) + +assign_mapper( context, LibraryFolderInfoAssociation, LibraryFolderInfoAssociation.table, + properties=dict( folder=relation( LibraryFolder, + primaryjoin=( LibraryFolderInfoAssociation.table.c.library_folder_id == LibraryFolder.table.c.id ), backref="info_association" ), + template=relation( FormDefinition, + primaryjoin=( LibraryFolderInfoAssociation.table.c.form_definition_id == FormDefinition.table.c.id ) ), + info=relation( FormValues, + primaryjoin=( LibraryFolderInfoAssociation.table.c.form_values_id == FormValues.table.c.id ) ) + ) ) assign_mapper( context, LibraryDataset, LibraryDataset.table, properties=dict( @@ -924,65 +823,14 @@ primaryjoin=( ( LibraryDatasetDatasetAssociation.table.c.parent_id == LibraryDatasetDatasetAssociation.table.c.id ) & ( LibraryDatasetDatasetAssociation.table.c.visible == True ) ) ) ) ) -assign_mapper( context, LibraryItemInfoTemplateElement, LibraryItemInfoTemplateElement.table, - properties=dict( library_item_info_template=relation( LibraryItemInfoTemplate, backref="elements" ), - ) ) - -assign_mapper( context, LibraryItemInfoTemplate, LibraryItemInfoTemplate.table ) - -assign_mapper( context, LibraryInfoTemplateAssociation, LibraryInfoTemplateAssociation.table, - properties=dict( library=relation( Library, backref="library_info_template_associations" ), - library_item_info_template = relation( LibraryItemInfoTemplate, backref="library_info_template_associations" ), - ) ) - -assign_mapper( context, LibraryFolderInfoTemplateAssociation, LibraryFolderInfoTemplateAssociation.table, - properties=dict( folder=relation( LibraryFolder, backref="library_folder_info_template_associations" ), - library_item_info_template = relation( LibraryItemInfoTemplate, backref="library_folder_info_template_associations" ), - ) ) - -assign_mapper( context, LibraryDatasetInfoTemplateAssociation, LibraryDatasetInfoTemplateAssociation.table, - properties=dict( library_dataset=relation( LibraryDataset, backref="library_dataset_info_template_associations" ), - library_item_info_template = relation( LibraryItemInfoTemplate, backref="library_dataset_info_template_associations" ), - ) ) - -assign_mapper( context, LibraryDatasetDatasetInfoTemplateAssociation, LibraryDatasetDatasetInfoTemplateAssociation.table, - properties=dict( library_dataset_dataset_association = relation( LibraryDatasetDatasetAssociation, backref="library_dataset_dataset_info_template_associations" ), - library_item_info_template = relation( LibraryItemInfoTemplate, backref="library_dataset_dataset_info_template_associations" ), - ) ) - -assign_mapper( context, LibraryItemInfoElement, LibraryItemInfoElement.table, - properties=dict( library_item_info=relation( LibraryItemInfo, backref="elements" ), - library_item_info_template_element=relation( LibraryItemInfoTemplateElement ) - ) ) - -assign_mapper( context, LibraryItemInfo, LibraryItemInfo.table, - properties=dict( library_item_info_template=relation( LibraryItemInfoTemplate, backref="library_item_infos" ), - user=relation( User.mapper ) - ) ) - -assign_mapper( context, LibraryInfoAssociation, LibraryInfoAssociation.table, - properties=dict( library=relation( Library, backref="library_info_associations" ), - library_item_info = relation( LibraryItemInfo, backref="library_info_associations" ), - user=relation( User.mapper ) - ) ) - -assign_mapper( context, LibraryFolderInfoAssociation, LibraryFolderInfoAssociation.table, - properties=dict( folder=relation( LibraryFolder, backref="library_folder_info_associations" ), - library_item_info = relation( LibraryItemInfo, backref="library_folder_info_associations" ), - user=relation( User.mapper ) - ) ) - -assign_mapper( context, LibraryDatasetInfoAssociation, LibraryDatasetInfoAssociation.table, - properties=dict( library_dataset=relation( LibraryDataset, backref="library_dataset_info_associations" ), - library_item_info = relation( LibraryItemInfo, backref="library_dataset_info_associations" ), - user=relation( User.mapper ) - ) ) - assign_mapper( context, LibraryDatasetDatasetInfoAssociation, LibraryDatasetDatasetInfoAssociation.table, - properties=dict( library_dataset_dataset_association = relation( LibraryDatasetDatasetAssociation, backref="library_dataset_dataset_info_associations" ), - library_item_info = relation( LibraryItemInfo, backref="library_dataset_dataset_info_associations" ), - user=relation( User.mapper ) - ) ) + properties=dict( library_dataset_dataset_association=relation( LibraryDatasetDatasetAssociation, + primaryjoin=( LibraryDatasetDatasetInfoAssociation.table.c.library_dataset_dataset_association_id == LibraryDatasetDatasetAssociation.table.c.id ), backref="info_association" ), + template=relation( FormDefinition, + primaryjoin=( LibraryDatasetDatasetInfoAssociation.table.c.form_definition_id == FormDefinition.table.c.id ) ), + info=relation( FormValues, + primaryjoin=( LibraryDatasetDatasetInfoAssociation.table.c.form_values_id == FormValues.table.c.id ) ) + ) ) assign_mapper( context, JobToInputDatasetAssociation, JobToInputDatasetAssociation.table, properties=dict( job=relation( Job ), dataset=relation( HistoryDatasetAssociation, lazy=False ) ) ) diff -r eb09beda047d -r 50ce3d8388f8 lib/galaxy/model/migrate/versions/0006_change_qual_datatype.py --- a/lib/galaxy/model/migrate/versions/0006_change_qual_datatype.py Fri Aug 07 12:55:07 2009 -0400 +++ b/lib/galaxy/model/migrate/versions/0006_change_qual_datatype.py Fri Aug 07 16:11:14 2009 -0400 @@ -1,3 +1,7 @@ +""" +This migration script changes certain values in the history_dataset_association.extension +column, specifically 'qual' is chaged to be 'qual454'. +""" from sqlalchemy import * from sqlalchemy.orm import * from migrate import * @@ -13,9 +17,17 @@ metadata = MetaData( migrate_engine ) db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, transactional=False ) ) + +def display_migration_details(): + print "========================================" + print "This migration script changes certain values in the history_dataset_association.extension" + print "column, specifically 'qual' is chaged to be 'qual454'." + print "========================================" + HistoryDatasetAssociation_table = Table( "history_dataset_association", metadata, autoload=True ) - + def upgrade(): + display_migration_details() # Load existing tables metadata.reflect() # Add 2 indexes to the galaxy_user table @@ -42,6 +54,5 @@ except Exception, e: log.debug( "Dropping index 'ix_hda_extension' to history_dataset_association table failed: %s" % ( str( e ) ) ) - def downgrade(): pass diff -r eb09beda047d -r 50ce3d8388f8 lib/galaxy/model/migrate/versions/0007_sharing_histories.py --- a/lib/galaxy/model/migrate/versions/0007_sharing_histories.py Fri Aug 07 12:55:07 2009 -0400 +++ b/lib/galaxy/model/migrate/versions/0007_sharing_histories.py Fri Aug 07 16:11:14 2009 -0400 @@ -1,3 +1,8 @@ +""" +This migration script creates the new history_user_share_association table, and adds +a new boolean type column to the history table. This provides support for sharing +histories in the same way that workflows are shared. +""" from sqlalchemy import * from sqlalchemy.orm import * from migrate import * @@ -14,6 +19,13 @@ metadata = MetaData( migrate_engine ) +def display_migration_details(): + print "========================================" + print "This migration script creates the new history_user_share_association table, and adds" + print "a new boolean type column to the history table. This provides support for sharing" + print "histories in the same way that workflows are shared." + print "========================================" + HistoryUserShareAssociation_table = Table( "history_user_share_association", metadata, Column( "id", Integer, primary_key=True ), Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ), @@ -21,6 +33,7 @@ ) def upgrade(): + display_migration_details() # Load existing tables metadata.reflect() # Create the history_user_share_association table diff -r eb09beda047d -r 50ce3d8388f8 lib/galaxy/model/migrate/versions/0008_galaxy_forms.py --- a/lib/galaxy/model/migrate/versions/0008_galaxy_forms.py Fri Aug 07 12:55:07 2009 -0400 +++ b/lib/galaxy/model/migrate/versions/0008_galaxy_forms.py Fri Aug 07 16:11:14 2009 -0400 @@ -1,3 +1,14 @@ +""" +This migration script adds the following new tables for supporting Galaxy forms: +1) form_definition_current +2) form_definition +3) form_values +4) request_type +5) request +6) sample +7) sample_state +8) sample_event +""" from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.exceptions import * @@ -22,15 +33,26 @@ metadata = MetaData( migrate_engine ) db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, transactional=False ) ) +def display_migration_details(): + print "========================================" + print "This migration script adds the following new tables for supporting Galaxy forms:" + print "1) form_definition_current" + print "2) form_definition" + print "3) form_values" + print "4) request_type" + print "5) request" + print "6) sample" + print "7) sample_state" + print "8) sample_event" + print "========================================" FormDefinitionCurrent_table = Table('form_definition_current', metadata, Column( "id", Integer, primary_key=True), Column( "create_time", DateTime, default=now ), Column( "update_time", DateTime, default=now, onupdate=now ), - Column( "latest_form_id", Integer, - #ForeignKey( "form_definition.id", use_alter=True, name='form_definition_current_latest_form_id_fk'), - index=True ), + Column( "latest_form_id", Integer, index=True ), Column( "deleted", Boolean, index=True, default=False )) + FormDefinition_table = Table('form_definition', metadata, Column( "id", Integer, primary_key=True), Column( "create_time", DateTime, default=now ), @@ -55,7 +77,7 @@ Column( "desc", TEXT ), Column( "request_form_id", Integer, ForeignKey( "form_definition.id" ), index=True ), Column( "sample_form_id", Integer, ForeignKey( "form_definition.id" ), index=True ) ) -# request table + Request_table = Table('request', metadata, Column( "id", Integer, primary_key=True), Column( "create_time", DateTime, default=now ), @@ -94,13 +116,10 @@ Column( "sample_state_id", Integer, ForeignKey( "sample_state.id" ), index=True ), Column( "comment", TEXT ) ) - - - def upgrade(): + display_migration_details() # Load existing tables metadata.reflect() - # Add all of the new tables above # metadata.create_all() try: @@ -145,8 +164,6 @@ SampleEvent_table.create() except Exception, e: log.debug( "Creating sample_event table failed: %s" % str( e ) ) - - def downgrade(): # Load existing tables @@ -183,7 +200,3 @@ SampleEvent_table.drop() except Exception, e: log.debug( "Dropping sample_event table failed: %s" % str( e ) ) - - - - diff -r eb09beda047d -r 50ce3d8388f8 lib/galaxy/model/migrate/versions/0009_request_table.py --- a/lib/galaxy/model/migrate/versions/0009_request_table.py Fri Aug 07 12:55:07 2009 -0400 +++ b/lib/galaxy/model/migrate/versions/0009_request_table.py Fri Aug 07 16:11:14 2009 -0400 @@ -1,3 +1,8 @@ +""" +This migration script adds a new column to 2 tables: +1) a new boolean type column named 'submitted' to the 'request' table +2) a new string type column named 'bar_code' to the 'sample' table +""" from sqlalchemy import * from sqlalchemy.orm import * from migrate import * @@ -15,11 +20,17 @@ metadata = MetaData( migrate_engine ) +def display_migration_details(): + print "========================================" + print "This migration script adds a new column to 2 tables:" + print "1) a new boolean type column named 'submitted' to the 'request' table" + print "2) a new string type column named 'bar_code' to the 'sample' table" + print "========================================" def upgrade(): + display_migration_details() # Load existing tables metadata.reflect() - # Add 1 column to the request table try: Request_table = Table( "request", metadata, autoload=True ) @@ -33,7 +44,6 @@ assert col is Request_table.c.submitted except Exception, e: log.debug( "Adding column 'submitted' to request table failed: %s" % ( str( e ) ) ) - # Add 1 column to the sample table try: Sample_table = Table( "sample", metadata, autoload=True ) @@ -49,4 +59,4 @@ log.debug( "Adding column 'bar_code' to sample table failed: %s" % ( str( e ) ) ) def downgrade(): - pass \ No newline at end of file + pass diff -r eb09beda047d -r 50ce3d8388f8 lib/galaxy/model/migrate/versions/0010_hda_display_at_authz_table.py --- a/lib/galaxy/model/migrate/versions/0010_hda_display_at_authz_table.py Fri Aug 07 12:55:07 2009 -0400 +++ b/lib/galaxy/model/migrate/versions/0010_hda_display_at_authz_table.py Fri Aug 07 16:11:14 2009 -0400 @@ -1,3 +1,13 @@ +""" +This migration script adds the history_dataset_association_display_at_authorization table, +which allows 'private' datasets to be displayed at external sites without making them public. +If using mysql, this script will display the following error, which is corrected in the next +migration script: + +history_dataset_association_display_at_authorization table failed: (OperationalError) +(1059, "Identifier name 'ix_history_dataset_association_display_at_authorization_update_time' +is too long +""" from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.exceptions import * @@ -22,6 +32,17 @@ metadata = MetaData( migrate_engine ) db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, transactional=False ) ) +def display_migration_details(): + print "========================================" + print "This migration script adds the history_dataset_association_display_at_authorization table, which" + print "allows 'private' datasets to be displayed at external sites without making them public." + print "" + print "If using mysql, this script will display the following error, which is corrected in the next migration" + print "script: history_dataset_association_display_at_authorization table failed: (OperationalError)" + print "(1059, 'Identifier name 'ix_history_dataset_association_display_at_authorization_update_time'" + print "is too long." + print "========================================" + HistoryDatasetAssociationDisplayAtAuthorization_table = Table( "history_dataset_association_display_at_authorization", metadata, Column( "id", Integer, primary_key=True ), Column( "create_time", DateTime, default=now ), @@ -31,13 +52,14 @@ Column( "site", TrimmedString( 255 ) ) ) def upgrade(): + display_migration_details() # Load existing tables metadata.reflect() try: HistoryDatasetAssociationDisplayAtAuthorization_table.create() except Exception, e: log.debug( "Creating history_dataset_association_display_at_authorization table failed: %s" % str( e ) ) - + def downgrade(): # Load existing tables metadata.reflect() diff -r eb09beda047d -r 50ce3d8388f8 lib/galaxy/model/migrate/versions/0011_v0010_mysql_index_fix.py --- a/lib/galaxy/model/migrate/versions/0011_v0010_mysql_index_fix.py Fri Aug 07 12:55:07 2009 -0400 +++ b/lib/galaxy/model/migrate/versions/0011_v0010_mysql_index_fix.py Fri Aug 07 16:11:14 2009 -0400 @@ -1,3 +1,8 @@ +""" +This script fixes a problem introduced in 0010_hda_display_at_atuhz_table.py. MySQL has a +name length limit and thus the index "ix_hdadaa_history_dataset_association_id" has to be +manually created. +""" from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.exceptions import * @@ -22,6 +27,13 @@ metadata = MetaData( migrate_engine ) db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, transactional=False ) ) +def display_migration_details(): + print "========================================" + print "This script fixes a problem introduced in the previous migration script ( 9->10 ). MySQL" + print "has a name length limit and thus the index 'ix_hdadaa_history_dataset_association_id' has" + print "to be manually created." + print "========================================" + HistoryDatasetAssociationDisplayAtAuthorization_table = Table( "history_dataset_association_display_at_authorization", metadata, Column( "id", Integer, primary_key=True ), Column( "create_time", DateTime, default=now ), @@ -31,6 +43,7 @@ Column( "site", TrimmedString( 255 ) ) ) def upgrade(): + display_migration_details() if migrate_engine.name == 'mysql': # Load existing tables metadata.reflect() @@ -39,7 +52,7 @@ i.create() except Exception, e: log.debug( "Adding index 'ix_hdadaa_history_dataset_association_id' to table 'history_dataset_association_display_at_authorization' table failed: %s" % str( e ) ) - + def downgrade(): if migrate_engine.name == 'mysql': # Load existing tables diff -r eb09beda047d -r 50ce3d8388f8 lib/galaxy/model/migrate/versions/0012_user_address.py --- a/lib/galaxy/model/migrate/versions/0012_user_address.py Fri Aug 07 12:55:07 2009 -0400 +++ b/lib/galaxy/model/migrate/versions/0012_user_address.py Fri Aug 07 16:11:14 2009 -0400 @@ -1,13 +1,20 @@ +""" +This script adds a new user_address table that is currently only used with sample requests, where +a user can select from a list of his addresses to associate with the request. This script also +drops the request.submitted column which was boolean and replaces it with a request.state column +which is a string, allowing for more flexibility with request states. +""" from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.exceptions import * from migrate import * from migrate.changeset import * - import datetime now = datetime.datetime.utcnow +import sys, logging +# Need our custom types, but don't import anything else from model +from galaxy.model.custom_types import * -import sys, logging log = logging.getLogger( __name__ ) log.setLevel(logging.DEBUG) handler = logging.StreamHandler( sys.stdout ) @@ -16,12 +23,16 @@ handler.setFormatter( formatter ) log.addHandler( handler ) -# Need our custom types, but don't import anything else from model -from galaxy.model.custom_types import * - metadata = MetaData( migrate_engine ) db_session = scoped_session( sessionmaker( bind=migrate_engine, autoflush=False, transactional=False ) ) +def display_migration_details(): + print "========================================" + print "This script adds a new user_address table that is currently only used with sample requests, where" + print "a user can select from a list of his addresses to associate with the request. This script also" + print "drops the request.submitted column which was boolean and replaces it with a request.state column" + print "which is a string, allowing for more flexibility with request states." + print "========================================" UserAddress_table = Table( "user_address", metadata, Column( "id", Integer, primary_key=True), @@ -41,15 +52,14 @@ Column( "purged", Boolean, index=True, default=False ) ) def upgrade(): + display_migration_details() # Load existing tables metadata.reflect() - # Add all of the new tables above try: UserAddress_table.create() except Exception, e: log.debug( "Creating user_address table failed: %s" % str( e ) ) - # Add 1 column to the request_type table try: RequestType_table = Table( "request_type", metadata, autoload=True ) @@ -63,7 +73,6 @@ assert col is RequestType_table.c.deleted except Exception, e: log.debug( "Adding column 'deleted' to request_type table failed: %s" % ( str( e ) ) ) - # Delete the submitted column try: Request_table = Table( "request", metadata, autoload=True ) @@ -82,8 +91,5 @@ except Exception, e: log.debug( "Adding column 'state' to request table failed: %s" % ( str( e ) ) ) - def downgrade(): pass - - diff -r eb09beda047d -r 50ce3d8388f8 lib/galaxy/model/migrate/versions/0013_change_lib_item_templates_to_forms.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/galaxy/model/migrate/versions/0013_change_lib_item_templates_to_forms.py Fri Aug 07 16:11:14 2009 -0400 @@ -0,0 +1,255 @@ +""" +This migration script eliminates all of the tables that were used for the 1st version of the +library templates where template fields and contents were each stored as a separate table row +in various library item tables. All of these tables are dropped in this script, eliminating all +existing template data. A total of 14 existing tables are dropped. + +We're now basing library templates on forms, so field contents are +stored as a jsonified list in the form_values table. This script introduces the following 3 +new association tables: +1) library_info_association +2) library_folder_info_association +3) library_dataset_dataset_info_association + +If using mysql, this script will throw an (OperationalError) exception due to a long index name on +the library_dataset_dataset_info_association table, which is OK because the script creates an index +with a shortened name. +""" +from sqlalchemy import * +from sqlalchemy.orm import * +from sqlalchemy.exceptions import * +from migrate import * +from migrate.changeset import * +import sys, logging + +log = logging.getLogger( __name__ ) +log.setLevel(logging.DEBUG) +handler = logging.StreamHandler( sys.stdout ) +format = "%(name)s %(levelname)s %(asctime)s %(message)s" +formatter = logging.Formatter( format ) +handler.setFormatter( formatter ) +log.addHandler( handler ) + +metadata = MetaData( migrate_engine ) + +def display_migration_details(): + print "========================================" + print "This migration script eliminates all of the tables that were used for the 1st version of the" + print "library templates where template fields and contents were each stored as a separate table row" + print "in various library item tables. All of these tables are dropped in this script, eliminating all" + print "existing template data. A total of 14 existing tables are dropped." + print "" + print "We're now basing library templates on Galaxy forms, so field contents are stored as a jsonified" + print "list in the form_values table. This script introduces the following 3 new association tables:" + print "1) library_info_association" + print "2) library_folder_info_association" + print "3) library_dataset_dataset_info_association" + print "" + print "If using mysql, this script will throw an (OperationalError) exception due to a long index name" + print "on the library_dataset_dataset_info_association table, which is OK because the script creates" + print "an index with a shortened name." + print "========================================" + +if migrate_engine.name == 'postgres': + # http://blog.pythonisito.com/2008/01/cascading-drop-table-with-sqlalchemy.htm... + from sqlalchemy.databases import postgres + class PGCascadeSchemaDropper(postgres.PGSchemaDropper): + def visit_table(self, table): + for column in table.columns: + if column.default is not None: + self.traverse_single(column.default) + self.append("\nDROP TABLE " + + self.preparer.format_table(table) + + " CASCADE") + self.execute() + postgres.dialect.schemadropper = PGCascadeSchemaDropper + +LibraryInfoAssociation_table = Table( 'library_info_association', metadata, + Column( "id", Integer, primary_key=True), + Column( "library_id", Integer, ForeignKey( "library.id" ), index=True ), + Column( "form_definition_id", Integer, ForeignKey( "form_definition.id" ), index=True ), + Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ) ) + +LibraryFolderInfoAssociation_table = Table( 'library_folder_info_association', metadata, + Column( "id", Integer, primary_key=True), + Column( "library_folder_id", Integer, ForeignKey( "library_folder.id" ), nullable=True, index=True ), + Column( "form_definition_id", Integer, ForeignKey( "form_definition.id" ), index=True ), + Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ) ) + +LibraryDatasetDatasetInfoAssociation_table = Table( 'library_dataset_dataset_info_association', metadata, + Column( "id", Integer, primary_key=True), + Column( "library_dataset_dataset_association_id", Integer, ForeignKey( "library_dataset_dataset_association.id" ), nullable=True, index=True ), + Column( "form_definition_id", Integer, ForeignKey( "form_definition.id" ), index=True ), + Column( "form_values_id", Integer, ForeignKey( "form_values.id" ), index=True ) ) + +def upgrade(): + display_migration_details() + # Load existing tables + metadata.reflect() + # Drop all of the original library_item_info tables + # NOTE: all existing library item into template data is eliminated here via table drops + try: + LibraryItemInfoPermissions_table = Table( "library_item_info_permissions", metadata, autoload=True ) + except NoSuchTableError: + LibraryItemInfoPermissions_table = None + log.debug( "Failed loading table library_item_info_permissions" ) + try: + LibraryItemInfoPermissions_table.drop() + except Exception, e: + log.debug( "Dropping library_item_info_permissions table failed: %s" % str( e ) ) + + try: + LibraryItemInfoTemplatePermissions_table = Table( "library_item_info_template_permissions", metadata, autoload=True ) + except NoSuchTableError: + LibraryItemInfoTemplatePermissions_table = None + log.debug( "Failed loading table library_item_info_template_permissions" ) + try: + LibraryItemInfoTemplatePermissions_table.drop() + except Exception, e: + log.debug( "Dropping library_item_info_template_permissions table failed: %s" % str( e ) ) + + try: + LibraryItemInfoElement_table = Table( "library_item_info_element", metadata, autoload=True ) + except NoSuchTableError: + LibraryItemInfoElement_table = None + log.debug( "Failed loading table library_item_info_element" ) + try: + LibraryItemInfoElement_table.drop() + except Exception, e: + log.debug( "Dropping library_item_info_element table failed: %s" % str( e ) ) + + try: + LibraryItemInfoTemplateElement_table = Table( "library_item_info_template_element", metadata, autoload=True ) + except NoSuchTableError: + LibraryItemInfoTemplateElement_table = None + log.debug( "Failed loading table library_item_info_template_element" ) + try: + LibraryItemInfoTemplateElement_table.drop() + except Exception, e: + log.debug( "Dropping library_item_info_template_element table failed: %s" % str( e ) ) + + try: + LibraryInfoTemplateAssociation_table = Table( "library_info_template_association", metadata, autoload=True ) + except NoSuchTableError: + LibraryInfoTemplateAssociation_table = None + log.debug( "Failed loading table library_info_template_association" ) + try: + LibraryInfoTemplateAssociation_table.drop() + except Exception, e: + log.debug( "Dropping library_info_template_association table failed: %s" % str( e ) ) + + try: + LibraryFolderInfoTemplateAssociation_table = Table( "library_folder_info_template_association", metadata, autoload=True ) + except NoSuchTableError: + LibraryFolderInfoTemplateAssociation_table = None + log.debug( "Failed loading table library_folder_info_template_association" ) + try: + LibraryFolderInfoTemplateAssociation_table.drop() + except Exception, e: + log.debug( "Dropping library_folder_info_template_association table failed: %s" % str( e ) ) + + try: + LibraryDatasetInfoTemplateAssociation_table = Table( "library_dataset_info_template_association", metadata, autoload=True ) + except NoSuchTableError: + LibraryDatasetInfoTemplateAssociation_table = None + log.debug( "Failed loading table library_dataset_info_template_association" ) + try: + LibraryDatasetInfoTemplateAssociation_table.drop() + except Exception, e: + log.debug( "Dropping library_dataset_info_template_association table failed: %s" % str( e ) ) + + try: + LibraryDatasetDatasetInfoTemplateAssociation_table = Table( "library_dataset_dataset_info_template_association", metadata, autoload=True ) + except NoSuchTableError: + LibraryDatasetDatasetInfoTemplateAssociation_table = None + log.debug( "Failed loading table library_dataset_dataset_info_template_association" ) + try: + LibraryDatasetDatasetInfoTemplateAssociation_table.drop() + except Exception, e: + log.debug( "Dropping library_dataset_dataset_info_template_association table failed: %s" % str( e ) ) + + try: + LibraryInfoAssociation_table = Table( "library_info_association", metadata, autoload=True ) + except NoSuchTableError: + LibraryInfoAssociation_table = None + log.debug( "Failed loading table library_info_association" ) + try: + LibraryInfoAssociation_table.drop() + except Exception, e: + log.debug( "Dropping library_info_association table failed: %s" % str( e ) ) + + try: + LibraryFolderInfoAssociation_table = Table( "library_folder_info_association", metadata, autoload=True ) + except NoSuchTableError: + LibraryFolderInfoAssociation_table = None + log.debug( "Failed loading table library_folder_info_association" ) + try: + LibraryFolderInfoAssociation_table.drop() + except Exception, e: + log.debug( "Dropping library_folder_info_association table failed: %s" % str( e ) ) + + try: + LibraryDatasetInfoAssociation_table = Table( "library_dataset_info_association", metadata, autoload=True ) + except NoSuchTableError: + LibraryDatasetInfoAssociation_table = None + log.debug( "Failed loading table library_dataset_info_association" ) + try: + LibraryDatasetInfoAssociation_table.drop() + except Exception, e: + log.debug( "Dropping library_dataset_info_association table failed: %s" % str( e ) ) + + try: + LibraryDatasetDatasetInfoAssociation_table = Table( "library_dataset_dataset_info_association", metadata, autoload=True ) + except NoSuchTableError: + LibraryDatasetDatasetInfoAssociation_table = None + log.debug( "Failed loading table library_dataset_dataset_info_association" ) + try: + LibraryDatasetDatasetInfoAssociation_table.drop() + except Exception, e: + log.debug( "Dropping library_dataset_dataset_info_association table failed: %s" % str( e ) ) + + try: + LibraryItemInfo_table = Table( "library_item_info", metadata, autoload=True ) + except NoSuchTableError: + LibraryItemInfo_table = None + log.debug( "Failed loading table library_item_info" ) + try: + LibraryItemInfo_table.drop() + except Exception, e: + log.debug( "Dropping library_item_info table failed: %s" % str( e ) ) + + try: + LibraryItemInfoTemplate_table = Table( "library_item_info_template", metadata, autoload=True ) + except NoSuchTableError: + LibraryItemInfoTemplate_table = None + log.debug( "Failed loading table library_item_info_template" ) + try: + LibraryItemInfoTemplate_table.drop() + except Exception, e: + log.debug( "Dropping library_item_info_template table failed: %s" % str( e ) ) + + # Create all new tables above + try: + LibraryInfoAssociation_table.create() + except Exception, e: + log.debug( "Creating library_info_association table failed: %s" % str( e ) ) + try: + LibraryFolderInfoAssociation_table.create() + except Exception, e: + log.debug( "Creating library_folder_info_association table failed: %s" % str( e ) ) + try: + LibraryDatasetDatasetInfoAssociation_table.create() + except Exception, e: + log.debug( "Creating library_dataset_dataset_info_association table failed: %s" % str( e ) ) + # Fix index on LibraryDatasetDatasetInfoAssociation_table for mysql + if migrate_engine.name == 'mysql': + # Load existing tables + metadata.reflect() + i = Index( "ix_lddaia_ldda_id", LibraryDatasetDatasetInfoAssociation_table.c.library_dataset_dataset_association_id ) + try: + i.create() + except Exception, e: + log.debug( "Adding index 'ix_lddaia_ldda_id' to table 'library_dataset_dataset_info_association' table failed: %s" % str( e ) ) + +def downgrade(): + log.debug( "Downgrade is not possible." ) diff -r eb09beda047d -r 50ce3d8388f8 lib/galaxy/security/__init__.py --- a/lib/galaxy/security/__init__.py Fri Aug 07 12:55:07 2009 -0400 +++ b/lib/galaxy/security/__init__.py Fri Aug 07 16:11:14 2009 -0400 @@ -75,12 +75,10 @@ self.permitted_actions = permitted_actions # List of "library_item" objects and their associated permissions and info template objects self.library_item_assocs = ( - ( self.model.Library, self.model.LibraryPermissions, self.model.LibraryInfoAssociation ), - ( self.model.LibraryFolder, self.model.LibraryFolderPermissions, self.model.LibraryFolderInfoAssociation ), - ( self.model.LibraryDataset, self.model.LibraryDatasetPermissions, self.model.LibraryDatasetInfoAssociation ), - ( self.model.LibraryDatasetDatasetAssociation, self.model.LibraryDatasetDatasetAssociationPermissions, self.model.LibraryDatasetDatasetInfoAssociation ), - ( self.model.LibraryItemInfo, self.model.LibraryItemInfoPermissions, None ), - ( self.model.LibraryItemInfoTemplate, self.model.LibraryItemInfoTemplatePermissions, None ) ) + ( self.model.Library, self.model.LibraryPermissions ), + ( self.model.LibraryFolder, self.model.LibraryFolderPermissions ), + ( self.model.LibraryDataset, self.model.LibraryDatasetPermissions ), + ( self.model.LibraryDatasetDatasetAssociation, self.model.LibraryDatasetDatasetAssociationPermissions ) ) def allow_action( self, user, action, **kwd ): if 'dataset' in kwd: return self.allow_dataset_action( user, action, kwd[ 'dataset' ] ) @@ -117,7 +115,7 @@ user_role_ids = [ r.id for r in user.all_roles() ] # Check to see if user has access to any of the roles allowed_role_assocs = [] - for item_class, permission_class, info_association_class in self.library_item_assocs: + for item_class, permission_class in self.library_item_assocs: if isinstance( library_item, item_class ): if permission_class == self.model.LibraryPermissions: allowed_role_assocs = permission_class.filter_by( action=action.action, library_id=library_item.id ).all() @@ -127,10 +125,6 @@ allowed_role_assocs = permission_class.filter_by( action=action.action, library_dataset_id=library_item.id ).all() elif permission_class == self.model.LibraryDatasetDatasetAssociationPermissions: allowed_role_assocs = permission_class.filter_by( action=action.action, library_dataset_dataset_association_id=library_item.id ).all() - elif permission_class == self.model.LibraryItemInfoPermissions: - allowed_role_assocs = permission_class.filter_by( action=action.action, library_item_info_id=library_item.id ).all() - elif permission_class == self.model.LibraryItemInfoTemplatePermissions: - allowed_role_assocs = permission_class.filter_by( action=action.action, library_item_info_template_id=library_item.id ).all() for allowed_role_assoc in allowed_role_assocs: if allowed_role_assoc.role_id in user_role_ids: return True @@ -366,7 +360,7 @@ role_assoc.delete() role_assoc.flush() # Add the new permissions on library_item - for item_class, permission_class, info_association_class in self.library_item_assocs: + for item_class, permission_class in self.library_item_assocs: if isinstance( library_item, item_class ): for action, roles in permissions.items(): if isinstance( action, Action ): @@ -396,12 +390,12 @@ permissions[role_assoc.action] = [ role_assoc.role ] self.set_all_library_permissions( target_library_item, permissions ) if user: - # The user passed will be the current Galaxy user. Make sure user's private role is included item_class = None - for item_class, permission_class, info_association_class in self.library_item_assocs: + for item_class, permission_class in self.library_item_assocs: if isinstance( target_library_item, item_class ): break if item_class: + # Make sure user's private role is included private_role = self.model.security_agent.get_private_user_role( user ) for name, action in self.permitted_actions.items(): if not permission_class.filter_by( role_id = private_role.id, action = action.action ).first(): diff -r eb09beda047d -r 50ce3d8388f8 lib/galaxy/web/controllers/admin.py --- a/lib/galaxy/web/controllers/admin.py Fri Aug 07 12:55:07 2009 -0400 +++ b/lib/galaxy/web/controllers/admin.py Fri Aug 07 16:11:14 2009 -0400 @@ -1,9 +1,9 @@ -import shutil, StringIO, operator, urllib, gzip, tempfile, sets, string +import shutil, StringIO, operator, urllib, gzip, tempfile, sets, string, sys from datetime import datetime, timedelta from galaxy import util, datatypes from galaxy.web.base.controller import * from galaxy.model.orm import * -import sys +from galaxy.web.controllers.forms import get_all_forms, get_form_widgets import logging log = logging.getLogger( __name__ ) @@ -710,6 +710,7 @@ library=trans.app.model.Library.get( id ), deleted=deleted, created_ldda_ids=created_ldda_ids, + forms=get_all_forms( trans ), msg=msg, messagetype=messagetype, show_deleted=show_deleted ) @@ -751,6 +752,22 @@ messagetype='done' ) ) return trans.fill_template( '/admin/library/new_library.mako', msg=msg, messagetype=messagetype ) elif action == 'information': + # See if we have any associated templates + info_association = library.get_info_association() + if info_association: + template = info_association.template + # See if we have any field contents + info = info_association.info + if info: + field_contents = {} + for index, value in enumerate( info.content ): + key = 'field_%i' % index + field_contents[ key ] = value + widgets = get_form_widgets( trans, template, field_contents ) + else: + widgets = get_form_widgets( trans, template ) + else: + widgets = [] if params.get( 'rename_library_button', False ): old_name = library.name new_name = util.restore_text( params.name ) @@ -759,8 +776,7 @@ msg = 'Enter a valid name' return trans.fill_template( '/admin/library/library_info.mako', library=library, - restrict=params.get( 'restrict', False ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype='error' ) else: @@ -780,12 +796,10 @@ messagetype='done' ) ) return trans.fill_template( '/admin/library/library_info.mako', library=library, - restrict=params.get( 'restrict', False ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype=messagetype ) elif action == 'delete': - # TODO: need to revamp the way we delete libraries, folders and contained LibraryDatasets. def delete_folder( library_folder ): library_folder.refresh() for folder in library_folder.folders: @@ -939,6 +953,22 @@ msg=msg, messagetype=messagetype ) elif action == 'information': + # See if we have any associated templates + info_association = folder.get_info_association() + if info_association: + template = info_association.template + # See if we have any field contents + info = info_association.info + if info: + field_contents = {} + for index, value in enumerate( info.content ): + key = 'field_%i' % index + field_contents[ key ] = value + widgets = get_form_widgets( trans, template, field_contents ) + else: + widgets = get_form_widgets( trans, template ) + else: + widgets = [] if params.get( 'rename_folder_button', False ): old_name = folder.name new_name = util.restore_text( params.name ) @@ -948,8 +978,7 @@ return trans.fill_template( '/admin/library/folder_info.mako', folder=folder, library_id=library_id, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype='error' ) else: @@ -967,12 +996,10 @@ return trans.fill_template( '/admin/library/folder_info.mako', folder=folder, library_id=library_id, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype=messagetype ) elif action == 'delete': - # TODO: need to revamp the way we delete folders and contained LibraryDatasets def delete_folder( folder ): folder.refresh() for subfolder in folder.active_folders: @@ -1045,8 +1072,6 @@ return trans.fill_template( '/admin/library/library_dataset_info.mako', library_dataset=library_dataset, library_id=library_id, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), msg=msg, messagetype=messagetype ) elif action == 'permissions': @@ -1101,7 +1126,7 @@ created_ldda_ids = trans.webapp.controllers[ 'library_dataset' ].upload_dataset( trans, controller='admin', library_id=library_id, - folder_id=folder_id, + folder_id=folder_id, replace_dataset=replace_dataset, **kwd ) if created_ldda_ids: @@ -1126,6 +1151,13 @@ msg=util.sanitize_text( msg ), messagetype=messagetype ) ) elif not id or replace_dataset: + # See if we have any associated templates + info_association = folder.get_info_association() + if info_association: + template = info_association.template + widgets = get_form_widgets( trans, template ) + 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 @@ -1150,6 +1182,7 @@ last_used_build=last_used_build, roles=roles, history=history, + widgets=widgets, msg=msg, messagetype=messagetype, replace_dataset=replace_dataset ) @@ -1175,6 +1208,23 @@ id=library_id, msg=util.sanitize_text( msg ), messagetype='error' ) ) + # See if we have any associated templates + info_association = ldda.get_info_association() + if info_association: + template = info_association.template + # See if we have any field contents + info = info_association.info + log.debug("####In library_dataset_dataset_association, info.content: %s" % str( info.content)) + if info: + field_contents = {} + for index, value in enumerate( info.content ): + key = 'field_%i' % index + field_contents[ key ] = value + widgets = get_form_widgets( trans, template, field_contents ) + else: + widgets = get_form_widgets( trans, template ) + else: + widgets = [] if action == 'permissions': if params.get( 'update_roles_button', False ): permissions = {} @@ -1242,6 +1292,7 @@ library_id=library_id, deleted=deleted, show_deleted=show_deleted, + widgets=widgets, msg=msg, messagetype=messagetype ) elif action == 'edit_info': @@ -1255,8 +1306,7 @@ ldda=ldda, library_id=library_id, datatypes=ldatatypes, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype=messagetype ) else: @@ -1293,8 +1343,7 @@ ldda=ldda, library_id=library_id, datatypes=ldatatypes, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype=messagetype ) elif params.get( 'detect', False ): @@ -1312,8 +1361,7 @@ ldda=ldda, library_id=library_id, datatypes=ldatatypes, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype=messagetype ) elif params.get( 'delete', False ): @@ -1324,8 +1372,7 @@ ldda=ldda, library_id=library_id, datatypes=ldatatypes, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype=messagetype ) ldda.datatype.before_edit( ldda ) @@ -1340,8 +1387,7 @@ ldda=ldda, library_id=library_id, datatypes=ldatatypes, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype=messagetype ) elif ids: @@ -1553,26 +1599,17 @@ last_used_build=last_used_build, roles=roles, history=history, + widgets=widgets, msg=msg, messagetype=messagetype ) @web.expose @web.require_admin - def info_template( self, trans, library_id, id=None, num_fields=0, folder_id=None, ldda_id=None, library_dataset_id=None, **kwd ): + def info_template( self, trans, library_id, id=None, folder_id=None, ldda_id=None, **kwd ): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) - if not num_fields: - num_fields = 0 - else: - num_fields = int( num_fields ) - if params.get( 'new_template', False ): - action = 'new_template' - elif params.get( 'permissions', False ): - action = 'permissions' - else: - action = 'edit_template' if id: - library_item = trans.app.model.LibraryItemInfoTemplate.get( int( id ) ) + library_item = trans.app.model.FormDefinition.get( int( id ) ) library_item_desc = 'information template' response_action = 'info_template' response_id = id @@ -1586,174 +1623,51 @@ library_item_desc = 'library dataset' response_action = 'library_dataset_dataset_association' response_id = ldda_id - elif library_dataset_id: - library_item = trans.app.model.LibraryDataset.get( int( library_dataset_id ) ) - library_item_desc = 'dataset' - response_action = 'library_dataset_dataset_association' - response_id = library_item.library_dataset_dataset_association.id else: library_item = trans.app.model.Library.get( int( library_id ) ) library_item_desc = 'library' response_action = 'browse_library' response_id = library_id - if action == 'new_template': - if params.get( 'create_info_template_button', False ): - return trans.fill_template( '/admin/library/new_info_template.mako', - library_item_name=library_item.name, - library_item_desc=library_item_desc, - num_fields=num_fields, - library_id=library_id, - folder_id=folder_id, - ldda_id=ldda_id, - library_dataset_id=library_dataset_id, - msg=msg, - messagetype=messagetype ) - elif params.get( 'new_info_template_button', False ): - # Make sure at least 1 template field is filled in - # TODO: Eventually we'll enhance templates to allow for required and optional fields. - proceed = False - for i in range( int( params.get( 'set_num_fields', 0 ) ) ): - elem_name = params.get( 'new_element_name_%i' % i, None ) - elem_description = params.get( 'new_element_description_%i' % i, None ) - if elem_name or elem_description: - proceed = True - break - if not proceed: - msg = "At least 1 of the fields must be completed." - return trans.fill_template( '/admin/library/new_info_template.mako', - library_item_name=library_item.name, - library_item_desc=library_item_desc, - num_fields=num_fields, - library_id=library_id, - folder_id=folder_id, - ldda_id=ldda_id, - library_dataset_id=library_dataset_id, - msg=msg, - messagetype=messagetype ) - # Create template - liit = trans.app.model.LibraryItemInfoTemplate() - liit.name = util.restore_text( params.get( 'name', '' ) ) - liit.description = util.restore_text( params.get( 'description', '' ) ) - liit.flush() - # Inherit the template's permissions from the library_item - trans.app.security_agent.copy_library_permissions( library_item, liit ) - # Create template association + forms = get_all_forms( trans ) + if not forms: + msg = "There are no forms on which to base the template, so create a form and " + msg += "try again to add the information template to the %s." % library_item_desc + trans.response.send_redirect( web.url_for( controller='forms', + action='new', + new=True, + msg=msg, + messagetype='done' ) ) + if params.get( 'add', False ): + if params.get( 'add_info_template_button', False ): + form = trans.app.model.FormDefinition.get( int( kwd[ 'form_id' ] ) ) + #fields = list( copy.deepcopy( form.fields ) ) + form_values = trans.app.model.FormValues( form, [] ) + form_values.flush() if folder_id: - liit_assoc = trans.app.model.LibraryFolderInfoTemplateAssociation() - liit_assoc.folder = trans.app.model.LibraryFolder.get( folder_id ) + assoc = trans.app.model.LibraryFolderInfoAssociation( library_item, form, form_values ) elif ldda_id: - liit_assoc = trans.app.model.LibraryDatasetDatasetInfoTemplateAssociation() - ldda = trans.app.model.LibraryDatasetDatasetAssociation.get( ldda_id ) - liit_assoc.library_dataset_dataset_association = ldda - # This response_action method requires a folder_id - folder_id = ldda.library_dataset.folder.id - elif library_dataset_id: - liit_assoc = trans.app.model.LibraryDatasetInfoTemplateAssociation() - library_dataset = trans.app.model.LibraryDataset.get( library_dataset_id ) - liit_assoc.library_dataset = library_dataset - # This response_action method requires a folder_id - folder_id = library_dataset.folder.id + assoc = trans.app.model.LibraryDatasetDatasetInfoAssociation( library_item, form, form_values ) else: - # We'll always be sent a library_id - liit_assoc = trans.app.model.LibraryInfoTemplateAssociation() - liit_assoc.library = trans.app.model.Library.get( library_id ) - liit_assoc.library_item_info_template = liit - liit_assoc.flush() - # Create and add elements - for i in range( int( params.get( 'set_num_fields', 0 ) ) ): - elem_name = params.get( 'new_element_name_%i' % i, None ) - elem_description = params.get( 'new_element_description_%i' % i, None ) - if elem_description and not elem_name: - # If we have a description but no name, the description will be both - # ( a name cannot be empty, but a description can ) - elem_name = elem_description - if elem_name: - # Skip any elements that have a missing name - liit.add_element( name=elem_name, description=elem_description ) - msg = "The new information template has been created." - return trans.response.send_redirect( web.url_for( controller='admin', - action=response_action, - id=response_id, - library_id=library_id, - folder_id=folder_id, - msg=util.sanitize_text( msg ), - messagetype='done' ) ) - return trans.fill_template( '/admin/library/create_info_template.mako', - library_item=library_item, - library_id=library_id, - msg=msg, - messagetype=messagetype ) - elif action == 'edit_template': - define_or_save = 'define' - edit_info_template_button = params.get( 'edit_info_template_button', False ) - if edit_info_template_button: - if edit_info_template_button == 'Define fields': - define_or_save = 'save' - else: - define_or_save = 'define' - # Save changes to existing attributes, only set name if nonempty/nonNone is passed, but always set description - name = params.get( 'name', None ) - if name: - library_item.name = name - library_item.description = params.get( 'description', '' ) - library_item.flush() - # Save changes to exisiting elements - for elem_id in util.listify( params.get( 'element_ids', [] ) ): - liit_element = trans.app.model.LibraryItemInfoTemplateElement.get( elem_id ) - name = params.get( 'element_name_%s' % elem_id, None ) - if name: - liit_element.name = name - liit_element.description = params.get( 'element_description_%s' % elem_id, None ) - liit_element.flush() - # Add new elements - for i in range( int( params.get( 'set_num_fields', 0 ) ) ): - elem_name = params.get( 'new_element_name_%i' % i, None ) - elem_description = params.get( 'new_element_description_%i' % i, None ) - # Skip any elements that have a missing name and description - if not elem_name: - # If we have a description but no name, the description will be both - # ( a name cannot be empty, but a description can ) - elem_name = elem_description - if elem_name: - library_item.add_element( name=elem_name, description=elem_description ) - library_item.refresh() - msg = "Information template '%s' has been updated" % library_item.name - return trans.fill_template( "/admin/library/edit_info_template.mako", - liit=library_item, - num_fields=num_fields, - library_id=library_id, - library_dataset_id=library_dataset_id, - ldda_id=ldda_id, - folder_id=folder_id, + assoc = trans.app.model.LibraryInfoAssociation( library_item, form, form_values ) + assoc.flush() + msg = 'An information template based on the form "%s" has been added to this %s.' % ( form.name, library_item_desc ) + trans.response.send_redirect( web.url_for( controller='admin', + action=response_action, + id=response_id, + msg=msg, + message_type='done' ) ) + return trans.fill_template( '/admin/library/select_info_template.mako', library_item_name=library_item.name, library_item_desc=library_item_desc, - define_or_save=define_or_save, - msg=msg, - messagetype=messagetype ) - elif action == 'permissions': - if params.get( 'update_roles_button', False ): - permissions = {} - for k, v in trans.app.model.Library.permitted_actions.items(): - in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( kwd.get( k + '_in', [] ) ) ] - permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles - trans.app.security_agent.set_all_library_permissions( library_item, permissions ) - library_item.refresh() - msg = "Permissions updated for information template '%s'" % library_item.name - return trans.response.send_redirect( web.url_for( controller='admin', - action='info_template', - library_id=library_id, - id=id, - permissions=True, - msg=util.sanitize_text( msg ), - messagetype='done' ) ) - return trans.fill_template( '/admin/library/info_template_permissions.mako', - liit=library_item, library_id=library_id, + folder_id=folder_id, + ldda_id=ldda_id, + forms=forms, msg=msg, messagetype=messagetype ) @web.expose @web.require_admin - def library_item_info( self, trans, library_id, id=None, library_item_id=None, library_item_type=None, **kwd ): + def edit_template_info( self, trans, library_id, num_widgets, library_item_id=None, library_item_type=None, **kwd ): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) @@ -1768,8 +1682,6 @@ library_item = trans.app.model.LibraryDatasetDatasetAssociation.get( library_item_id ) # This response_action method requires a folder_id folder_id = library_item.library_dataset.folder.id - elif library_item_type == 'library_item_info_elememt': - library_item = trans.app.model.LibraryItemInfoElement.get( library_item_id ) else: msg = "Invalid library item type ( %s ) specified, id ( %s )" % ( str( library_item_type ), str( library_item_id ) ) return trans.response.send_redirect( web.url_for( controller='admin', @@ -1777,107 +1689,47 @@ id=library_id, msg=util.sanitize_text( msg ), messagetype='error' ) ) - if params.get( 'new_info', False ): - if library_item: - if params.get( 'create_new_info_button', False ): - library_item_info_template_id = params.get( 'library_item_info_template_id', None ) - library_item_info_template = trans.app.model.LibraryItemInfoTemplate.get( int( library_item_info_template_id ) ) - # Make sure at least 1 template field is filled in - # TODO: Eventually we'll enhance templates to allow for required and optional fields. - proceed = False - for template_element in library_item_info_template.elements: - if params.get( "info_element_%s_%s" % ( library_item_info_template.id, template_element.id ), None ): - proceed = True - break - if not proceed: - msg = "At least 1 of the fields must be completed." - return trans.response.send_redirect( web.url_for( controller='admin', - action=library_item_type, - id=library_item.id, - library_id=library_id, - folder_id=folder_id, - edit_info=True, - msg=util.sanitize_text( msg ), - messagetype='error' ) ) - user = trans.get_user() - library_item_info = trans.app.model.LibraryItemInfo( user=user ) - library_item_info.library_item_info_template = library_item_info_template - library_item_info.flush() - trans.app.security_agent.copy_library_permissions( library_item_info_template, library_item_info ) - for template_element in library_item_info_template.elements: - info_element_value = params.get( "info_element_%s_%s" % ( library_item_info_template.id, template_element.id ), None ) - info_element = trans.app.model.LibraryItemInfoElement() - info_element.contents = info_element_value - info_element.library_item_info_template_element = template_element - info_element.library_item_info = library_item_info - info_element.flush() - info_association_class = None - for item_class, permission_class, info_association_class in trans.app.security_agent.library_item_assocs: - if isinstance( library_item, item_class ): - break - if info_association_class: - library_item_info_association = info_association_class( user=user ) - library_item_info_association.set_library_item( library_item ) - library_item_info_association.library_item_info = library_item_info - library_item_info_association.flush() - else: - raise 'Invalid class (%s) specified for library_item (%s)' % ( library_item.__class__, library_item.__class__.__name__ ) - msg = 'The information has been saved' - return trans.response.send_redirect( web.url_for( controller='admin', - action=library_item_type, - id=library_item.id, - library_id=library_id, - folder_id=folder_id, - edit_info=True, - msg=util.sanitize_text( msg ), - messagetype='done' ) ) - return trans.fill_template( "/admin/library/new_info.mako", - library_id=library_id, - library_item=library_item, - library_item_type=library_item_type, - msg=msg, - messagetype=messagetype ) - elif params.get( 'edit_info', False ): - if params.get( 'edit_info_button', False ): - ids = util.listify( id ) - for id in ids: - library_item_info_element = trans.app.model.LibraryItemInfoElement.get( int( id ) ) - new_contents = util.restore_text( params.get( ( 'info_element_%s' % id ), '' ) ) - library_item_info_element.contents = new_contents - library_item_info_element.flush() - msg = 'The information has been updated.' - return trans.response.send_redirect( web.url_for( controller='admin', - action=library_item_type, - id=library_item.id, - library_id=library_id, - folder_id=folder_id, - edit_info=True, - msg=util.sanitize_text( msg ), - messagetype='done' ) ) - elif params.get( 'permissions', False ): - if params.get( 'update_roles_button', False ): - permissions = {} - for k, v in trans.app.model.Library.permitted_actions.items(): - in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( kwd.get( k + '_in', [] ) ) ] - permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles - trans.app.security_agent.set_all_library_permissions( library_item.library_item_info, permissions ) - library_item.library_item_info.refresh() - library_item.refresh() - msg = "Permissions updated for field '%s'" % library_item.library_item_info_template_element.name - return trans.response.send_redirect( web.url_for( controller='admin', - action='library_item_info', - library_id=library_id, - id=id, - library_item_id=library_item_id, - library_item_type=library_item_type, - permissions=True, - msg=util.sanitize_text( msg ), - messagetype='done' ) ) - return trans.fill_template( '/admin/library/info_permissions.mako', - library_item_info_element=library_item, - library_id=library_id, - msg=msg, - messagetype=messagetype ) + # Save updated template field contents + field_contents = [] + for index in range( int( num_widgets ) ): + field_contents.append( util.restore_text( params.get( 'field_%i' % ( index ), '' ) ) ) + if field_contents: + # Since information templates are inherited, the template fields can be displayed on the information + # page for a folder or library dataset when it has no info_association object. If the user has added + # field contents on an inherited template via a parent's info_association, we'll need to create a new + # form_values and info_association for the current object. + info_association = library_item.get_info_association( restrict=True ) + if info_association: + template = info_association.template + info = info_association.info + form_values = trans.app.model.FormValues.get( info.id ) + # Update existing content only if it has changed + if form_values.content != field_contents: + form_values.content = field_contents + form_values.flush() + else: + # Inherit the next available info_association so we can get the template + info_association = library_item.get_info_association() + template = info_association.template + # Create a new FormValues object + form_values = trans.app.model.FormValues( template, field_contents ) + form_values.flush() + # Create a new info_association between the current library item and form_values + if library_item_type == 'folder': + info_association = trans.app.model.LibraryFolderInfoAssociation( library_item, template, form_values ) + info_association.flush() + elif library_item_type == 'library_dataset_dataset_association': + info_association = trans.app.model.LibraryDatasetDatasetInfoAssociation( library_item, template, form_values ) + info_association.flush() + msg = 'The information has been updated.' + return trans.response.send_redirect( web.url_for( controller='admin', + action=library_item_type, + id=library_item.id, + library_id=library_id, + folder_id=folder_id, + edit_info=True, + msg=util.sanitize_text( msg ), + messagetype='done' ) ) @web.expose @web.require_admin def download_dataset_from_folder(self, trans, id, library_id=None, **kwd): @@ -2101,19 +1953,6 @@ else: last_updated[job.id] = '%s minutes' % int( delta.seconds / 60 ) return trans.fill_template( '/admin/jobs.mako', jobs = jobs, last_updated = last_updated, cutoff = cutoff, msg = msg, messagetype = messagetype ) - - def _get_all_forms(self, trans, all_versions=False): - ''' - This method returns all the latest forms from the - form_definition_current table if all_versions is set to True. Otherwise - this method return all the versions of all the forms from form_definition - table - ''' - if all_versions: - return trans.app.model.FormDefinition.query().all() - else: - fdc_list = trans.app.model.FormDefinitionCurrent.query().all() - return [fdc.latest_form for fdc in fdc_list] @web.expose @web.require_admin def manage_request_types( self, trans, **kwd ): @@ -2121,7 +1960,7 @@ msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) show_filter = util.restore_text( params.get( 'show_filter', 'Active' ) ) - forms = self._get_all_forms(trans, all_versions=True) + forms = get_all_forms(trans, all_versions=True) request_types_list = trans.app.model.RequestType.query().all() if show_filter == 'All': request_types = request_types_list @@ -2141,12 +1980,12 @@ params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) - if params.get('create', False) == 'True': + if params.get( 'create', False ): return trans.fill_template( '/admin/requests/create_request_type.mako', - forms=self._get_all_forms(trans, all_versions=False), + forms=get_all_forms( trans ), msg=msg, messagetype=messagetype) - elif params.get('add_states', False) == 'True': + elif params.get( 'add_states', False ): return trans.fill_template( '/admin/requests/add_states.mako', sample_type_name=util.restore_text( params.name ), desc=util.restore_text( params.description ), @@ -2155,11 +1994,11 @@ sample_form_id=int(util.restore_text( params.sample_form_id )), msg=msg, messagetype=messagetype) - elif params.get('save_new', False) == 'True': + elif params.get( 'save_new', False ): st, msg = self._save_request_type(trans, **kwd) if not st: return trans.fill_template( '/admin/requests/create_request_type.mako', - forms=self._get_all_forms(trans, all_versions=False), + forms=get_all_forms( trans ), msg=msg, messagetype='error') return trans.response.send_redirect( web.url_for( controller='admin', @@ -2171,7 +2010,7 @@ ss_list = trans.app.model.SampleState.filter(trans.app.model.SampleState.table.c.request_type_id == rt.id).all() return trans.fill_template( '/admin/requests/view_request_type.mako', request_type=rt, - forms=self._get_all_forms(trans, all_versions=False), + forms=get_all_forms( trans ), states_list=ss_list, deleted=False, show_deleted=False, diff -r eb09beda047d -r 50ce3d8388f8 lib/galaxy/web/controllers/forms.py --- a/lib/galaxy/web/controllers/forms.py Fri Aug 07 12:55:07 2009 -0400 +++ b/lib/galaxy/web/controllers/forms.py Fri Aug 07 16:11:14 2009 -0400 @@ -10,7 +10,6 @@ import copy log = logging.getLogger( __name__ ) - class Forms( BaseController ): @web.expose @@ -44,45 +43,30 @@ show_filter=show_filter, msg=msg, messagetype=messagetype ) - def _get_all_forms(self, trans, all_versions=False): - ''' - This method returns all the latest forms from the - form_definition_current table if all_versions is set to True. Otherwise - this method return all the versions of all the forms from form_definition - table - ''' - if all_versions: - return trans.app.model.FormDefinition.query().all() - else: - fdc_list = trans.app.model.FormDefinitionCurrent.query().all() - return [fdc.latest_form for fdc in fdc_list] @web.expose @web.require_admin def new( self, trans, **kwd ): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) - messagetype = params.get( 'messagetype', 'done' ) - if params.get('new', False) and not params.get('create_form', False): - self.current_form = {} - self.current_form['name'] = 'New Form' - self.current_form['desc'] = '' - self.current_form['fields'] = [] - inputs = [ ( 'Name', TextField('name', 40,self.current_form['name'] ) ), - ( 'Description', TextField('description', 40, self.current_form['desc']) ), - ( 'Import from csv file (Optional)', TextField('csv_file', 40, '') ) ] - return trans.fill_template( '/admin/forms/create_form.mako', - inputs=inputs, - msg=msg, - messagetype=messagetype ) - elif params.get('create_form', False) == 'True': - if 'submitted' in params.new: - self.num_add_fields = 0 - fd, msg = self.__save_form(trans, fdc_id=None, **kwd) - self.__get_saved_form(fd) - return trans.response.send_redirect( web.url_for( controller='forms', - action='edit', - form_id=fd.id, - show_form=True) ) + messagetype = params.get( 'messagetype', 'done' ) + if params.get( 'create_form_button', False ): + fd, msg = self.__save_form( trans, fdc_id=None, **kwd ) + self.__get_saved_form( fd ) + return trans.response.send_redirect( web.url_for( controller='forms', + action='edit', + form_id=fd.id, + show_form=True ) ) + self.current_form = {} + self.current_form[ 'name' ] = 'New Form' + self.current_form[ 'desc' ] = '' + self.current_form[ 'fields' ] = [] + inputs = [ ( 'Name', TextField( 'name', 40, self.current_form[ 'name' ] ) ), + ( 'Description', TextField( 'description', 40, self.current_form[ 'desc' ] ) ), + ( 'Import from csv file (Optional)', TextField( 'csv_file', 40, '' ) ) ] + return trans.fill_template( '/admin/forms/create_form.mako', + inputs=inputs, + msg=msg, + messagetype=messagetype ) @web.expose @web.require_admin def delete( self, trans, **kwd ): @@ -111,73 +95,75 @@ @web.require_admin def edit( self, trans, **kwd ): ''' - This callback method is for handling all the editing functions like: - remaning fields, adding/deleting fields, changing fields attributes + This callback method is for handling all the editing functions like + renaming fields, adding/deleting fields, changing fields attributes. ''' params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) - fd = trans.app.model.FormDefinition.get(int(util.restore_text( params.form_id ))) - # SHOW THE FORM FOR EDITING. - if params.get('show_form', False) == 'True': - self.__get_saved_form(fd) - # the following two dicts store the unsaved select box options + form_id = params.get( 'form_id', None ) + if not form_id: + msg = 'Invalid form id %s' % str( form_id ) + trans.response.send_redirect( web.url_for( controller='forms', + action='manage', + msg=msg, + messagetype='error' ) ) + fd = trans.app.model.FormDefinition.get( int( params.form_id ) ) + # Show the form for editing + if params.get( 'show_form', False ): + self.__get_saved_form( fd ) + # The following two dicts store the unsaved select box options self.del_options = {} self.add_options = {} - return self.__show(trans=trans, form=fd, msg=msg, - messagetype=messagetype, **kwd) - # DELETE FIELD - elif params.get('remove_button', False): - self.__update_current_form(**kwd) - index = int(params.get('remove_button', None).split(' ')[2])-1 - self.__remove_field(index) - return self.__show(trans=trans, form=fd, msg=msg, - messagetype=messagetype, **kwd) - # SAVE CHANGES - elif params.get('save_changes_button', False) == 'Save': - self.__update_current_form(**kwd) - fd_new, msg = self.__save_form(trans, fd.form_definition_current.id, **kwd) + if fd.fields: + return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) + else: + # If the form is empty, we'll simulate a click on the add_field_button so the + # form will be displayed with the field choice, saving a mouse click. + return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, empty_form=True, **kwd ) + # Delete a field + elif params.get( 'remove_button', False ): + self.__update_current_form( **kwd ) + index = int( kwd[ 'remove_button' ].split( ' ' )[2] ) - 1 + self.__remove_field( index ) + return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) + # Save changes + elif params.get( 'save_changes_button', False ): + self.__update_current_form( **kwd ) + fd_new, msg = self.__save_form( trans, fd.form_definition_current.id, **kwd ) if not fd_new: - return self.__show(trans=trans, form=fd, msg=msg, - messagetype='error', **kwd) + return self.__show( trans=trans, form=fd, msg=msg, messagetype='error', **kwd ) else: fd = fd_new msg = "The form '%s' has been updated with the changes." % fd.name - return self.__show(trans=trans, form=fd, msg=msg, - messagetype=messagetype, **kwd) - #ADD A FIELD - elif params.get('add_field_button', False) == 'Add field': - self.__update_current_form(**kwd) + return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) + #Add a field + elif params.get( 'add_field_button', False ): + self.__update_current_form( **kwd ) self.__add_field() # show the form again with one empty field - return self.__show(trans=trans, form=fd, msg=msg, - messagetype=messagetype, **kwd) - # SHOW FORM READ ONLY - elif params.get('read_only', False): + return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) + # Show form read-only + elif params.get( 'read_only', False ): return trans.fill_template( '/admin/forms/show_form_read_only.mako', form=fd, msg=msg, messagetype=messagetype ) - # REFRESH PAGE, SelectField is selected/deselected as the type of a field - elif params.get('refresh', False) == 'true': - self.__update_current_form(**kwd) - return self.__show(trans=trans, form=fd, msg=msg, - messagetype=messagetype, **kwd) - # REMOVE SelectField OPTION - elif params.get('select_box_options', False) == 'remove': - #self.__update_current_form(**kwd) - index = int(params.get( 'field_index', None )) - option = int(params.get( 'option_index', None )) - del self.current_form['fields'][index]['selectlist'][option] - return self.__show(trans=trans, form=fd, msg=msg, - messagetype=messagetype, **kwd) - # ADD SelectField OPTION - elif params.get('select_box_options', False) == 'add': - #self.__update_current_form(**kwd) - index = int(params.get( 'field_index', None )) - self.current_form['fields'][index]['selectlist'].append('') - return self.__show(trans=trans, form=fd, msg=msg, - messagetype=messagetype, **kwd) + # Refresh page, SelectField is selected/deselected as the type of a field + elif params.get( 'refresh', False ): + self.__update_current_form( **kwd ) + return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) + # Remove SelectField option + elif params.get( 'select_box_options', False ) == 'remove': + index = int( kwd[ 'field_index' ] ) + option = int( kwd[ 'option_index' ] ) + del self.current_form[ 'fields' ][ index ][ 'selectlist' ][ option ] + return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) + # Add SelectField option + elif params.get( 'select_box_options', False ) == 'add': + index = int( kwd[ 'field_index' ] ) + self.current_form[ 'fields' ][ index ][ 'selectlist' ].append( '' ) + return self.__show( trans=trans, form=fd, msg=msg, messagetype=messagetype, **kwd ) def __remove_field(self, index): del self.current_form['fields'][index] def __add_field(self): @@ -193,6 +179,10 @@ self.current_form['fields'].append(empty_field) def __get_field(self, index, **kwd): params = util.Params( kwd ) + #TODO: RC this needs to be handled so that it does not throw an exception. + # To reproduce, create a new form, click the "add field" button, click the + # browser back arrow, then click the "add field" button again. + # You should never attempt to "restore_text()" on a None object... name = util.restore_text( params.get( 'field_name_%i' % index, None ) ) helptext = util.restore_text( params.get( 'field_helptext_%i' % index, None ) ) required = params.get( 'field_required_%i' % index, False ) @@ -314,9 +304,6 @@ trans.sa_session.save_or_update( fdc ) trans.sa_session.flush() msg = "The new form named '%s' has been created. " % (fd.name) - request_types = trans.app.model.RequestType.query().all() - if not request_types: - msg = msg + "Now you can create requests to associate with this form." return fd, msg class FieldUI(object): @@ -381,18 +368,31 @@ def label(self): return str(self.index)+'.'+self.label - def __show(self, trans, form, msg=None, messagetype='done', **kwd): + def __show( self, trans, form, msg='', messagetype='done', empty_form=False, **kwd ): ''' - This method displays the form and any of the changes made to it + This method displays the form and any of the changes made to it, + The empty_form param allows for this method to simulate clicking + the "add_field_button" on the edit_form.mako page so that the page + is displayed with the first field to be added, saving a mouse click. ''' + if empty_form: + # Send params that will simulate a button click on the add_field_button + # button on edit_form.mako. + param_dict = { 'form_id' : str( form.id ), + 'num_fields' : '0', + 'refresh' : 'true', + 'name' : form.name, + 'description' : form.desc, + 'add_field_button' : 'Add field' } + self.edit( trans, **param_dict ) params = util.Params( kwd ) # name & description - form_details = [ ( 'Name', TextField('name', 40, self.current_form['name']) ), - ( 'Description', TextField('description', 40, self.current_form['desc']) ) ] + form_details = [ ( 'Name', TextField( 'name', 40, self.current_form[ 'name' ] ) ), + ( 'Description', TextField( 'description', 40, self.current_form[ 'desc' ] ) ) ] # fields field_details = [] - for index, field in enumerate(self.current_form['fields']): - field_ui = self.FieldUI(index, field) + for index, field in enumerate( self.current_form[ 'fields' ] ): + field_ui = self.FieldUI( index, field ) field_details.append( field_ui.get() ) return trans.fill_template( '/admin/forms/edit_form.mako', form_details=form_details, @@ -401,3 +401,59 @@ field_types=BaseField.form_field_types(), msg=msg, messagetype=messagetype ) + +# Common methods for all components that use forms +def get_all_forms( trans, all_versions=False, filter=None ): + ''' + Return all the latest forms from the form_definition_current table + if all_versions is set to True. Otherwise return all the versions + of all the forms from the form_definition table. + + TODO: when we add the concept of a form_definition_type ( e.g., + 'request_header', 'request_sample', 'library_template' ), filter + the query if received filter is not None. + ''' + if all_versions: + return trans.app.model.FormDefinition.query().all() + else: + fdc_list = trans.app.model.FormDefinitionCurrent.query().all() + return [ fdc.latest_form for fdc in fdc_list ] +def get_form_widgets( trans, form, contents={} ): + ''' + Return the list of widgets that comprise a form definition, + including field contents if any. + ''' + widgets = [] + for index, field in enumerate( form.fields ): + field_name = 'field_%i' % index + if field_name in contents: + value = contents[ field_name ] + elif 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 = '' + field_widget = eval( field[ 'type' ] )( field_name ) + if field[ 'type' ] == 'TextField': + field_widget.set_size( 40 ) + field_widget.value = value + elif field[ 'type' ] == 'TextArea': + field_widget.set_size( 3, 40 ) + field_widget.value = value + elif field[ 'type' ] == 'SelectField': + for option in field[ 'selectlist' ]: + if option == value: + field_widget.add_option( option, option, selected=True ) + else: + field_widget.add_option( option, option ) + elif field[ 'type' ] == 'CheckboxField': + field_widget.checked = value + if field[ 'required' ] == 'required': + req = 'Required' + else: + req = 'Optional' + widgets.append( dict( label=field[ 'label' ], + widget=field_widget, + helptext='%s (%s)' % ( field[ 'helptext' ], req ) ) ) + return widgets diff -r eb09beda047d -r 50ce3d8388f8 lib/galaxy/web/controllers/library.py --- a/lib/galaxy/web/controllers/library.py Fri Aug 07 12:55:07 2009 -0400 +++ b/lib/galaxy/web/controllers/library.py Fri Aug 07 16:11:14 2009 -0400 @@ -2,6 +2,7 @@ from galaxy.model.orm import * from galaxy.datatypes import sniff from galaxy import util +from galaxy.web.controllers.forms import get_all_forms, get_form_widgets from galaxy.util.streamball import StreamBall import logging, tempfile, zipfile, tarfile, os, sys @@ -130,6 +131,21 @@ msg=util.sanitize_text( msg ), messagetype='error' ) ) if action == 'information': + # See if we have any associated templates + if library.info_association: + template = library.info_association[0].template + # See if we have any field contents + info = library.info_association[0].info + if info: + field_contents = {} + for index, value in enumerate( info.content ): + key = 'field_%i' % index + field_contents[ key ] = value + widgets = get_form_widgets( trans, template, field_contents ) + else: + widgets = get_form_widgets( trans, template ) + else: + widgets = [] if params.get( 'rename_library_button', False ): old_name = library.name new_name = util.restore_text( params.name ) @@ -138,8 +154,7 @@ msg = 'Enter a valid name' return trans.fill_template( '/library/library_info.mako', library=library, - restrict=params.get( 'restrict', False ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype='error' ) else: @@ -159,8 +174,7 @@ messagetype='done' ) ) return trans.fill_template( '/library/library_info.mako', library=library, - restrict=params.get( 'restrict', False ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype=messagetype ) elif action == 'permissions': @@ -377,8 +391,6 @@ return trans.fill_template( '/library/library_dataset_info.mako', library_dataset=library_dataset, library_id=library_id, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), msg=msg, messagetype=messagetype ) elif action == 'permissions': @@ -456,6 +468,22 @@ id=library_id, msg=util.sanitize_text( msg ), messagetype='error' ) ) + # See if we have any associated templates + info_association = folder.get_info_association() + if info_association: + template = info_association.template + # See if we have any field contents + info = info_association.info + if info: + field_contents = {} + for index, value in enumerate( info.content ): + key = 'field_%i' % index + field_contents[ key ] = value + widgets = get_form_widgets( trans, template, field_contents ) + else: + widgets = get_form_widgets( trans, template ) + else: + widgets = [] if action == 'permissions': if params.get( 'update_roles_button', False ): # The user clicked the Save button on the 'Associate With Roles' form @@ -497,6 +525,7 @@ return trans.fill_template( '/library/ldda_info.mako', ldda=ldda, library_id=library_id, + widgets=widgets, msg=msg, messagetype=messagetype ) elif action == 'edit_info': @@ -520,8 +549,7 @@ ldda=ldda, library_id=library_id, datatypes=ldatatypes, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype=messagetype ) elif params.get( 'save', False ): @@ -562,8 +590,7 @@ ldda=ldda, library_id=library_id, datatypes=ldatatypes, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype=messagetype ) elif params.get( 'detect', False ): @@ -588,8 +615,7 @@ ldda=ldda, library_id=library_id, datatypes=ldatatypes, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype=messagetype ) elif params.get( 'delete', False ): @@ -607,8 +633,7 @@ ldda=ldda, library_id=library_id, datatypes=ldatatypes, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype=messagetype ) if trans.app.security_agent.allow_action( trans.user, @@ -626,12 +651,11 @@ ldda=ldda, library_id=library_id, datatypes=ldatatypes, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype=messagetype ) elif ids: - # Multiple ids specfied, display permission form, permissions will be updated for all simultaneously. + # Multiple ids specified, display permission form, permissions will be updated for all simultaneously. lddas = [] for id in [ int( id ) for id in ids ]: ldda = trans.app.model.LibraryDatasetDatasetAssociation.get( id ) @@ -737,7 +761,7 @@ controller='library', library_id=library_id, folder_id=folder_id, - replace_dataset=replace_dataset, + replace_dataset=replace_dataset, **kwd ) if created_ldda_ids: ldda_id_list = created_ldda_ids.split( ',' ) @@ -965,6 +989,22 @@ msg=msg, messagetype=messagetype ) elif action == 'information': + # See if we have any associated templates + info_association = folder.get_info_association() + if info_association: + template = info_association.template + # See if we have any field contents + info = info_association.info + if info: + field_contents = {} + for index, value in enumerate( info.content ): + key = 'field_%i' % index + field_contents[ key ] = value + widgets = get_form_widgets( trans, template, field_contents ) + else: + widgets = get_form_widgets( trans, template ) + else: + widgets = [] if params.get( 'rename_folder_button', False ): if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MODIFY, @@ -977,8 +1017,7 @@ return trans.fill_template( "/library/folder_info.mako", folder=folder, library_id=library_id, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype='error' ) else: @@ -998,15 +1037,13 @@ return trans.fill_template( "/library/folder_info.mako", folder=folder, library_id=library_id, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype='error' ) return trans.fill_template( '/library/folder_info.mako', folder=folder, library_id=library_id, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), + widgets=widgets, msg=msg, messagetype=messagetype ) elif action == 'permissions': @@ -1044,22 +1081,12 @@ msg=msg, messagetype=messagetype ) @web.expose - def info_template( self, trans, library_id, id=None, num_fields=0, folder_id=None, ldda_id=None, library_dataset_id=None, **kwd ): + def info_template( self, trans, library_id, id=None, folder_id=None, ldda_id=None, **kwd ): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) - if not num_fields: - num_fields = 0 - else: - num_fields = int( num_fields ) - if params.get( 'new_template', False ): - action = 'new_template' - elif params.get( 'permissions', False ): - action = 'permissions' - else: - action = 'edit_template' if id: - library_item = trans.app.model.LibraryItemInfoTemplate.get( int( id ) ) + library_item = trans.app.model.FormDefinition.get( int( id ) ) library_item_desc = 'information template' response_action = 'info_template' response_id = id @@ -1073,176 +1100,41 @@ library_item_desc = 'library dataset' response_action = 'library_dataset_dataset_association' response_id = ldda_id - elif library_dataset_id: - library_item = trans.app.model.LibraryDataset.get( int( library_dataset_id ) ) - library_item_desc = 'dataset' - response_action = 'library_dataset_dataset_association' - response_id = library_item.library_dataset_dataset_association.id else: library_item = trans.app.model.Library.get( int( library_id ) ) library_item_desc = 'library' response_action = 'browse_library' response_id = library_id - if action == 'new_template': - if params.get( 'create_info_template_button', False ): - return trans.fill_template( '/library/new_info_template.mako', - library_item=library_item, - library_item_name=library_item.name, - library_item_desc=library_item_desc, - num_fields=num_fields, - library_id=library_id, - folder_id=folder_id, - ldda_id=ldda_id, - library_dataset_id=library_dataset_id, - msg=msg, - messagetype=messagetype ) - elif params.get( 'new_info_template_button', False ): - # Make sure at least 1 template field is filled in - # TODO: Eventually we'll enhance templates to allow for required and optional fields. - proceed = False - for i in range( int( params.get( 'set_num_fields', 0 ) ) ): - elem_name = params.get( 'new_element_name_%i' % i, None ) - elem_description = params.get( 'new_element_description_%i' % i, None ) - if elem_name or elem_description: - proceed = True - break - if not proceed: - msg = "At least 1 of the fields must be completed." - return trans.fill_template( '/library/new_info_template.mako', - library_item=library_item, - library_item_name=library_item.name, - library_item_desc=library_item_desc, - num_fields=num_fields, - library_id=library_id, - folder_id=folder_id, - ldda_id=ldda_id, - library_dataset_id=library_dataset_id, - msg=msg, - messagetype=messagetype ) - # Create template - liit = trans.app.model.LibraryItemInfoTemplate() - liit.name = util.restore_text( params.get( 'name', '' ) ) - liit.description = util.restore_text( params.get( 'description', '' ) ) - liit.flush() - # Inherit the template's permissions from the library_item - trans.app.security_agent.copy_library_permissions( liit, library_item ) - # Create template association + if params.get( 'add', False ): + if params.get( 'add_info_template_button', False ): + form = trans.app.model.FormDefinition.get( int( kwd[ 'form_id' ] ) ) + #fields = list( copy.deepcopy( form.fields ) ) + form_values = trans.app.model.FormValues( form, [] ) + form_values.flush() if folder_id: - liit_assoc = trans.app.model.LibraryFolderInfoTemplateAssociation() - liit_assoc.folder = trans.app.model.LibraryFolder.get( folder_id ) + assoc = trans.app.model.LibraryFolderInfoAssociation( library_item, form, form_values ) elif ldda_id: - liit_assoc = trans.app.model.LibraryDatasetDatasetInfoTemplateAssociation() - ldda = trans.app.model.LibraryDatasetDatasetAssociation.get( ldda_id ) - liit_assoc.library_dataset_dataset_association = ldda - # This response_action method requires a folder_id - folder_id = ldda.library_dataset.folder.id - elif library_dataset_id: - liit_assoc = trans.app.model.LibraryDatasetInfoTemplateAssociation() - library_dataset = trans.app.model.LibraryDataset.get( library_dataset_id ) - liit_assoc.library_dataset = library_dataset - # This response_action method requires a folder_id - folder_id = library_dataset.folder.id + assoc = trans.app.model.LibraryDatasetDatasetInfoAssociation( library_item, form, form_values ) else: - # We'll always be sent a library_id - liit_assoc = trans.app.model.LibraryInfoTemplateAssociation() - liit_assoc.library = trans.app.model.Library.get( library_id ) - liit_assoc.library_item_info_template = liit - liit_assoc.flush() - # Create and add elements - for i in range( int( params.get( 'set_num_fields', 0 ) ) ): - elem_name = params.get( 'new_element_name_%i' % i, None ) - elem_description = params.get( 'new_element_description_%i' % i, None ) - if elem_description and not elem_name: - # If we have a description but no name, the description will be both - # ( a name cannot be empty, but a description can ) - elem_name = elem_description - if elem_name: - # Skip any elements that have a missing name - liit.add_element( name=elem_name, description=elem_description ) - msg = "The new information template has been created." - return trans.response.send_redirect( web.url_for( controller='library', - action=response_action, - id=response_id, - library_id=library_id, - folder_id=folder_id, - msg=util.sanitize_text( msg ), - messagetype='done' ) ) - return trans.fill_template( '/library/create_info_template.mako', - library_item=library_item, - library_id=library_id, - msg=msg, - messagetype=messagetype ) - elif action == 'edit_template': - define_or_save = 'define' - edit_info_template_button = params.get( 'edit_info_template_button', False ) - if edit_info_template_button: - if edit_info_template_button == 'Define fields': - define_or_save = 'save' - else: - define_or_save = 'define' - # Save changes to existing attributes, only set name if nonempty/nonNone is passed, but always set description - name = params.get( 'name', None ) - if name: - library_item.name = name - library_item.description = params.get( 'description', '' ) - library_item.flush() - # Save changes to exisiting elements - for elem_id in util.listify( params.get( 'element_ids', [] ) ): - liit_element = trans.app.model.LibraryItemInfoTemplateElement.get( elem_id ) - name = params.get( 'element_name_%s' % elem_id, None ) - if name: - liit_element.name = name - liit_element.description = params.get( 'element_description_%s' % elem_id, None ) - liit_element.flush() - # Add new elements - for i in range( int( params.get( 'set_num_fields', 0 ) ) ): - elem_name = params.get( 'new_element_name_%i' % i, None ) - elem_description = params.get( 'new_element_description_%i' % i, None ) - # Skip any elements that have a missing name and description - if not elem_name: - # If we have a description but no name, the description will be both - # ( a name cannot be empty, but a description can ) - elem_name = elem_description - if elem_name: - library_item.add_element( name=elem_name, description=elem_description ) - library_item.refresh() - msg = 'Information template %s has been updated' % library_item.name - return trans.fill_template( "/library/edit_info_template.mako", - liit=library_item, - num_fields=num_fields, - library_id=library_id, - library_dataset_id=library_dataset_id, - ldda_id=ldda_id, - folder_id=folder_id, + assoc = trans.app.model.LibraryInfoAssociation( library_item, form, form_values ) + assoc.flush() + msg = 'An information template based on the form "%s" has been added to this %s.' % ( form.name, library_item_desc ) + trans.response.send_redirect( web.url_for( controller='library', + action=response_action, + id=response_id, + msg=msg, + message_type='done' ) ) + return trans.fill_template( '/library/select_info_template.mako', library_item_name=library_item.name, library_item_desc=library_item_desc, - define_or_save=define_or_save, - msg=msg, - messagetype=messagetype ) - elif action == 'permissions': - if params.get( 'update_roles_button', False ): - # The user clicked the Save button on the 'Associate With Roles' form - permissions = {} - for k, v in trans.app.model.Library.permitted_actions.items(): - in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( kwd.get( k + '_in', [] ) ) ] - permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles - trans.app.security_agent.set_all_library_permissions( library_item, permissions ) - library_item.refresh() - msg = "Permissions updated for information template '%s'" % library_item.name - return trans.response.send_redirect( web.url_for( controller='library', - action='info_template', - library_id=library_id, - id=id, - permissions=True, - msg=util.sanitize_text( msg ), - messagetype='done' ) ) - return trans.fill_template( '/library/info_template_permissions.mako', - liit=library_item, library_id=library_id, + folder_id=folder_id, + ldda_id=ldda_id, + forms=get_all_forms( trans ), msg=msg, messagetype=messagetype ) @web.expose - def library_item_info( self, trans, library_id, id=None, library_item_id=None, library_item_type=None, **kwd ): + def edit_template_info( self, trans, library_id, num_widgets, library_item_id=None, library_item_type=None, **kwd ): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) @@ -1257,8 +1149,6 @@ library_item = trans.app.model.LibraryDatasetDatasetAssociation.get( library_item_id ) # This response_action method requires a folder_id folder_id = library_item.library_dataset.folder.id - elif library_item_type == 'library_item_info_elememt': - library_item = trans.app.model.LibraryItemInfoElement.get( library_item_id ) else: msg = "Invalid library item type ( %s ) specified, id ( %s )" % ( str( library_item_type ), str( library_item_id ) ) return trans.response.send_redirect( web.url_for( controller='library', @@ -1266,104 +1156,20 @@ id=library_id, msg=util.sanitize_text( msg ), messagetype='error' ) ) - if params.get( 'new_info', False ): - if library_item: - if params.get( 'create_new_info_button', False ): - library_item_info_template_id = params.get( 'library_item_info_template_id', None ) - library_item_info_template = trans.app.model.LibraryItemInfoTemplate.get( int( library_item_info_template_id ) ) - # Make sure at least 1 template field is filled in - # TODO: Eventually we'll enhance templates to allow for required and optional fields. - proceed = False - for template_element in library_item_info_template.elements: - if params.get( "info_element_%s_%s" % ( library_item_info_template.id, template_element.id ), None ): - proceed = True - break - if not proceed: - msg = "At least 1 of the fields must be completed." - return trans.response.send_redirect( web.url_for( controller='admin', - action=library_item_type, - id=library_item.id, - library_id=library_id, - folder_id=folder_id, - edit_info=True, - msg=util.sanitize_text( msg ), - messagetype='error' ) ) - user = trans.get_user() - library_item_info = trans.app.model.LibraryItemInfo( user=user ) - library_item_info.library_item_info_template = library_item_info_template - library_item_info.flush() - trans.app.security_agent.copy_library_permissions( library_item_info_template, library_item_info ) - for template_element in library_item_info_template.elements: - info_element_value = params.get( "info_element_%s_%s" % ( library_item_info_template.id, template_element.id ), None ) - info_element = trans.app.model.LibraryItemInfoElement() - info_element.contents = info_element_value - info_element.library_item_info_template_element = template_element - info_element.library_item_info = library_item_info - info_element.flush() - info_association_class = None - for item_class, permission_class, info_association_class in trans.app.security_agent.library_item_assocs: - if isinstance( library_item, item_class ): - break - if info_association_class: - library_item_info_association = info_association_class( user=user ) - library_item_info_association.set_library_item( library_item ) - library_item_info_association.library_item_info = library_item_info - library_item_info_association.flush() - else: - raise 'Invalid class (%s) specified for library_item (%s)' % ( library_item.__class__, library_item.__class__.__name__ ) - msg = 'The information has been saved.' - return trans.response.send_redirect( web.url_for( controller='library', - action=library_item_type, - id=library_item.id, - library_id=library_id, - folder_id=folder_id, - edit_info=True, - msg=util.sanitize_text( msg ), - messagetype='done' ) ) - return trans.fill_template( "/library/new_info.mako", - library_id=library_id, - library_item=library_item, - library_item_type=library_item_type, - msg=msg, - messagetype=messagetype ) - elif params.get( 'edit_info', False ): - if params.get( 'edit_info_button', False ): - ids = util.listify( id ) - for id in ids: - library_item_info_element = trans.app.model.LibraryItemInfoElement.get( int( id ) ) - new_contents = util.restore_text( params.get( ( 'info_element_%s' % id ), '' ) ) - library_item_info_element.contents = new_contents - library_item_info_element.flush() - msg = 'The information has been updated.' - return trans.response.send_redirect( web.url_for( controller='library', - action=library_item_type, - id=library_item.id, - library_id=library_id, - folder_id=folder_id, - edit_info=True, - msg=util.sanitize_text( msg ), - messagetype='done' ) ) - elif params.get( 'permissions', False ): - if params.get( 'update_roles_button', False ): - permissions = {} - for k, v in trans.app.model.Library.permitted_actions.items(): - in_roles = [ trans.app.model.Role.get( x ) for x in util.listify( kwd.get( k + '_in', [] ) ) ] - permissions[ trans.app.security_agent.get_action( v.action ) ] = in_roles - trans.app.security_agent.set_all_library_permissions( library_item.library_item_info, permissions ) - library_item.library_item_info.refresh() - library_item.refresh() - msg = "Permissions updated for field '%s'" % library_item.library_item_info_template_element.name - return trans.response.send_redirect( web.url_for( controller='library', - action='library_item_info', - library_id=library_id, - id=id, - library_item_id=library_item_id, - library_item_type=library_item_type, - permissions=True, - msg=util.sanitize_text( msg ), - messagetype='done' ) ) - return trans.fill_template( '/library/info_permissions.mako', - library_item_info_element=library_item, - library_id=library_id, - msg=msg, - messagetype=messagetype ) + # Save updated template field contents + field_values = [] + for index in range( int( num_widgets ) ): + field_values.append( util.restore_text( params.get( 'field_%i' % ( index ), '' ) ) ) + info = library_item.info_association[0].info + form_values = trans.app.model.FormValues.get( info.id ) + form_values.content = field_values + form_values.flush() + msg = 'The information has been updated.' + return trans.response.send_redirect( web.url_for( controller='library', + action=library_item_type, + id=library_item.id, + library_id=library_id, + folder_id=folder_id, + edit_info=True, + msg=util.sanitize_text( msg ), + messagetype='done' ) ) diff -r eb09beda047d -r 50ce3d8388f8 lib/galaxy/web/controllers/library_dataset.py --- a/lib/galaxy/web/controllers/library_dataset.py Fri Aug 07 12:55:07 2009 -0400 +++ b/lib/galaxy/web/controllers/library_dataset.py Fri Aug 07 16:11:14 2009 -0400 @@ -12,9 +12,9 @@ os.unlink( filename ) except: log.exception( 'failure removing temporary file: %s' % filename ) - def add_file( self, trans, folder_id, file_obj, name, file_format, dbkey, roles, info='no info', space_to_tab=False, - replace_dataset=None, library_item_info_template=None, template_elements={}, message=None ): - folder = trans.app.model.LibraryFolder.get( folder_id ) + def add_file( self, trans, folder, file_obj, name, file_format, dbkey, roles, + info='no info', space_to_tab=False, replace_dataset=None, + template=None, template_field_contents=[], message=None ): data_type = None line_count = 0 temp_name, is_multi_byte = sniff.stream_to_file( file_obj ) @@ -142,24 +142,17 @@ folder.flush() library_dataset.library_dataset_dataset_association_id = ldda.id library_dataset.flush() - # Handle any templates included in the upload form - if library_item_info_template: - user = trans.get_user() - library_item_info = trans.app.model.LibraryItemInfo( user=user ) - library_item_info.library_item_info_template = library_item_info_template - library_item_info.flush() - trans.app.security_agent.copy_library_permissions( library_item_info_template, library_item_info ) - for template_element in library_item_info_template.elements: - info_element_value = template_elements.get( "info_element_%s_%s" % ( library_item_info_template.id, template_element.id ), None ) - info_element = trans.app.model.LibraryItemInfoElement() - info_element.contents = info_element_value - info_element.library_item_info_template_element = template_element - info_element.library_item_info = library_item_info - info_element.flush() - library_item_info_association = trans.app.model.LibraryDatasetDatasetInfoAssociation( user=user ) - library_item_info_association.set_library_item( ldda ) - library_item_info_association.library_item_info = library_item_info - library_item_info_association.flush() + # Handle template included in the upload form, if any + if template and template_field_contents: + # Since information templates are inherited, the template fields can be displayed on the upload form. + # If the user has added field contents, we'll need to create a new form_values and info_association + # for the new library_dataset_dataset_association object. + # Create a new FormValues object, using the template we previously retrieved + form_values = trans.app.model.FormValues( template, template_field_contents ) + form_values.flush() + # Create a new info_association between the current ldda and form_values + info_association = trans.app.model.LibraryDatasetDatasetInfoAssociation( ldda, template, form_values ) + info_association.flush() # If roles were selected upon upload, restrict access to the Dataset to those roles if roles: for role in roles: @@ -207,22 +200,19 @@ replace_id = None message = params.get( 'message', '' ) upload_option = params.get( 'upload_option', 'upload_file' ) - # Handle any templates included in the upload form by building a dictionary of info elements to send to add_file - template_elements = {} - library_item_info_template = None - library_item_info_template_id = params.get( 'library_item_info_template_id', None ) - if library_item_info_template_id: - library_item_info_template = trans.app.model.LibraryItemInfoTemplate.get( int( library_item_info_template_id ) ) - for template_element in library_item_info_template.elements: - # Make sure at least 1 template field is filled in - # TODO: Eventually we'll enhance templates to allow for required and optional fields. - if params.get( "info_element_%s_%s" % ( library_item_info_template.id, template_element.id ), None ): - for template_element in library_item_info_template.elements: - key = "info_element_%s_%s" % ( library_item_info_template.id, template_element.id ) - value = params.get( key, None ) - if value: - template_elements[ key ] = value err_redirect = False + # See if we have any template field contents + template_field_contents = [] + template = None + folder = trans.app.model.LibraryFolder.get( folder_id ) + info_association = folder.get_info_association() + if info_association: + template = info_association.template + for field_index in range( len( template.fields ) ): + field_name = 'field_%i' % field_index + if params.get( field_name, False ): + field_value = util.restore_text( params.get( field_name, '' ) ) + template_field_contents.append( field_value ) if upload_option == 'upload_file' and data_file == '' and url_paste == '': msg = 'Select a file, enter a URL or enter text' err_redirect = True @@ -263,7 +253,7 @@ file_name = file_name.split( '/' )[-1] try: created_ldda = self.add_file( trans, - folder_id, + folder, data_file.file, file_name, file_format, @@ -272,8 +262,8 @@ info="uploaded file", space_to_tab=space_to_tab, replace_dataset=replace_dataset, - library_item_info_template=library_item_info_template, - template_elements=template_elements, + template=template, + template_field_contents=template_field_contents, message=message ) created_ldda_ids = str( created_ldda.id ) except Exception, e: @@ -291,7 +281,7 @@ name_set_from_line = True try: created_ldda = self.add_file( trans, - folder_id, + folder, urllib.urlopen( line ), line, file_format, @@ -300,8 +290,8 @@ info="uploaded url", space_to_tab=space_to_tab, replace_dataset=replace_dataset, - library_item_info_template=library_item_info_template, - template_elements=template_elements, + template=template, + template_field_contents=template_field_contents, message=message ) created_ldda_ids = '%s,%s' % ( created_ldda_ids, str( created_ldda.id ) ) except Exception, e: @@ -317,7 +307,7 @@
participants (1)
-
Greg Von Kuster