galaxy.web package

The Galaxy web application framework

galaxy.web.url_for(*args, **kargs)[source]

Generates a URL

All keys given to url_for are sent to the Routes Mapper instance for generation except for:

anchor          specified the anchor name to be appened to the path
host            overrides the default (current) host if provided
protocol        overrides the default (current) protocol if provided
qualified       creates the URL with the host/port information as
                needed

The URL is generated based on the rest of the keys. When generating a new URL, values will be used from the current request’s parameters (if present). The following rules are used to determine when and how to keep the current requests parameters:

  • If the controller is present and begins with ‘/’, no defaults are used
  • If the controller is changed, action is set to ‘index’ unless otherwise specified

For example, if the current request yielded a dict of {‘controller’: ‘blog’, ‘action’: ‘view’, ‘id’: 2}, with the standard ‘:controller/:action/:id’ route, you’d get the following results:

url_for(id=4)                    =>  '/blog/view/4',
url_for(controller='/admin')     =>  '/admin',
url_for(controller='admin')      =>  '/admin/view/2'
url_for(action='edit')           =>  '/blog/edit/2',
url_for(action='list', id=None)  =>  '/blog/list'

Static and Named Routes

If there is a string present as the first argument, a lookup is done against the named routes table to see if there’s any matching routes. The keyword defaults used with static routes will be sent in as GET query arg’s if a route matches.

If no route by that name is found, the string is assumed to be a raw URL. Should the raw URL begin with / then appropriate SCRIPT_NAME data will be added if present, otherwise the string will be used as the url with keyword args becoming GET query args.

galaxy.web.error(message)[source]
galaxy.web.expose(func)[source]

Decorator: mark a function as ‘exposed’ and thus web accessible

galaxy.web.json(func, pretty=False)[source]

Format the response as JSON and set the response content type to JSON_CONTENT_TYPE.

galaxy.web.json_pretty(func)[source]

Indent and sort returned JSON.

galaxy.web.require_admin(func)[source]
galaxy.web.require_login(verb='perform this action', use_panels=False, webapp='galaxy')[source]
galaxy.web.expose_api(func, to_json=True, user_required=True)[source]

Expose this function via the API.

galaxy.web.expose_api_anonymous(func, to_json=True)[source]

Expose this function via the API but don’t require a set user.

galaxy.web.expose_api_raw(func)[source]

Expose this function via the API but don’t dump the results to JSON.

galaxy.web.expose_api_raw_anonymous(func)[source]

Expose this function via the API but don’t dump the results to JSON.

galaxy.web.form(*args, **kwargs)[source]
class galaxy.web.FormBuilder(action='', title='', name='form', submit_text='submit', use_panels=False)[source]

Bases: object

Simple class describing an HTML form

__init__(action='', title='', name='form', submit_text='submit', use_panels=False)[source]
add_checkbox(name, label, value=None, error=None, help=None)[source]
add_input(type, name, label, value=None, error=None, help=None, use_label=True)[source]
add_password(name, label, value=None, error=None, help=None)[source]
add_select(name, label, value=None, options=[], error=None, help=None, use_label=True)[source]
add_text(name, label, value=None, error=None, help=None)[source]

Submodules

galaxy.web.buildapp module

For backward compatibility only, pulls app_factor from galaxy.webapps.main

galaxy.web.buildapp.app_factory(global_conf, **kwargs)[source]

galaxy.web.form_builder module

Classes for generating HTML forms

class galaxy.web.form_builder.BaseField(name, value=None, label=None, **kwds)[source]

Bases: object

__init__(name, value=None, label=None, **kwds)[source]
get_html(prefix='')[source]

Returns the html widget corresponding to the parameter

get_disabled_str(disabled=False)[source]
to_dict()[source]
class galaxy.web.form_builder.TextField(name, size=None, value=None, **kwds)[source]

Bases: galaxy.web.form_builder.BaseField

A standard text input box.

>>> print TextField( "foo" ).get_html()
<input type="text" name="foo" size="10" value="">
>>> print TextField( "bins", size=4, value="default" ).get_html()
<input type="text" name="bins" size="4" value="default">
__init__(name, size=None, value=None, **kwds)[source]
get_html(prefix='', disabled=False)[source]
set_size(size)[source]
to_dict()[source]
class galaxy.web.form_builder.PasswordField(name, size=None, value=None, **kwds)[source]

