commit/galaxy-central: carlfeberhard: Client App: factor out config serializer, move defensive programming
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/6f698dec5895/ Changeset: 6f698dec5895 User: carlfeberhard Date: 2014-04-15 22:06:26 Summary: Client App: factor out config serializer, move defensive programming Affected #: 1 file diff -r 1da9460ee1d0d5f3f89a767e41c40b5188af988c -r 6f698dec58950f0f56421a13474df0359c0777d7 templates/galaxy_client_app.mako --- a/templates/galaxy_client_app.mako +++ b/templates/galaxy_client_app.mako @@ -3,27 +3,10 @@ <%def name="bootstrap()"> ## Bootstap dictionaries for GalaxyApp object's JSON, create GalaxyApp, ## and steal existing attributes from plain objects already created - <% - config_dict = {} - user_dict = {} - try: - if 'configuration' in trans.webapp.api_controllers: - config_dict = ( trans.webapp.api_controllers[ 'configuration' ] - .get_config_dict( trans.app.config, trans.user_is_admin() ) ) - - if 'users' in trans.webapp.api_controllers: - user_dict = self.get_user_dict() - - except Exception, exc: - pass - - # genomes - # datatypes - %><script type="text/javascript"> require([ 'galaxy-app-base' ], function( app ){ galaxy = new app.GalaxyApp({ - config : ${ h.to_json_string( config_dict ) }, + config : ${ get_config_json() }, userJSON : ${ get_user_json() }, root : '${h.url_for( "/" )}', //TODO: get these options from the server @@ -48,34 +31,64 @@ </script></%def> + +## ---------------------------------------------------------------------------- +<%def name="get_config_dict()"> + ## Return a dictionary of universe_wsgi.ini settings + <% + config_dict = {} + try: + if 'configuration' in trans.webapp.api_controllers: + config_dict = ( trans.webapp.api_controllers[ 'configuration' ] + .get_config_dict( trans.app.config, trans.user_is_admin() ) ) + except Exception, exc: + pass + + return config_dict + %> +</%def> + +<%def name="get_config_json()"> + ## Conv. fn to write as JSON +${ h.to_json_string( get_config_dict() )} +</%def> + + ## ---------------------------------------------------------------------------- <%def name="get_user_dict()"> ## Return a dictionary of user or anonymous user data including: ## email, id, disk space used, quota percent, and tags used <% - if trans.user: - user_dict = trans.user.to_dict( view='element', - value_mapper={ 'id': trans.security.encode_id, 'total_disk_usage': float } ) - user_dict[ 'quota_percent' ] = trans.app.quota_agent.get_percent( trans=trans ) + user_dict = {} + try: + if trans.user: + user_dict = trans.user.to_dict( view='element', + value_mapper={ 'id': trans.security.encode_id, 'total_disk_usage': float } ) + user_dict[ 'quota_percent' ] = trans.app.quota_agent.get_percent( trans=trans ) - # tags used - users_api_controller = trans.webapp.api_controllers[ 'users' ] - user_dict[ 'tags_used' ] = users_api_controller.get_user_tags_used( trans, user=trans.user ) - return user_dict + # tags used + users_api_controller = trans.webapp.api_controllers[ 'users' ] + user_dict[ 'tags_used' ] = users_api_controller.get_user_tags_used( trans, user=trans.user ) + return user_dict - usage = 0 - percent = None - try: - usage = trans.app.quota_agent.get_usage( trans, history=trans.history ) - percent = trans.app.quota_agent.get_percent( trans=trans, usage=usage ) - except AssertionError, assertion: - # no history for quota_agent.get_usage assertion + usage = 0 + percent = None + try: + usage = trans.app.quota_agent.get_usage( trans, history=trans.history ) + percent = trans.app.quota_agent.get_percent( trans=trans, usage=usage ) + except AssertionError, assertion: + # no history for quota_agent.get_usage assertion + pass + return { + 'total_disk_usage' : int( usage ), + 'nice_total_disk_usage' : util.nice_size( usage ), + 'quota_percent' : percent + } + + except Exception, exc: pass - return { - 'total_disk_usage' : int( usage ), - 'nice_total_disk_usage' : util.nice_size( usage ), - 'quota_percent' : percent - } + + return 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