Skip to content

Commit

Permalink
Managers, history: replace _get_history_data with proper serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
carlfeberhard committed Jul 30, 2015
1 parent ed29f74 commit bb4588a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 32 deletions.
17 changes: 12 additions & 5 deletions lib/galaxy/managers/histories.py
Expand Up @@ -321,14 +321,21 @@ def serialize_history_state( self, history, key, **context ):

return state

def serialize_contents( self, history, *args, **context ):
def serialize_contents( self, history, key, trans=None, **context ):
contents_dictionaries = []
for content in history.contents_iter( types=[ 'dataset', 'dataset_collection' ] ):
contents_dict = {}

if isinstance( content, model.HistoryDatasetAssociation ):
contents_dict = self.hda_serializer.serialize_to_view( content, view='detailed', **context )
# elif isinstance( content, model.HistoryDatasetCollectionAssociation ):
# contents_dict = self._serialize_collection( trans, content )
contents_dict = self.hda_serializer.serialize_to_view( content,
view='detailed', trans=trans, **context )
# TODO: work out: shouldn't history annotations *always* use user=history.user? why anything else?
hda_annotation = self.hda_serializer.serialize_annotation( content, 'annotation', user=history.user )
contents_dict[ 'annotation' ] = hda_annotation

elif isinstance( content, model.HistoryDatasetCollectionAssociation ):
contents_dict = self._serialize_collection( trans, content )

contents_dictionaries.append( contents_dict )
return contents_dictionaries

Expand All @@ -341,7 +348,7 @@ def _serialize_collection( self, trans, collection ):
id=self.app.security.encode_id( collection.id ),
)
return collections_util.dictify_dataset_collection_instance( dataset_collection_instance,
security=self.app.security, parent=dataset_collection_instance.history, view="element" )
security=self.app.security, parent=dataset_collection_instance.history, view="element" )


class HistoryDeserializer( sharable.SharableModelDeserializer, deletable.PurgableDeserializerMixin ):
Expand Down
37 changes: 20 additions & 17 deletions lib/galaxy/webapps/galaxy/controllers/history.py
Expand Up @@ -564,9 +564,10 @@ def structure( self, trans, id=None, **kwargs ):
unencoded_history_id = self.decode_id( id )
history_to_view = self.history_manager.get_accessible( unencoded_history_id, trans.user, current_history=trans.history )

history_data = self.history_manager._get_history_data( trans, history_to_view )
history_dictionary = history_data[ 'history' ]
hda_dictionaries = history_data[ 'contents' ]
history_dictionary = self.history_serializer.serialize_to_view( history_to_view,
view='detailed', user=trans.user, trans=trans )
contents = self.history_serializer.serialize_contents( history_to_view,
'contents', trans=trans, user=trans.user )

jobs = ( trans.sa_session.query( trans.app.model.Job )
.filter( trans.app.model.Job.user == history_to_view.user )
Expand All @@ -583,7 +584,7 @@ def structure( self, trans, id=None, **kwargs ):
tools[ tool_id ] = tool.to_dict( trans, io_details=True, link_details=True )

return trans.fill_template( "history/structure.mako", historyId=history_dictionary[ 'id' ],
history=history_dictionary, hdas=hda_dictionaries, jobs=jobs, tools=tools, **kwargs )
history=history_dictionary, hdas=contents, jobs=jobs, tools=tools, **kwargs )

