Warning

This document is for an in-development version of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.

galaxy.web.framework.helpers package

Galaxy web framework helpers

The functions in this module should be considered part of the API used by visualizations in their mako files through the $h object, see GalaxyWebTransaction in galaxy/webapps/base/webapp.py

galaxy.web.framework.helpers.time_ago(x)[source]

Convert a datetime to a string.

galaxy.web.framework.helpers.iff(a, b, c)[source]

Ternary shortcut

galaxy.web.framework.helpers.truncate(content, length=100, suffix='...')[source]

Smart string truncation

galaxy.web.framework.helpers.css(*args)[source]

Take a list of stylesheet names (no extension) and return appropriate string of link tags.

Cache-bust with time that server started running on

galaxy.web.framework.helpers.dist_css(*args)[source]

Transition function ‘css’ helper – this is the modern way where all bundled artifacts are in the unified ‘dist’.

galaxy.web.framework.helpers.js_helper(prefix, *args)[source]

Take a prefix and list of javascript names and return appropriate string of script tags.

Cache-bust with time that server started running on

galaxy.web.framework.helpers.dist_js(*args)[source]

Take a prefix and list of javascript names and return appropriate string of script tags.

galaxy.web.framework.helpers.is_true(val)[source]

Returns true if input is a boolean and true or is a string and looks like a true value.

galaxy.web.framework.helpers.to_js_bool(val)[source]

Prints javascript boolean for passed value. TODO: isn’t there a standard python JSON parser we should be using instead of all these manual conversions?

galaxy.web.framework.helpers.js_nullable(val)[source]

Prints javascript null instead of python None TODO: isn’t there a standard python JSON parser we should be using instead of all these manual conversions?

Submodules

galaxy.web.framework.helpers.grids module

class galaxy.web.framework.helpers.grids.GridColumn(label, key=None, model_class=None, method=None, format=None, escape=True)[source]

Bases: object

__init__(label, key=None, model_class=None, method=None, format=None, escape=True)[source]

Create a grid column.

get_value(trans, grid, item)[source]
sort(trans, query, ascending, column_name=None)[source]

Sort query using this column.

class galaxy.web.framework.helpers.grids.GridData[source]

Bases: object

Specifies the content a grid (data table).

model_class: type | None = None
columns: List[GridColumn] = []
default_limit: int = 1000
__init__()[source]

galaxy.web.framework.helpers.tags module

Code derived from WebHelpers: https://bitbucket.org/bbangert/webhelpers

Licensed under the MIT license: https://bitbucket.org/bbangert/webhelpers/src/tip/LICENSE

galaxy.web.framework.helpers.tags.format_attrs(**attrs)[source]

Format HTML attributes into a string of ‘ key=”value”’ pairs which can be inserted into an HTML tag.

The attributes are sorted alphabetically. If any value is None, the entire attribute is suppressed.

Usage: >>> format_attrs(p=2, q=3) == u’ p=”2” q=”3”’ True >>> format_attrs(p=2, q=None) == u’ p=”2”’ True >>> format_attrs(p=None) == u’’ True

Return script include tags for the specified javascript URLs.

urls should be the exact URLs desired. A previous version of this helper added magic prefixes; this is no longer the case.

Specify the keyword argument defer=True to enable the script defer attribute.

Examples:

>>> print(javascript_link('/javascripts/prototype.js', '/other-javascripts/util.js'))
<script src="/javascripts/prototype.js" type="text/javascript"></script>
<script src="/other-javascripts/util.js" type="text/javascript"></script>

>>> print(javascript_link('/app.js', '/test/test.1.js'))
<script src="/app.js" type="text/javascript"></script>
<script src="/test/test.1.js" type="text/javascript"></script>

Return CSS link tags for the specified stylesheet URLs.

urls should be the exact URLs desired. A previous version of this helper added magic prefixes; this is no longer the case.

Examples:

>>> print(stylesheet_link('/stylesheets/style.css'))
<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />

>>> print(stylesheet_link('/stylesheets/dir/file.css', media='all'))
<link href="/stylesheets/dir/file.css" media="all" rel="stylesheet" type="text/css" />