def create_ConPlot(plot_click, refresh_click, factor, contact_marker_size, track_marker_size, track_separation, track_selection, cmap_selection, transparent, superimpose, distance_matrix, verbose_labels, selected_palettes, session_id): trigger = dash.callback_context.triggered[0] cache = keydb.KeyDB(connection_pool=keydb_pool) if not callback_utils.ensure_triggered(trigger): return no_update, None, no_update, no_update elif session_utils.is_expired_session(session_id, cache, app.logger): return components.PlotPlaceHolder(), components.SessionTimedOutModal( ), components.DisplayControlCard(), True app.logger.info('Session {} plot requested'.format(session_id)) if any([ True for x in (factor, contact_marker_size, track_marker_size, track_separation) if x is None or x < 0 ]): app.logger.info( 'Session {} invalid display control value detected'.format( session_id)) return no_update, components.InvalidInputModal(), no_update, no_update elif superimpose and ('--- Empty ---' in cmap_selection or len(set(cmap_selection)) == 1): return no_update, components.InvalidMapSelectionModal( ), no_update, no_update app.logger.info('Session {} creating conplot'.format(session_id)) return plot_utils.create_ConPlot( session_id, cache, trigger, track_selection, cmap_selection, selected_palettes, factor, contact_marker_size, track_marker_size, track_separation, transparent, superimpose, distance_matrix, verbose_labels)
def manage_stored_sessions(delete_clicks, load_click, stop_share, load_share, session_id): trigger = dash.callback_context.triggered[0] cache = keydb.KeyDB(connection_pool=keydb_pool) if session_utils.is_expired_session(session_id, cache, app.logger): return components.SessionTimedOutToast(), no_update, no_update elif not callback_utils.ensure_triggered(trigger): return no_update, no_update, no_update selected_session_pkid, action = callback_utils.get_session_action(trigger) username, current_session_pkid = session_utils.get_current_info( session_id, cache) if action == callback_utils.ButtonActions.delete: return session_utils.delete_session(selected_session_pkid, current_session_pkid, session_id, app.logger) elif action == callback_utils.ButtonActions.load: return session_utils.load_session(username, selected_session_pkid, session_id, cache, app.logger) elif action == callback_utils.ButtonActions.stop: return session_utils.stop_share_session(username, selected_session_pkid, current_session_pkid, session_id, app.logger)
def javascript_exe_button(n_clicks, session_id): trigger = dash.callback_context.triggered[-1] cache = keydb.KeyDB(connection_pool=keydb_pool) if not callback_utils.ensure_triggered(trigger): return no_update, no_update, no_update elif 'new-session' in trigger[ 'prop_id'] or session_utils.is_expired_session( session_id, cache, app.logger): cache = keydb.KeyDB(connection_pool=keydb_pool) new_session_id = session_utils.initiate_session( cache, app.logger, keydb_timeout) return "location.reload();", no_update, new_session_id else: app.logger.info('Fetching example data') try: session_utils.load_session('user_1', 46, session_id, cache, app.logger) except (psycopg2.OperationalError, AttributeError) as e: app.logger.error('Unable to fetch example data: {}'.format(e)) return no_update, components.ExampleSessionConnectionErrorModal( ), no_update return "location.reload();", no_update, no_update
def store_session(n_clicks, session_name, session_id): trigger = dash.callback_context.triggered[0] cache = keydb.KeyDB(connection_pool=keydb_pool) if session_utils.is_expired_session(session_id, cache, app.logger): return components.SessionTimedOutToast() elif not callback_utils.ensure_triggered(trigger): return no_update return session_utils.store_session(session_name, session_id, cache, app.logger)
def change_password(n_clicks, old_password, new_password, session_id): trigger = dash.callback_context.triggered[0] cache = keydb.KeyDB(connection_pool=keydb_pool) if session_utils.is_expired_session(session_id, cache, app.logger): return components.SessionTimedOutToast() elif not callback_utils.ensure_triggered(trigger): return no_update return app_utils.change_password(new_password, old_password, cache, session_id, app.logger)
def require_user_login(n_clicks, username, password, session_id): trigger = dash.callback_context.triggered[0] cache = keydb.KeyDB(connection_pool=keydb_pool) if session_utils.is_expired_session(session_id, cache, app.logger): return no_update, components.SessionTimedOutToast() elif not callback_utils.ensure_triggered(trigger): return no_update, no_update return app_utils.user_login(username, password, session_id, cache, app.logger)[:-1]
def remove_dataset(alerts_open, session_id): trigger = dash.callback_context.triggered[-1] cache = keydb.KeyDB(connection_pool=keydb_pool) if not callback_utils.ensure_triggered(trigger): return None elif session_utils.is_expired_session(session_id, cache, app.logger): return components.SessionTimedOutModal() data_utils.remove_dataset(trigger, cache, session_id, app.logger) return None
def create_user(n_clicks, username, password, email, session_id): trigger = dash.callback_context.triggered[0] cache = keydb.KeyDB(connection_pool=keydb_pool) if session_utils.is_expired_session(session_id, cache, app.logger): return no_update, components.SessionTimedOutModal( ), no_update, no_update, no_update, no_update elif not callback_utils.ensure_triggered(trigger): return no_update, no_update, no_update, no_update, no_update, no_update return app_utils.create_user(username, password, email, session_id, cache, app.logger)
def submit_contact_form(n_clicks, name, email, subject, description, session_id): trigger = dash.callback_context.triggered[0] cache = keydb.KeyDB(connection_pool=keydb_pool) if session_utils.is_expired_session(session_id, cache, app.logger): return components.SessionTimedOutModal(), None, None, None, None elif not callback_utils.ensure_triggered(trigger): return no_update, no_update, no_update, no_update, no_update return callback_utils.submit_form(name, email, subject, description, app.logger), None, None, None, None
def display_page(url, session_id): trigger = dash.callback_context.triggered[0] cache = keydb.KeyDB(connection_pool=keydb_pool) if url is None: return no_update elif session_utils.is_expired_session(session_id, cache, app.logger): return layouts.SessionTimeout(session_id) elif not callback_utils.ensure_triggered(trigger): return no_update app.logger.info('Session {} requested url {}'.format(session_id, url)) return app_utils.serve_url(url, session_id, cache, app.logger)
def upload_additional_track(fname, fcontent, input_format, fname_alerts, session_id): trigger = dash.callback_context.triggered[0] cache = keydb.KeyDB(connection_pool=keydb_pool) if session_utils.is_expired_session(session_id, cache, app.logger): return no_update, None, components.SessionTimedOutModal() elif not callback_utils.ensure_triggered(trigger): return callback_utils.retrieve_additional_fnames(session_id, cache), None, None return data_utils.upload_dataset(fname, fcontent, input_format, fname_alerts, session_id, cache, app.logger)
def upload_sequence(fname, fcontent, session_id): trigger = dash.callback_context.triggered[0] cache = keydb.KeyDB(connection_pool=keydb_pool) if session_utils.is_expired_session(session_id, cache, app.logger): return no_update, None, components.SessionTimedOutModal() elif not callback_utils.ensure_triggered(trigger): return callback_utils.retrieve_sequence_fname(session_id, cache), None, None elif not cache_utils.is_valid_fname(fname): return no_update, no_update, components.InvalidFnameModal(fname) return data_utils.upload_sequence(fname, fcontent, session_id, cache, app.logger)
def share_session(share_click, share_with, session_pkid, session_id): trigger = dash.callback_context.triggered[0] cache = keydb.KeyDB(connection_pool=keydb_pool) session_pkid = session_pkid['index'] if session_utils.is_expired_session(session_id, cache, app.logger): return components.SessionTimedOutToast() elif not callback_utils.ensure_triggered(trigger): return no_update username, current_session_pkid = session_utils.get_current_info( session_id, cache) if not share_with: return components.InvalidUsernameToast() elif username == share_with: return components.ShareWithOwnerToast() return session_utils.share_session(session_pkid, share_with, app.logger)
def upload_contact(fname, fcontent, input_format, fname_alerts, session_id): trigger = dash.callback_context.triggered[0] cache = keydb.KeyDB(connection_pool=keydb_pool) if session_utils.is_expired_session(session_id, cache, app.logger): return no_update, None, components.SessionTimedOutModal() elif not callback_utils.ensure_triggered(trigger): return callback_utils.retrieve_contact_fnames(session_id, cache), None, None elif not cache_utils.is_valid_fname(fname): return no_update, no_update, components.InvalidFnameModal(fname) return data_utils.upload_dataset( fname, fcontent, input_format, fname_alerts, session_id, cache, app.logger, dataset=loaders.DatasetReference.CONTACT_MAP.value)