@web.expose
def view( self, trans, id=None, show_deleted=False, show_hidden=False, use_panels=True ):
Expand All @@ -599,16 +600,18 @@ def view( self, trans, id=None, show_deleted=False, show_hidden=False, use_panel
use_panels = galaxy.util.string_as_bool( use_panels )

history_dictionary = {}
hda_dictionaries = []
contents = []
user_is_owner = False
try:
history_to_view = self.history_manager.get_accessible( self.decode_id( id ), trans.user, current_history=trans.history )
history_to_view = self.history_manager.get_accessible( self.decode_id( id ), trans.user,
current_history=trans.history )
user_is_owner = history_to_view.user == trans.user

# include all datasets: hidden, deleted, and purged
history_data = self.history_manager._get_history_data( trans, history_to_view )
history_dictionary = history_data[ 'history' ]
hda_dictionaries = history_data[ 'contents' ]
history_dictionary = self.history_serializer.serialize_to_view( history_to_view,
view='detailed', user=trans.user, trans=trans )
contents = self.history_serializer.serialize_contents( history_to_view,
'contents', trans=trans, user=trans.user )

except Exception, exc:
user_id = str( trans.user.id ) if trans.user else '(anonymous)'
Expand All @@ -621,8 +624,8 @@ def view( self, trans, id=None, show_deleted=False, show_hidden=False, use_panel
return trans.show_error_message( error_msg, use_panels=use_panels )

return trans.fill_template_mako( "history/view.mako",
history=history_dictionary, hdas=hda_dictionaries, user_is_owner=user_is_owner,
show_deleted=show_deleted, show_hidden=show_hidden, use_panels=use_panels )
history=history_dictionary, hdas=contents, user_is_owner=user_is_owner,
show_deleted=show_deleted, show_hidden=show_hidden, use_panels=use_panels )

@web.expose
def view_multiple( self, trans, include_deleted_histories=False, order='update' ):
Expand Down Expand Up @@ -683,19 +686,19 @@ def display_by_username_and_slug( self, trans, username, slug ):

# create ownership flag for template, dictify models
user_is_owner = trans.user == history.user
history_data = self.history_manager._get_history_data( trans, history )
history_dict = history_data[ 'history' ]
hda_dicts = history_data[ 'contents' ]
history_dictionary = self.history_serializer.serialize_to_view( history,
view='detailed', user=trans.user, trans=trans )
contents = self.history_serializer.serialize_contents( history, 'contents', trans=trans, user=trans.user )

history_dict[ 'annotation' ] = self.get_item_annotation_str( trans.sa_session, history.user, history )
history_dictionary[ 'annotation' ] = self.get_item_annotation_str( trans.sa_session, history.user, history )
# note: adding original annotation since this is published - get_dict returns user-based annos
# for hda_dict in hda_dicts:
# hda_dict[ 'annotation' ] = hda.annotation
# dataset.annotation = self.get_item_annotation_str( trans.sa_session, history.user, dataset )

return trans.stream_template_mako( "history/display.mako", item=history, item_data=[],
user_is_owner=user_is_owner, history_dict=history_dict, hda_dicts=hda_dicts,
user_item_rating=user_item_rating, ave_item_rating=ave_item_rating, num_ratings=num_ratings )
user_is_owner=user_is_owner, history_dict=history_dictionary, hda_dicts=contents,
user_item_rating=user_item_rating, ave_item_rating=ave_item_rating, num_ratings=num_ratings )

# ......................................................................... sharing & publishing
@web.expose
Expand Down
16 changes: 9 additions & 7 deletions lib/galaxy/webapps/galaxy/controllers/page.py
Expand Up @@ -302,6 +302,7 @@ class PageController( BaseUIController, SharableMixin,
def __init__( self, app ):
super( PageController, self ).__init__( app )
self.history_manager = managers.histories.HistoryManager( app )
self.history_serializer = managers.histories.HistorySerializer( self.app )
self.hda_manager = managers.hdas.HDAManager( app )

@web.expose
Expand Down Expand Up @@ -755,15 +756,16 @@ def _get_embedded_history_html( self, trans, id ):
history.annotation = self.get_item_annotation_str( trans.sa_session, history.user, history )

# include all datasets: hidden, deleted, and purged
history_data = self.history_manager._get_history_data( trans, history )
history_dictionary = history_data[ 'history' ]
hda_dictionaries = history_data[ 'contents' ]
history_dictionary = self.history_serializer.serialize_to_view( history,
view='detailed', user=trans.user, trans=trans )
contents = self.history_serializer.serialize_contents( history, 'contents', trans=trans, user=trans.user )
history_dictionary[ 'annotation' ] = history.annotation

filled = trans.fill_template( "history/embed.mako", item=history,
user_is_owner=user_is_owner,
history_dict=history_dictionary,
hda_dicts=hda_dictionaries )
filled = trans.fill_template( "history/embed.mako",
item=history,
user_is_owner=user_is_owner,
history_dict=history_dictionary,
hda_dicts=contents )
return filled

def _get_embedded_visualization_html( self, trans, id ):
Expand Down
9 changes: 6 additions & 3 deletions lib/galaxy/webapps/galaxy/controllers/root.py
Expand Up @@ -26,6 +26,7 @@ class RootController( BaseUIController, UsesAnnotations ):
def __init__( self, app ):
super( RootController, self ).__init__( app )
self.history_manager = managers.histories.HistoryManager( app )
self.history_serializer = managers.histories.HistorySerializer( self.app )

@web.expose
def default(self, trans, target1=None, target2=None, **kwd):
Expand Down Expand Up @@ -124,9 +125,11 @@ def history( self, trans, as_xml=False, show_deleted=None, show_hidden=None, **k
history_dictionary = {}
hda_dictionaries = []
try:
history_data = self.history_manager._get_history_data( trans, trans.get_history( create=True ) )
history_dictionary = history_data[ 'history' ]
hda_dictionaries = history_data[ 'contents' ]
history = trans.get_history( create=True )
history_dictionary = self.history_serializer.serialize_to_view( history,
view='detailed', user=trans.user, trans=trans )
hda_dictionaries = self.history_serializer.serialize_contents( history,
'contents', trans=trans, user=trans.user )

except Exception, exc:
user_id = str( trans.user.id ) if trans.user else '(anonymous)'
Expand Down

0 comments on commit bb4588a

Please sign in to comment.