Bases: galaxy.web.form_builder.BaseField

A password input box. text appears as “**

>>> print PasswordField( "foo" ).get_html()
<input type="password" name="foo" size="10" value="">
>>> print PasswordField( "bins", size=4, value="default" ).get_html()
<input type="password" name="bins" size="4" value="default">
__init__(name, size=None, value=None, **kwds)[source]
get_html(prefix='', disabled=False)[source]
set_size(size)[source]
to_dict()[source]
class galaxy.web.form_builder.TextArea(name, size=None, value=None, **kwds)[source]

Bases: galaxy.web.form_builder.BaseField

A standard text area box.

>>> print TextArea( "foo" ).get_html()
<textarea name="foo" rows="5" cols="25"></textarea>
>>> print TextArea( "bins", size="4x5", value="default" ).get_html()
<textarea name="bins" rows="4" cols="5">default</textarea>
__init__(name, size=None, value=None, **kwds)[source]
get_html(prefix='', disabled=False)[source]
set_size(rows, cols)[source]
to_dict()[source]
class galaxy.web.form_builder.CheckboxField(name, checked=None, refresh_on_change=False, refresh_on_change_values=None, value=None, **kwds)[source]

Bases: galaxy.web.form_builder.BaseField

A checkbox (boolean input)

>>> print CheckboxField( "foo" ).get_html()
<input type="checkbox" id="foo" name="foo" value="__CHECKED__"><input type="hidden" name="foo" value="__NOTHING__">
>>> print CheckboxField( "bar", checked="yes" ).get_html()
<input type="checkbox" id="bar" name="bar" value="__CHECKED__" checked="checked"><input type="hidden" name="bar" value="__NOTHING__">
__init__(name, checked=None, refresh_on_change=False, refresh_on_change_values=None, value=None, **kwds)[source]
get_html(prefix='', disabled=False)[source]
static is_checked(value)[source]
set_checked(value)[source]
to_dict()[source]
class galaxy.web.form_builder.FileField(name, value=None, ajax=False, **kwds)[source]

Bases: galaxy.web.form_builder.BaseField

A file upload input.

>>> print FileField( "foo" ).get_html()
<input type="file" name="foo">
>>> print FileField( "foo", ajax = True ).get_html()
<input type="file" name="foo" galaxy-ajax-upload="true">
__init__(name, value=None, ajax=False, **kwds)[source]
get_html(prefix='')[source]
class galaxy.web.form_builder.HiddenField(name, value=None, **kwds)[source]

Bases: galaxy.web.form_builder.BaseField

A hidden field.

>>> print HiddenField( "foo", 100 ).get_html()
<input type="hidden" name="foo" value="100">
__init__(name, value=None, **kwds)[source]
get_html(prefix='')[source]
to_dict()[source]
class galaxy.web.form_builder.SelectField(name, multiple=None, display=None, refresh_on_change=False, refresh_on_change_values=None, size=None, field_id=None, value=None, selectlist=None, **kwds)[source]

Bases: galaxy.web.form_builder.BaseField

A select field.

