[hg] galaxy 2515: Add new flag, allow_datatype_change, to Dataty...
details: http://www.bx.psu.edu/hg/galaxy/rev/aabcc797c1da changeset: 2515:aabcc797c1da user: Dan Blankenberg <dan@bx.psu.edu> date: Thu Jul 30 16:23:47 2009 -0400 description: Add new flag, allow_datatype_change, to Datatypes. When set to False, datasets of this datatype cannot be changed from or into. This is needed, i.e. for Rgenetics Datatypes to prevent loss of metadata ('base_name') which occurs when changing to datatypes without this metadata parameter and would render the dataset unusable (composite filenames could be incorrect). 8 file(s) affected in this change: lib/galaxy/datatypes/data.py lib/galaxy/datatypes/genetics.py lib/galaxy/web/controllers/admin.py lib/galaxy/web/controllers/library.py lib/galaxy/web/controllers/root.py templates/admin/library/ldda_edit_info.mako templates/dataset/edit_attributes.mako templates/library/ldda_edit_info.mako diffs (287 lines): diff -r 904a72f5cf4c -r aabcc797c1da lib/galaxy/datatypes/data.py --- a/lib/galaxy/datatypes/data.py Thu Jul 30 15:03:53 2009 -0400 +++ b/lib/galaxy/datatypes/data.py Thu Jul 30 16:23:47 2009 -0400 @@ -51,6 +51,8 @@ copy_safe_peek = True is_binary = True #The dataset contains binary data --> do not space_to_tab or convert newlines, etc. Allow binary file uploads of this type when True. + + allow_datatype_change = True #Allow user to change between this datatype and others. If False, this datatype cannot be changed from or into. #Composite datatypes composite_type = None diff -r 904a72f5cf4c -r aabcc797c1da lib/galaxy/datatypes/genetics.py --- a/lib/galaxy/datatypes/genetics.py Thu Jul 30 15:03:53 2009 -0400 +++ b/lib/galaxy/datatypes/genetics.py Thu Jul 30 16:23:47 2009 -0400 @@ -122,6 +122,7 @@ file_ext="html" composite_type = 'auto_primary_file' + allow_datatype_change = False def missing_meta( self, dataset ): """Checks for empty meta values""" @@ -255,6 +256,8 @@ file_ext = None is_binary = True + + allow_datatype_change = False composite_type = 'basic' diff -r 904a72f5cf4c -r aabcc797c1da lib/galaxy/web/controllers/admin.py --- a/lib/galaxy/web/controllers/admin.py Thu Jul 30 15:03:53 2009 -0400 +++ b/lib/galaxy/web/controllers/admin.py Thu Jul 30 16:23:47 2009 -0400 @@ -1094,7 +1094,7 @@ replace_dataset = None # Let's not overwrite the imported datatypes module with the variable datatypes? # The built-in 'id' is overwritten in lots of places as well - ldatatypes = [ x for x in trans.app.datatypes_registry.datatypes_by_extension.iterkeys() ] + ldatatypes = [ dtype_name for dtype_name, dtype_value in trans.app.datatypes_registry.datatypes_by_extension.iteritems() if dtype_value.allow_datatype_change ] ldatatypes.sort() if params.get( 'new_dataset_button', False ): upload_option = params.get( 'upload_option', 'upload_file' ) @@ -1247,17 +1247,20 @@ elif action == 'edit_info': if params.get( 'change', False ): # The user clicked the Save button on the 'Change data type' form - trans.app.datatypes_registry.change_datatype( ldda, params.datatype ) - trans.app.model.flush() - msg = "Data type changed for library dataset '%s'" % ldda.name - return trans.fill_template( "/admin/library/ldda_edit_info.mako", - ldda=ldda, - library_id=library_id, - datatypes=ldatatypes, - restrict=params.get( 'restrict', True ), - render_templates=params.get( 'render_templates', False ), - msg=msg, - messagetype=messagetype ) + if ldda.datatype.allow_datatype_change and trans.app.datatypes_registry.get_datatype_by_extension( params.datatype ).allow_datatype_change: + trans.app.datatypes_registry.change_datatype( ldda, params.datatype ) + trans.app.model.flush() + msg = "Data type changed for library dataset '%s'" % ldda.name + return trans.fill_template( "/admin/library/ldda_edit_info.mako", + ldda=ldda, + library_id=library_id, + datatypes=ldatatypes, + restrict=params.get( 'restrict', True ), + render_templates=params.get( 'render_templates', False ), + msg=msg, + messagetype=messagetype ) + else: + return trans.show_error_message( "You are unable to change datatypes in this manner. Changing %s to %s is not allowed." % ( ldda.extension, params.datatype ) ) elif params.get( 'save', False ): # The user clicked the Save button on the 'Edit Attributes' form old_name = ldda.name diff -r 904a72f5cf4c -r aabcc797c1da lib/galaxy/web/controllers/library.py --- a/lib/galaxy/web/controllers/library.py Thu Jul 30 15:03:53 2009 -0400 +++ b/lib/galaxy/web/controllers/library.py Thu Jul 30 16:23:47 2009 -0400 @@ -430,7 +430,7 @@ replace_dataset = None # Let's not overwrite the imported datatypes module with the variable datatypes? # The built-in 'id' is overwritten in lots of places as well - ldatatypes = [ x for x in trans.app.datatypes_registry.datatypes_by_extension.iterkeys() ] + ldatatypes = [ dtype_name for dtype_name, dtype_value in trans.app.datatypes_registry.datatypes_by_extension.iteritems() if dtype_value.allow_datatype_change ] ldatatypes.sort() if id: if params.get( 'permissions', False ): @@ -505,10 +505,14 @@ if trans.app.security_agent.allow_action( trans.user, trans.app.security_agent.permitted_actions.LIBRARY_MODIFY, library_item=ldda ): - trans.app.datatypes_registry.change_datatype( ldda, params.datatype ) - trans.app.model.flush() - msg = "Data type changed for library dataset '%s'" % ldda.name - messagetype = 'done' + if ldda.datatype.allow_datatype_change and trans.app.datatypes_registry.get_datatype_by_extension( params.datatype ).allow_datatype_change: + trans.app.datatypes_registry.change_datatype( ldda, params.datatype ) + trans.app.model.flush() + msg = "Data type changed for library dataset '%s'" % ldda.name + messagetype = 'done' + else: + msg = "You are unable to change datatypes in this manner. Changing %s to %s is not allowed." % ( ldda.extension, params.datatype ) + messagetype = 'error' else: msg = "You are not authorized to change the data type of dataset '%s'" % ldda.name messagetype = 'error' diff -r 904a72f5cf4c -r aabcc797c1da lib/galaxy/web/controllers/root.py --- a/lib/galaxy/web/controllers/root.py Thu Jul 30 15:03:53 2009 -0400 +++ b/lib/galaxy/web/controllers/root.py Thu Jul 30 16:23:47 2009 -0400 @@ -247,8 +247,11 @@ params = util.Params( kwd, safe=False ) if params.change: # The user clicked the Save button on the 'Change data type' form - trans.app.datatypes_registry.change_datatype( data, params.datatype ) - trans.app.model.flush() + if data.datatype.allow_datatype_change and trans.app.datatypes_registry.get_datatype_by_extension( params.datatype ).allow_datatype_change: + trans.app.datatypes_registry.change_datatype( data, params.datatype ) + trans.app.model.flush() + else: + return trans.show_error_message( "You are unable to change datatypes in this manner. Changing %s to %s is not allowed." % ( data.extension, params.datatype ) ) elif params.save: # The user clicked the Save button on the 'Edit Attributes' form data.name = params.name @@ -314,7 +317,7 @@ data.metadata.dbkey = data.dbkey # let's not overwrite the imported datatypes module with the variable datatypes? # the built-in 'id' is overwritten in lots of places as well - ldatatypes = [x for x in trans.app.datatypes_registry.datatypes_by_extension.iterkeys()] + ldatatypes = [ dtype_name for dtype_name, dtype_value in trans.app.datatypes_registry.datatypes_by_extension.iteritems() if dtype_value.allow_datatype_change ] ldatatypes.sort() trans.log_event( "Opened edit view on dataset %s" % str(id) ) return trans.fill_template( "/dataset/edit_attributes.mako", data=data, datatypes=ldatatypes ) diff -r 904a72f5cf4c -r aabcc797c1da templates/admin/library/ldda_edit_info.mako --- a/templates/admin/library/ldda_edit_info.mako Thu Jul 30 15:03:53 2009 -0400 +++ b/templates/admin/library/ldda_edit_info.mako Thu Jul 30 16:23:47 2009 -0400 @@ -99,24 +99,30 @@ <div class="toolForm"> <div class="toolFormTitle">Change data type of ${ldda.name}</div> <div class="toolFormBody"> - <form name="change_datatype" action="${h.url_for( controller='admin', action='library_dataset_dataset_association', library_id=library_id, folder_id=ldda.library_dataset.folder.id, edit_info=True )}" method="post"> - <input type="hidden" name="id" value="${ldda.id}"/> + %if ldda.datatype.allow_datatype_change: + <form name="change_datatype" action="${h.url_for( controller='admin', action='library_dataset_dataset_association', library_id=library_id, folder_id=ldda.library_dataset.folder.id, edit_info=True )}" method="post"> + <input type="hidden" name="id" value="${ldda.id}"/> + <div class="form-row"> + <label>New Type:</label> + <div style="float: left; width: 250px; margin-right: 10px;"> + ${datatype( ldda, datatypes )} + </div> + <div class="toolParamHelp" style="clear: both;"> + This will change the datatype of the existing dataset + but <i>not</i> modify its contents. Use this if Galaxy + has incorrectly guessed the type of your dataset. + </div> + <div style="clear: both"></div> + </div> + <div class="form-row"> + <input type="submit" name="change" value="Save"/> + </div> + </form> + %else: <div class="form-row"> - <label>New Type:</label> - <div style="float: left; width: 250px; margin-right: 10px;"> - ${datatype( ldda, datatypes )} - </div> - <div class="toolParamHelp" style="clear: both;"> - This will change the datatype of the existing dataset - but <i>not</i> modify its contents. Use this if Galaxy - has incorrectly guessed the type of your dataset. - </div> - <div style="clear: both"></div> + <div class="warningmessagesmall">${_('Changing the datatype of this dataset is not allowed.')}</div> </div> - <div class="form-row"> - <input type="submit" name="change" value="Save"/> - </div> - </form> + %endif </div> </div> diff -r 904a72f5cf4c -r aabcc797c1da templates/dataset/edit_attributes.mako --- a/templates/dataset/edit_attributes.mako Thu Jul 30 15:03:53 2009 -0400 +++ b/templates/dataset/edit_attributes.mako Thu Jul 30 16:23:47 2009 -0400 @@ -102,27 +102,34 @@ </div> <p /> %endif + <div class="toolForm"> <div class="toolFormTitle">${_('Change data type')}</div> <div class="toolFormBody"> - <form name="change_datatype" action="${h.url_for( controller='root', action='edit' )}" method="post"> - <input type="hidden" name="id" value="${data.id}"/> + %if data.datatype.allow_datatype_change: + <form name="change_datatype" action="${h.url_for( controller='root', action='edit' )}" method="post"> + <input type="hidden" name="id" value="${data.id}"/> + <div class="form-row"> + <label> + ${_('New Type')}: + </label> + <div style="float: left; width: 250px; margin-right: 10px;"> + ${datatype( data, datatypes )} + </div> + <div class="toolParamHelp" style="clear: both;"> + ${_('This will change the datatype of the existing dataset but <i>not</i> modify its contents. Use this if Galaxy has incorrectly guessed the type of your dataset.')} + </div> + <div style="clear: both"></div> + </div> + <div class="form-row"> + <input type="submit" name="change" value="${_('Save')}"/> + </div> + </form> + %else: <div class="form-row"> - <label> - ${_('New Type')}: - </label> - <div style="float: left; width: 250px; margin-right: 10px;"> - ${datatype( data, datatypes )} - </div> - <div class="toolParamHelp" style="clear: both;"> - ${_('This will change the datatype of the existing dataset but <i>not</i> modify its contents. Use this if Galaxy has incorrectly guessed the type of your dataset.')} - </div> - <div style="clear: both"></div> + <div class="warningmessagesmall">${_('Changing the datatype of this dataset is not allowed.')}</div> </div> - <div class="form-row"> - <input type="submit" name="change" value="${_('Save')}"/> - </div> - </form> + %endif </div> </div> <p /> diff -r 904a72f5cf4c -r aabcc797c1da templates/library/ldda_edit_info.mako --- a/templates/library/ldda_edit_info.mako Thu Jul 30 15:03:53 2009 -0400 +++ b/templates/library/ldda_edit_info.mako Thu Jul 30 16:23:47 2009 -0400 @@ -99,24 +99,30 @@ <div class="toolForm"> <div class="toolFormTitle">Change data type</div> <div class="toolFormBody"> - <form name="change_datatype" action="${h.url_for( controller='library', action='library_dataset_dataset_association', library_id=library_id, folder_id=ldda.library_dataset.folder.id, edit_info=True )}" method="post"> - <input type="hidden" name="id" value="${ldda.id}"/> + %if ldda.datatype.allow_datatype_change: + <form name="change_datatype" action="${h.url_for( controller='library', action='library_dataset_dataset_association', library_id=library_id, folder_id=ldda.library_dataset.folder.id, edit_info=True )}" method="post"> + <input type="hidden" name="id" value="${ldda.id}"/> + <div class="form-row"> + <label>New Type:</label> + <div style="float: left; width: 250px; margin-right: 10px;"> + ${datatype( ldda, datatypes )} + </div> + <div class="toolParamHelp" style="clear: both;"> + This will change the datatype of the existing dataset + but <i>not</i> modify its contents. Use this if Galaxy + has incorrectly guessed the type of your dataset. + </div> + <div style="clear: both"></div> + </div> + <div class="form-row"> + <input type="submit" name="change" value="Save"/> + </div> + </form> + %else: <div class="form-row"> - <label>New Type:</label> - <div style="float: left; width: 250px; margin-right: 10px;"> - ${datatype( ldda, datatypes )} - </div> - <div class="toolParamHelp" style="clear: both;"> - This will change the datatype of the existing dataset - but <i>not</i> modify its contents. Use this if Galaxy - has incorrectly guessed the type of your dataset. - </div> - <div style="clear: both"></div> + <div class="warningmessagesmall">${_('Changing the datatype of this dataset is not allowed.')}</div> </div> - <div class="form-row"> - <input type="submit" name="change" value="Save"/> - </div> - </form> + %endif </div> </div> <p/>
participants (1)
-
Greg Von Kuster