1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/2a4f4be3c377/ Changeset: 2a4f4be3c377 User: jmchilton Date: 2013-09-19 21:46:45 Summary: Allow user field (__user_email__, __user_name__, etc..) in hidden fields as outlined in PR 206, but do so in a way that centralizes some related logic (i.e. logic used by Cheetah in job templates and used by dynamic filter options). Affected #: 4 files diff -r 64f283100f960c1ae7645fae17394334b1b7f349 -r 2a4f4be3c377de638ee280b7a3ae83c62af6038a lib/galaxy/jobs/__init__.py --- a/lib/galaxy/jobs/__init__.py +++ b/lib/galaxy/jobs/__init__.py @@ -680,20 +680,8 @@ out_data[ "output_file" ] = FakeDatasetAssociation( dataset=special.dataset ) # These can be passed on the command line if wanted as $__user_*__ - if job.history and job.history.user: - user = job.history.user - user_id = '%d' % job.history.user.id - user_email = str(job.history.user.email) - user_name = str(job.history.user.username) - else: - user = None - user_id = 'Anonymous' - user_email = 'Anonymous' - user_name = 'Anonymous' - incoming['__user__'] = user - incoming['__user_id__'] = incoming['userId'] = user_id - incoming['__user_email__'] = incoming['userEmail'] = user_email - incoming['__user_name__'] = user_name + incoming.update( model.User.user_template_environment( job.history and job.history.user ) ) + # Build params, done before hook so hook can use param_dict = self.tool.build_param_dict( incoming, inp_data, out_data, diff -r 64f283100f960c1ae7645fae17394334b1b7f349 -r 2a4f4be3c377de638ee280b7a3ae83c62af6038a lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -18,6 +18,7 @@ import simplejson import socket import time +from string import Template import galaxy.datatypes import galaxy.datatypes.registry @@ -159,6 +160,47 @@ total += hda.dataset.get_total_size() return total + @staticmethod + def user_template_environment( user ): + """ + + >>> env = User.user_template_environment(None) + >>> env['__user_email__'] + 'Anonymous' + >>> env['__user_id__'] + 'Anonymous' + >>> user = User('foo@example.com') + >>> user.id = 6 + >>> user.username = 'foo2' + >>> env = User.user_template_environment(user) + >>> env['__user_id__'] + '6' + >>> env['__user_name__'] + 'foo2' + """ + if user: + user_id = '%d' % user.id + user_email = str( user.email ) + user_name = str( user.username ) + else: + user = None + user_id = 'Anonymous' + user_email = 'Anonymous' + user_name = 'Anonymous' + environment = {} + environment[ '__user__' ] = user + environment[ '__user_id__' ] = environment[ 'userId' ] = user_id + environment[ '__user_email__' ] = environment[ 'userEmail' ] = user_email + environment[ '__user_name__' ] = user_name + return environment + + @staticmethod + def expand_user_properties( user, in_string ): + """ + """ + environment = User.user_template_environment( user ) + return Template( in_string ).safe_substitute( environment ) + class Job( object, Dictifiable ): dict_collection_visible_keys = [ 'id' ] diff -r 64f283100f960c1ae7645fae17394334b1b7f349 -r 2a4f4be3c377de638ee280b7a3ae83c62af6038a lib/galaxy/tools/__init__.py --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -2291,7 +2291,7 @@ args = dict() for key, param in self.inputs.iteritems(): if isinstance( param, HiddenToolParameter ): - args[key] = param.value + args[key] = model.User.expand_user_properties( trans.user, param.value ) elif isinstance( param, BaseURLToolParameter ): args[key] = param.get_value( trans ) else: diff -r 64f283100f960c1ae7645fae17394334b1b7f349 -r 2a4f4be3c377de638ee280b7a3ae83c62af6038a lib/galaxy/tools/parameters/dynamic_options.py --- a/lib/galaxy/tools/parameters/dynamic_options.py +++ b/lib/galaxy/tools/parameters/dynamic_options.py @@ -6,6 +6,7 @@ import operator, sys, os, logging import basic, validation from galaxy.util import string_as_bool +from galaxy.model import User import galaxy.tools log = logging.getLogger(__name__) @@ -55,8 +56,7 @@ rval = [] filter_value = self.value try: - if trans.user.email: - filter_value = filter_value.replace('$__user_email__',trans.user.email) + filter_value = User.expand_user_properties( trans.user, filter_value) except: pass for fields in options: 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.