commit/galaxy-central: carlfeberhard: Tags: user: cache a list of tags used in Galaxy.currUser and add to users.show; Histories, HDAs: allow setting and getting of tags (in bulk) via update
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/26ada521210e/ Changeset: 26ada521210e User: carlfeberhard Date: 2013-11-01 20:16:50 Summary: Tags: user: cache a list of tags used in Galaxy.currUser and add to users.show; Histories, HDAs: allow setting and getting of tags (in bulk) via update Affected #: 6 files diff -r ef83037950ea0e867271999e2cc1902bd9f65302 -r 26ada521210ef52684dda3e394521bcfba23b5da lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -1751,6 +1751,14 @@ misc_info = hda.info, misc_blurb = hda.blurb ) + tags_str_list = [] + for tag in self.tags: + tag_str = tag.user_tname + if tag.value is not None: + tag_str += ":" + tag.user_value + tags_str_list.append( tag_str ) + rval[ 'tags' ] = tags_str_list + if hda.copied_from_library_dataset_dataset_association is not None: rval['copied_from_ldda_id'] = hda.copied_from_library_dataset_dataset_association.id diff -r ef83037950ea0e867271999e2cc1902bd9f65302 -r 26ada521210ef52684dda3e394521bcfba23b5da lib/galaxy/web/base/controller.py --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -452,7 +452,8 @@ if 'annotation' in new_data.keys() and trans.get_user(): history.add_item_annotation( trans.sa_session, trans.get_user(), history, new_data[ 'annotation' ] ) changed[ 'annotation' ] = new_data[ 'annotation' ] - # tags + if 'tags' in new_data.keys() and trans.get_user(): + self.set_tags_from_list( trans, history, new_data[ 'tags' ], user=trans.user ) # importable (ctrl.history.set_accessible_async) # sharing/permissions? # slugs? @@ -715,7 +716,8 @@ if 'annotation' in new_data.keys() and trans.get_user(): hda.add_item_annotation( trans.sa_session, trans.get_user(), hda, new_data[ 'annotation' ] ) changed[ 'annotation' ] = new_data[ 'annotation' ] - # tags + if 'tags' in new_data.keys() and trans.get_user(): + self.set_tags_from_list( trans, hda, new_data[ 'tags' ], user=trans.user ) # sharing/permissions? # purged @@ -2340,6 +2342,49 @@ log.debug( "In get_item_tag_assoc with tagged_item %s" % tagged_item ) return self.get_tag_handler( trans )._get_item_tag_assoc( user, tagged_item, tag_name ) + def set_tags_from_list( self, trans, item, new_tags_list, user=None ): + #precondition: item is already security checked against user + #precondition: incoming tags is a list of sanitized/formatted strings + user = user or trans.user + + # based on controllers/tag retag_async: delete all old, reset to entire new + trans.app.tag_handler.delete_item_tags( trans, user, item ) + new_tags_str = ','.join( new_tags_list ) + trans.app.tag_handler.apply_item_tags( trans, user, item, new_tags_str.encode( 'utf-8' ) ) + trans.sa_session.flush() + return item.tags + + def get_user_tags_used( self, trans, user=None ): + """ + Return a list of distinct 'user_tname:user_value' strings that the + given user has used. + + user defaults to trans.user. + Returns an empty list if no user is given and trans.user is anonymous. + """ + #TODO: for lack of a UsesUserMixin - placing this here - maybe into UsesTags, tho + user = user or trans.user + if not user: + return [] + + # get all the taggable model TagAssociations + tag_models = [ v.tag_assoc_class for v in trans.app.tag_handler.item_tag_assoc_info.values() ] + # create a union of subqueries for each for this user - getting only the tname and user_value + all_tags_query = None + for tag_model in tag_models: + subq = ( trans.sa_session.query( tag_model.user_tname, tag_model.user_value ) + .filter( tag_model.user == trans.user ) ) + all_tags_query = subq if all_tags_query is None else all_tags_query.union( subq ) + + # if nothing init'd the query, bail + if all_tags_query is None: + return [] + + # boil the tag tuples down into a sorted list of DISTINCT name:val strings + tags = all_tags_query.distinct().all() + tags = [( ( name + ':' + val ) if val else name ) for name, val in tags ] + return sorted( tags ) + class UsesExtendedMetadataMixin( SharableItemSecurityMixin ): diff -r ef83037950ea0e867271999e2cc1902bd9f65302 -r 26ada521210ef52684dda3e394521bcfba23b5da lib/galaxy/webapps/galaxy/api/histories.py --- a/lib/galaxy/webapps/galaxy/api/histories.py +++ b/lib/galaxy/webapps/galaxy/api/histories.py @@ -11,14 +11,14 @@ from galaxy import web from galaxy.util import string_as_bool, restore_text from galaxy.util.sanitize_html import sanitize_html -from galaxy.web.base.controller import BaseAPIController, UsesHistoryMixin +from galaxy.web.base.controller import BaseAPIController, UsesHistoryMixin, UsesTagsMixin from galaxy.web import url_for from galaxy.model.orm import desc import logging log = logging.getLogger( __name__ ) -class HistoriesController( BaseAPIController, UsesHistoryMixin ): +class HistoriesController( BaseAPIController, UsesHistoryMixin, UsesTagsMixin ): @web.expose_api_anonymous def index( self, trans, deleted='False', **kwd ): @@ -369,6 +369,9 @@ if not ( isinstance( val, str ) or isinstance( val, unicode ) ): raise ValueError( 'annotation must be a string or unicode: %s' %( str( type( val ) ) ) ) validated_payload[ 'annotation' ] = sanitize_html( val, 'utf-8' ) + elif key == 'tags': + if isinstance( val, list ): + validated_payload[ 'tags' ] = [ sanitize_html( t, 'utf-8' ) for t in val ] elif key not in valid_but_uneditable_keys: pass #log.warn( 'unknown key: %s', str( key ) ) diff -r ef83037950ea0e867271999e2cc1902bd9f65302 -r 26ada521210ef52684dda3e394521bcfba23b5da lib/galaxy/webapps/galaxy/api/history_contents.py --- a/lib/galaxy/webapps/galaxy/api/history_contents.py +++ b/lib/galaxy/webapps/galaxy/api/history_contents.py @@ -4,9 +4,10 @@ import logging from galaxy import exceptions, util, web -from galaxy.web.base.controller import (BaseAPIController, url_for, +from galaxy.web.base.controller import ( BaseAPIController, url_for, UsesHistoryDatasetAssociationMixin, UsesHistoryMixin, UsesLibraryMixin, - UsesLibraryMixinItems) + UsesLibraryMixinItems, UsesTagsMixin ) +from galaxy.util.sanitize_html import sanitize_html log = logging.getLogger( __name__ ) @@ -413,6 +414,9 @@ if not ( isinstance( val, str ) or isinstance( val, unicode ) ): raise ValueError( 'misc_info must be a string or unicode: %s' %( str( type( val ) ) ) ) validated_payload[ 'info' ] = util.sanitize_html.sanitize_html( val, 'utf-8' ) + elif key == 'tags': + if isinstance( val, list ): + validated_payload[ 'tags' ] = [ sanitize_html( t, 'utf-8' ) for t in val ] elif key not in valid_but_uneditable_keys: pass #log.warn( 'unknown key: %s', str( key ) ) diff -r ef83037950ea0e867271999e2cc1902bd9f65302 -r 26ada521210ef52684dda3e394521bcfba23b5da lib/galaxy/webapps/galaxy/api/users.py --- a/lib/galaxy/webapps/galaxy/api/users.py +++ b/lib/galaxy/webapps/galaxy/api/users.py @@ -71,6 +71,7 @@ raise HTTPBadRequest( detail='Invalid user id ( %s ) specified' % id ) item = user.to_dict( view='element', value_mapper={ 'id': trans.security.encode_id, 'total_disk_usage': float } ) + item[ 'tags_used' ] = self.get_user_tags_used( trans, user=user ) #TODO: move into api_values (needs trans, tho - can we do that with api_keys/@property??) #TODO: works with other users (from admin)?? item['quota_percent'] = trans.app.quota_agent.get_percent( trans=trans ) diff -r ef83037950ea0e867271999e2cc1902bd9f65302 -r 26ada521210ef52684dda3e394521bcfba23b5da templates/webapps/galaxy/base_panels.mako --- a/templates/webapps/galaxy/base_panels.mako +++ b/templates/webapps/galaxy/base_panels.mako @@ -18,7 +18,9 @@ if trans.user: user_dict = trans.user.to_dict( view='element', value_mapper={ 'id': trans.security.encode_id, 'total_disk_usage': float } ) + ##TODO: move these into to_dict user_dict['quota_percent'] = trans.app.quota_agent.get_percent( trans=trans ) + user_dict['tags_used'] = trans.webapp.controllers[ 'tag' ].get_user_tags_used( trans ) else: usage = 0 percent = None @@ -33,6 +35,7 @@ 'nice_total_disk_usage' : util.nice_size( usage ), 'quota_percent' : percent } + %> ${h.to_json_string( user_dict )} </%def> Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org