Warning

This document is for an old release 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.webapps.base package

Submodules

galaxy.webapps.base.controller module

Contains functionality needed in every web interface

class galaxy.webapps.base.controller.BaseController(app)[source]

Bases: object

Base class for Galaxy web application controllers.

__init__(app)[source]

Initialize an interface for application ‘app’

get_toolbox()[source]

Returns the application toolbox

get_class(class_name)[source]

Returns the class object that a string denotes. Without this method, we’d have to do eval(<class_name>).

get_object(trans, id, class_name, check_ownership=False, check_accessible=False, deleted=None)[source]

Convenience method to get a model object with the specified checks.

get_user(trans, id, check_ownership=False, check_accessible=False, deleted=None)[source]
get_group(trans, id, check_ownership=False, check_accessible=False, deleted=None)[source]
get_role(trans, id, check_ownership=False, check_accessible=False, deleted=None)[source]
decode_id(id)[source]
encode_all_ids(trans, rval, recursive=False)[source]

Encodes all integer values in the dict rval whose keys are ‘id’ or end with ‘_id’

It might be useful to turn this in to a decorator

parse_filter_params(qdict, filter_attr_key='q', filter_value_key='qv', attr_op_split_char='-')[source]
parse_limit_offset(qdict)[source]
galaxy.webapps.base.controller.Root

alias of galaxy.webapps.base.controller.BaseController

class galaxy.webapps.base.controller.BaseUIController(app)[source]

Bases: galaxy.webapps.base.controller.BaseController

get_object(trans, id, class_name, check_ownership=False, check_accessible=False, deleted=None)[source]

Convenience method to get a model object with the specified checks.

message_exception(trans, message, sanitize=True)[source]
class galaxy.webapps.base.controller.BaseAPIController(app)[source]

Bases: galaxy.webapps.base.controller.BaseController

get_object(trans, id, class_name, check_ownership=False, check_accessible=False, deleted=None)[source]

Convenience method to get a model object with the specified checks.

validate_in_users_and_groups(trans, payload)[source]

For convenience, in_users and in_groups can be encoded IDs or emails/group names in the API.

not_implemented(trans, **kwd)[source]
class galaxy.webapps.base.controller.JSAppLauncher(app)[source]

Bases: galaxy.webapps.base.controller.BaseUIController

A controller that launches JavaScript web applications.

JS_APP_MAKO_FILEPATH = '/js-app.mako'

path to js app template

DEFAULT_ENTRY_FN = 'app'

window-scoped js function to call to start the app (will be passed options, bootstrapped)

USER_BOOTSTRAP_KEYS = ('id', 'email', 'username', 'is_admin', 'tags_used', 'total_disk_usage', 'nice_total_disk_usage', 'quota_percent', 'preferences')

keys used when serializing current user for bootstrapped data

__init__(app)[source]

Initialize an interface for application ‘app’

client(trans, **kwd)[source]

Endpoint for clientside routes. This ships the primary SPA client.