>>> t = SelectField( "foo", multiple=True )
>>> t.add_option( "tuti", 1 )
>>> t.add_option( "fruity", "x" )
>>> print t.get_html()
<select name="foo" multiple>
<option value="1">tuti</option>
<option value="x">fruity</option>
</select>
>>> t = SelectField( "bar" )
>>> t.add_option( "automatic", 3 )
>>> t.add_option( "bazooty", 4, selected=True )
>>> print t.get_html()
<select name="bar" last_selected_value="4">
<option value="3">automatic</option>
<option value="4" selected>bazooty</option>
</select>
>>> t = SelectField( "foo", display="radio" )
>>> t.add_option( "tuti", 1 )
>>> t.add_option( "fruity", "x" )
>>> print t.get_html()
<div><input type="radio" name="foo" value="1" id="foo|1"><label class="inline" for="foo|1">tuti</label></div>
<div><input type="radio" name="foo" value="x" id="foo|x"><label class="inline" for="foo|x">fruity</label></div>
>>> t = SelectField( "bar", multiple=True, display="checkboxes" )
>>> t.add_option( "automatic", 3 )
>>> t.add_option( "bazooty", 4, selected=True )
>>> print t.get_html()
<div class="checkUncheckAllPlaceholder" checkbox_name="bar"></div>
<div><input type="checkbox" name="bar" value="3" id="bar|3"><label class="inline" for="bar|3">automatic</label></div>
<div><input type="checkbox" name="bar" value="4" id="bar|4" checked='checked'><label class="inline" for="bar|4">bazooty</label></div>
__init__(name, multiple=None, display=None, refresh_on_change=False, refresh_on_change_values=None, size=None, field_id=None, value=None, selectlist=None, **kwds)[source]
add_option(text, value, selected=False)[source]
get_html(prefix='', disabled=False, extra_attr=None)[source]
get_html_checkboxes(prefix='', disabled=False)[source]
get_html_radio(prefix='', disabled=False)[source]
get_html_default(prefix='', disabled=False)[source]
get_selected(return_label=False, return_value=False, multi=False)[source]

Return the currently selected option’s label, value or both as a tuple. For multi-select lists, a list is returned.

to_dict()[source]
class galaxy.web.form_builder.AddressField(name, user=None, value=None, params=None, security=None, **kwds)[source]

Bases: galaxy.web.form_builder.BaseField

static fields()[source]
__init__(name, user=None, value=None, params=None, security=None, **kwds)[source]
get_html(disabled=False)[source]
to_dict()[source]
class galaxy.web.form_builder.WorkflowField(name, user=None, value=None, params=None, security=None, **kwds)[source]

Bases: galaxy.web.form_builder.BaseField

__init__(name, user=None, value=None, params=None, security=None, **kwds)[source]
get_html(disabled=False)[source]
to_dict()[source]
class galaxy.web.form_builder.WorkflowMappingField(name, user=None, value=None, params=None, **kwd)[source]

Bases: galaxy.web.form_builder.BaseField

__init__(name, user=None, value=None, params=None, **kwd)[source]
get_html(disabled=False)[source]
class galaxy.web.form_builder.HistoryField(name, user=None, value=None, params=None, security=None, **kwds)[source]

Bases: galaxy.web.form_builder.BaseField

__init__(name, user=None, value=None, params=None, security=None, **kwds)[source]
get_html(disabled=False)[source]
to_dict()[source]
galaxy.web.form_builder.get_suite()[source]

Get unittest suite for this module

galaxy.web.form_builder.build_select_field(trans, objs, label_attr, select_field_name, initial_value='none', selected_value='none', refresh_on_change=False, multiple=False, display=None, size=None)[source]

Build a SelectField given a set of objects. The received params are:

  • objs: the set of objects used to populate the option list

  • label_attr: the attribute of each obj (e.g., name, email, etc ) whose value is used to populate each option label.

    • If the string ‘self’ is passed as label_attr, each obj in objs is assumed to be a string, so the obj itself is used
  • select_field_name: the name of the SelectField

  • initial_value: the value of the first option in the SelectField - allows for an option telling the user to select something

  • selected_value: the value of the currently selected option

  • refresh_on_change: True if the SelectField should perform a refresh_on_change

galaxy.web.formatting module

galaxy.web.formatting.expand_pretty_datetime_format(value)[source]
>>> expand_pretty_datetime_format("%H:%M:%S %Z")
'%H:%M:%S %Z'
>>> locale_format = expand_pretty_datetime_format("$locale (UTC)")
>>> import locale
>>> expected_format = '%s (UTC)' % locale.nl_langinfo(locale.D_T_FMT)
>>> locale_format == expected_format
True
>>> expand_pretty_datetime_format("$iso8601")
'%Y-%m-%d %H:%M:%S'

galaxy.web.params module

Mixins for parsing web form and API parameters

class galaxy.web.params.BaseParamParser[source]

Bases: object

get_params(kwargs)[source]
class galaxy.web.params.QuotaParamParser[source]

Bases: galaxy.web.params.BaseParamParser

get_quota_params(kwargs)[source]