Should not be used with url_for – see (https://github.com/galaxyproject/galaxy/issues/1878) for why.

template(trans, app_name: str, entry_fn: str = 'app', options=None, bootstrapped_data: Optional[dict] = None, masthead: Optional[bool] = True, **additional_options)[source]

Render and return the single page mako template that starts the app.

Parameters
  • app_name – the first portion of the webpack bundle to as the app.

  • entry_fn – the name of the window-scope function that starts the app. Defaults to ‘app’.

  • bootstrapped_data – update containing any more data the app may need.

  • masthead – include masthead elements in the initial page dom.

  • additional_options – update to the options sent to the app.

class galaxy.webapps.base.controller.Datatype(extension, dtype, type_extension, mimetype, display_in_upload)[source]

Bases: object

Used for storing in-memory list of datatypes currently in the datatypes registry.

__init__(extension, dtype, type_extension, mimetype, display_in_upload)[source]

Initialize self. See help(type(self)) for accurate signature.

class galaxy.webapps.base.controller.CreatesApiKeysMixin[source]

Bases: object

Mixing centralizing logic for creating API keys for user objects.

Deprecated - please use api_keys.ApiKeyManager for new development.

create_api_key(trans, user)[source]
class galaxy.webapps.base.controller.SharableItemSecurityMixin[source]

Bases: object

Mixin for handling security for sharable items.

security_check(trans, item, check_ownership=False, check_accessible=False)[source]

Security checks for an item: checks if (a) user owns item or (b) item is accessible to user.

class galaxy.webapps.base.controller.ExportsHistoryMixin[source]

Bases: object

serve_ready_history_export(trans, jeha)[source]
queue_history_export(trans, history, gzip=True, include_hidden=False, include_deleted=False, directory_uri=None, file_name=None)[source]
class galaxy.webapps.base.controller.ImportsHistoryMixin[source]

Bases: object

queue_history_import(trans, archive_type, archive_source)[source]
class galaxy.webapps.base.controller.UsesLibraryMixinItems[source]

Bases: galaxy.webapps.base.controller.SharableItemSecurityMixin

get_library_folder(trans, id, check_ownership=False, check_accessible=True)[source]
get_library_dataset_dataset_association(trans, id, check_ownership=False, check_accessible=True)[source]
get_library_dataset(trans, id, check_ownership=False, check_accessible=True)[source]
can_current_user_add_to_library_item(trans, item)[source]
check_user_can_add_to_library_item(trans, item, check_accessible=True)[source]

Raise exception if user cannot add to the specified library item (i.e. Folder). Can set check_accessible to False if folder was loaded with this check.

copy_hda_to_library_folder(trans, hda, library_folder, roles=None, ldda_message='', element_identifier=None)[source]
class galaxy.webapps.base.controller.UsesVisualizationMixin[source]

Bases: galaxy.webapps.base.controller.UsesLibraryMixinItems

Mixin for controllers that use Visualization objects.

slug_builder = <galaxy.managers.sharable.SlugBuilder object>
get_visualization(trans, id, check_ownership=True, check_accessible=False)[source]

Get a Visualization from the database by id, verifying ownership.

get_visualizations_by_user(trans, user, order_by=None, query_only=False)[source]

Return query or query results of visualizations filtered by a user.

Set order_by to a column or list of columns to change the order returned. Defaults to DEFAULT_ORDER_BY. Set query_only to return just the query for further filtering or processing.

get_visualizations_shared_with_user(trans, user, order_by=None, query_only=False)[source]

Return query or query results for visualizations shared with the given user.

Set order_by to a column or list of columns to change the order returned. Defaults to DEFAULT_ORDER_BY. Set query_only to return just the query for further filtering or processing.

get_published_visualizations(trans, exclude_user=None, order_by=None, query_only=False)[source]

Return query or query results for published visualizations optionally excluding the user in exclude_user.

Set order_by to a column or list of columns to change the order returned. Defaults to DEFAULT_ORDER_BY. Set query_only to return just the query for further filtering or processing.

get_visualization_summary_dict(visualization)[source]

Return a set of summary attributes for a visualization in dictionary form. NOTE: that encoding ids isn’t done here should happen at the caller level.

get_visualization_dict(visualization)[source]

Return a set of detailed attributes for a visualization in dictionary form. The visualization’s latest_revision is returned in its own sub-dictionary. NOTE: that encoding ids isn’t done here should happen at the caller level.

get_visualization_revision_dict(revision)[source]

Return a set of detailed attributes for a visualization in dictionary form. NOTE: that encoding ids isn’t done here should happen at the caller level.

import_visualization(trans, id, user=None)[source]

Copy the visualization with the given id and associate the copy with the given user (defaults to trans.user).

Raises ItemAccessibilityException if user is not passed and the current user is anonymous, and if the visualization is not importable. Raises ItemDeletionException if the visualization has been deleted.

create_visualization(trans, type, title='Untitled Visualization', slug=None, dbkey=None, annotation=None, config=None, save=True)[source]

Create visualiation and first revision.

add_visualization_revision(trans, visualization, config, title, dbkey)[source]

Adds a new VisualizationRevision to the given visualization with the given parameters and set its parent visualization’s latest_revision to the new revision.

save_visualization(trans, config, type, id=None, title=None, dbkey=None, slug=None, annotation=None)[source]
get_tool_def(trans, hda)[source]

Returns definition of an interactive tool for an HDA.

get_visualization_config(trans, visualization)[source]

Returns a visualization’s configuration. Only works for trackster visualizations right now.

get_new_track_config(trans, dataset)[source]

Returns track configuration dict for a dataset.

get_hda_or_ldda(trans, hda_ldda, dataset_id)[source]

Returns either HDA or LDDA for hda/ldda and id combination.

get_hda(trans, dataset_id, check_ownership=True, check_accessible=False, check_state=True)[source]

Get an HDA object by id performing security checks using the current transaction.

Deprecated in lieu to galaxy.managers.hdas.HDAManager.get_accessible(decoded_id, user)

class galaxy.webapps.base.controller.UsesStoredWorkflowMixin[source]

Bases: galaxy.webapps.base.controller.SharableItemSecurityMixin, galaxy.model.item_attrs.UsesAnnotations

Mixin for controllers that use StoredWorkflow objects.

slug_builder = <galaxy.managers.sharable.SlugBuilder object>
get_stored_workflow(trans, id, check_ownership=True, check_accessible=False)[source]

Get a StoredWorkflow from the database by id, verifying ownership.

get_stored_workflow_steps(trans, stored_workflow)[source]

Restores states for a stored workflow’s steps.

class galaxy.webapps.base.controller.UsesFormDefinitionsMixin[source]

Bases: object

Mixin for controllers that use Galaxy form objects.

get_all_forms(trans, all_versions=False, filter=None, form_type='All')[source]

Return all the latest forms from the form_definition_current table if all_versions is set to True. Otherwise return all the versions of all the forms from the form_definition table.

save_widget_field(trans, field_obj, widget_name, **kwd)[source]
get_form_values(trans, user, form_definition, **kwd)[source]

Returns the name:value dictionary containing all the form values

class galaxy.webapps.base.controller.SharableMixin[source]

Bases: object

Mixin for a controller that manages an item that can be shared.

manager: Any = None
serializer: Any = None
slug_builder = <galaxy.managers.sharable.SlugBuilder object>
set_slug_async(trans, id, new_slug)[source]
share(trans, id=None, email='', **kwd)[source]

Handle sharing an item with a particular user.

display_by_username_and_slug(trans, username, slug)[source]

Display item by username and slug.

Returns item’s name and link.

get_item_content_async(trans, id)[source]

Returns item content in HTML format.

get_item(trans, id)[source]

Return item based on id.

class galaxy.webapps.base.controller.UsesQuotaMixin[source]

Bases: object

get_quota(trans, id, check_ownership=False, check_accessible=False, deleted=None)[source]
class galaxy.webapps.base.controller.UsesTagsMixin[source]

Bases: galaxy.webapps.base.controller.SharableItemSecurityMixin

get_tag_handler(trans)galaxy.model.tags.GalaxyTagHandler[source]
set_tags_from_list(trans, item, new_tags_list, user=None)[source]
get_user_tags_used(trans, user=None)[source]

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.

class galaxy.webapps.base.controller.UsesExtendedMetadataMixin[source]

Bases: galaxy.webapps.base.controller.SharableItemSecurityMixin

Mixin for getting and setting item extended metadata.

get_item_extended_metadata_obj(trans, item)[source]

Given an item object (such as a LibraryDatasetDatasetAssociation), find the object of the associated extended metadata

set_item_extended_metadata_obj(trans, item, extmeta_obj, check_writable=False)[source]
unset_item_extended_metadata_obj(trans, item, check_writable=False)[source]
create_extended_metadata(trans, extmeta)[source]

Create/index an extended metadata object. The returned object is not associated with any items

delete_extended_metadata(trans, item)[source]
galaxy.webapps.base.controller.sort_by_attr(seq, attr)[source]

Sort the sequence of objects by object’s attribute Arguments: seq - the list or any sequence (including immutable one) of objects to sort. attr - the name of attribute to sort by

galaxy.webapps.base.webapp module

class galaxy.webapps.base.webapp.WebApplication(galaxy_app, session_cookie='galaxysession', name=None)[source]

Bases: galaxy.web.framework.base.WebApplication

Base WSGI application instantiated for all Galaxy webapps.

A web application that:

  • adds API and UI controllers by scanning given directories and importing all modules found there.

  • has a security object.

  • builds mako template lookups.

  • generates GalaxyWebTransactions.

injection_aware: bool = False
__init__(galaxy_app, session_cookie='galaxysession', name=None)[source]

Create a new web application object. To actually connect some controllers use add_controller and add_route. Call finalize_config when all controllers and routes have been added and __call__ to handle a request (WSGI style).

create_mako_template_lookup(galaxy_app, name)[source]
handle_controller_exception(e, trans, **kwargs)[source]

Allow handling of exceptions raised in controller methods.

make_body_iterable(trans, body)[source]
transaction_chooser(environ, galaxy_app, session_cookie)[source]
add_ui_controllers(package_name, app)[source]

Search for UI controllers in package_name and add them to the webapp.

add_api_controllers(package_name, app)[source]

Search for UI controllers in package_name and add them to the webapp.

galaxy.webapps.base.webapp.config_allows_origin(origin_raw, config)[source]
galaxy.webapps.base.webapp.qualified_url_builder(path)[source]
class galaxy.webapps.base.webapp.GalaxyWebTransaction(environ: Dict[str, Any], app, webapp, session_cookie=None)[source]

Bases: galaxy.web.framework.base.DefaultWebTransaction, galaxy.managers.context.ProvidesHistoryContext

Encapsulates web transaction specific state for the Galaxy application (specifically the user’s “cookie” session and history)

__init__(environ: Dict[str, Any], app, webapp, session_cookie=None)None[source]

Initialize self. See help(type(self)) for accurate signature.

property app

Provide access to the Galaxy app object.

property qualified_url_builder

Provide access to fully qualified Galaxy URLs (if available).

setup_i18n()[source]
set_cors_allow(name=None, value=None)[source]
set_cors_origin(origin=None)[source]
set_cors_headers()[source]

Allow CORS requests if configured to do so by echoing back the request’s ‘Origin’ header (if any) as the response header ‘Access-Control-Allow-Origin’

Preflight OPTIONS requests to the API work by routing all OPTIONS requests to a single method in the authenticate API (options method), setting CORS headers, and responding OK.

NOTE: raising some errors (such as httpexceptions), will remove the header (e.g. client will get both CORS error and 404 inside that)

get_user()[source]

Return the current user if logged in or None.

set_user(user)[source]

Set the current user.

property user

Return the current user if logged in or None.

Convenience method for getting a session cookie

Convenience method for setting a session cookie

get_or_create_remote_user(remote_user_email)[source]

Create a remote user with the email remote_user_email and return it

property cookie_path
check_user_library_import_dir(user)[source]
user_checks(user)[source]

This could contain more checks around a user upon login

handle_user_login(user)[source]
Login a new user (possibly newly created)
  • do some ‘system’ checks (if any) for this user

  • create a new session

  • associate new session with user

  • if old session had a history and it was not associated with a user, associate it with the new session, otherwise associate the current session’s history with the user

  • add the disk usage of the current session to the user’s total disk usage

handle_user_logout(logout_all=False)[source]
Logout the current user:
  • invalidate the current session

  • create a new session with no user associated

get_galaxy_session()[source]

Return the current galaxy session

get_history(create=False, most_recent=False)[source]

Load the current history.

  • If that isn’t available, we find the most recently updated history.

  • If that isn’t available, we get or create the default history.

Transactions will not always have an active history (API requests), so None is a valid response.

set_history(history)[source]
property history

Provide access to the user’s current history model object.

Return type

Optional[galaxy.model.History]

get_or_create_default_history()[source]

Gets or creates a default history and associates it with the current session.

get_most_recent_history()[source]

Gets the most recently updated history.

new_history(name=None)[source]

Create a new history and associate it with the current session and its associated user (if set).

template_context

Property that replaces itself with a calculated value the first time it is used.

set_message(message, type=None)[source]

Convenience method for setting the ‘message’ and ‘message_type’ element of the template context.

get_message()[source]

Convenience method for getting the ‘message’ element of the template context.

show_message(message, type='info', refresh_frames=None, cont=None, use_panels=False, active_view='')[source]

Convenience method for displaying a simple page with a single message.

type: one of “error”, “warning”, “info”, or “done”; determines the

type of dialog box and icon displayed with the message

refresh_frames: names of frames in the interface that should be

refreshed when the message is displayed

show_error_message(message, refresh_frames=None, use_panels=False, active_view='')[source]

Convenience method for displaying an error message. See show_message.

show_ok_message(message, refresh_frames=None, use_panels=False, active_view='')[source]

Convenience method for displaying an ok message. See show_message.

show_warn_message(message, refresh_frames=None, use_panels=False, active_view='')[source]

Convenience method for displaying an warn message. See show_message.

property session_csrf_token
check_csrf_token(payload)[source]
fill_template(filename, **kwargs)[source]

Fill in a template, putting any keyword arguments on the context.

fill_template_mako(filename, template_lookup=None, **kwargs)[source]
stream_template_mako(filename, **kwargs)[source]
qualified_url_for_path(path)[source]
galaxy.webapps.base.webapp.default_url_path(path)[source]
galaxy.webapps.base.webapp.build_native_uwsgi_app(paste_factory, config_section)[source]

uwsgi can load paste factories with –ini-paste, but this builds non-paste uwsgi apps.

In particular these are useful with –yaml or –json for config.

galaxy.webapps.base.webapp.build_url_map(app, global_conf, local_conf)[source]