本文整理汇总了Python中tvb.interfaces.web.controllers.common.add2session函数的典型用法代码示例。如果您正苦于以下问题:Python add2session函数的具体用法?Python add2session怎么用?Python add2session使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add2session函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_burst_from_json
def load_burst_from_json(self, **data):
"""Upload Burst from previously exported JSON file"""
self.logger.debug("Uploading ..." + str(data))
try:
upload_param = "uploadedfile"
if upload_param in data and data[upload_param]:
upload_param = data[upload_param]
if isinstance(upload_param, FieldStorage) or isinstance(upload_param, Part):
if not upload_param.file:
raise BurstServiceException("Please select a valid JSON file.")
upload_param = upload_param.file.read()
upload_param = json.loads(upload_param)
prj_id = common.get_current_project().id
importer = ImportService()
burst_entity = importer.load_burst_entity(upload_param, prj_id)
common.add2session(common.KEY_BURST_CONFIG, burst_entity)
except Exception as excep:
self.logger.warning(excep.message)
common.set_error_message(excep.message)
raise cherrypy.HTTPRedirect('/burst/')
示例2: profile
def profile(self, logout=False, save=False, **data):
"""
Display current user's profile page.
On POST: logout, or save password/email.
"""
if cherrypy.request.method == "POST" and logout:
raise cherrypy.HTTPRedirect("/user/logout")
template_specification = dict(mainContent="profile", title="User Profile")
user = common.get_logged_user()
if cherrypy.request.method == "POST" and save:
try:
form = EditUserForm()
data = form.to_python(data)
if data.get(KEY_PASSWORD):
user.password = md5(data[KEY_PASSWORD]).hexdigest()
if data.get(KEY_EMAIL):
user.email = data[KEY_EMAIL]
old_password = None
if data.get("old_password"):
old_password = md5(data["old_password"]).hexdigest()
self.user_service.edit_user(user, old_password)
if old_password:
common.set_info_message("Changes Submitted!")
else:
common.set_info_message("Submitted! No password changed.")
except formencode.Invalid, excep:
template_specification[common.KEY_ERRORS] = excep.unpack_errors()
except UsernameException, excep:
self.logger.exception(excep)
user = common.get_logged_user()
common.add2session(common.KEY_USER, self.user_service.get_user_by_id(user.id))
common.set_error_message("Could not save changes. Probably wrong old password!!")
示例3: submit_model_parameters
def submit_model_parameters(self, submit_action="cancel_action"):
"""
Collects the model parameters values from all the models used for the surface vertices.
@:param submit_action: a post parameter. It distinguishes if this request is a cancel or a submit
"""
if submit_action == "submit_action":
context_model_parameters = common.get_from_session(KEY_CONTEXT_MPS)
burst_configuration = common.get_from_session(common.KEY_BURST_CONFIG)
for original_param, modified_param in context_model_parameters.prepared_model_parameter_names.items():
full_name = PARAMS_MODEL_PATTERN % (context_model_parameters.model_name, original_param)
param_data = context_model_parameters.get_data_for_model_param(original_param, modified_param)
if isinstance(param_data, dict):
equation = param_data[KEY_EQUATION]
focal_points = param_data[KEY_FOCAL_POINTS]
# if focal points or the equation are missing do not update this model parameter
if not focal_points or not equation:
continue
param_data[KEY_EQUATION] = equation.to_json(equation)
param_data[KEY_FOCAL_POINTS] = json.dumps(focal_points)
param_data = json.dumps(param_data)
burst_configuration.update_simulation_parameter(full_name, param_data)
### Update in session BURST configuration for burst-page.
common.add2session(common.KEY_BURST_CONFIG, burst_configuration.clone())
### Clean from session drawing context
common.remove_from_session(KEY_CONTEXT_MPS)
raise cherrypy.HTTPRedirect("/burst/")
示例4: settings
def settings(self, save_settings=False, **data):
"""Main settings page submit and get"""
template_specification = dict(mainContent="../settings/system_settings", title="System Settings")
if save_settings:
try:
form = SettingsForm()
data = form.to_python(data)
isrestart, isreset = self.settingsservice.save_settings(**data)
if isrestart:
thread = threading.Thread(target=self._restart_services, kwargs={'should_reset': isreset})
thread.start()
common.add2session(common.KEY_IS_RESTART, True)
common.set_important_message('Please wait until TVB is restarted properly!')
raise cherrypy.HTTPRedirect('/tvb')
# Here we will leave the same settings page to be displayed.
# It will continue reloading when CherryPy restarts.
except formencode.Invalid as excep:
template_specification[common.KEY_ERRORS] = excep.unpack_errors()
except InvalidSettingsException as excep:
self.logger.error('Invalid settings! Exception %s was raised' % (str(excep)))
common.set_error_message(excep.message)
template_specification.update({'keys_order': self.settingsservice.KEYS_DISPLAY_ORDER,
'config_data': self.settingsservice.configurable_keys,
common.KEY_FIRST_RUN: TvbProfile.is_first_run()})
return self.fill_default_attributes(template_specification)
示例5: save_parameters
def save_parameters(self, index_in_tab, **data):
"""
Save parameters
:param tab_nr: the index of the selected tab
:param index_in_tab: the index of the configured portlet in the selected tab
:param data: the {"portlet_parameters": json_string} Where json_string is a Jsonified dictionary
{"name": value}, representing the configuration of the current portlet
Having these inputs, current method updated the configuration of the portlet in the
corresponding tab position form the burst configuration in session.
"""
burst_config = common.get_from_session(common.KEY_BURST_CONFIG)
tab_nr = burst_config.selected_tab
old_portlet_config = burst_config.tabs[int(tab_nr)].portlets[int(index_in_tab)]
data = json.loads(data['portlet_parameters'])
# Replace all void entries with 'None'
for entry in data:
if data[entry] == '':
data[entry] = None
need_relaunch = self.burst_service.update_portlet_configuration(old_portlet_config, data)
if need_relaunch:
#### Reset Burst Configuration into an entity not persisted (id = None for all)
common.add2session(common.KEY_BURST_CONFIG, burst_config.clone())
return "relaunchView"
else:
self.workflow_service.store_workflow_step(old_portlet_config.visualizer)
return "noRelaunch"
示例6: index
def index(self, **data):
"""
Login page (with or without messages).
"""
template_specification = dict(mainContent="login", title="Login", data=data)
if cherrypy.request.method == 'POST':
form = LoginForm()
try:
data = form.to_python(data)
username = data[KEY_USERNAME]
password = data[KEY_PASSWORD]
user = self.user_service.check_login(username, password)
if user is not None:
common.add2session(common.KEY_USER, user)
common.set_info_message('Welcome ' + username)
self.logger.debug("User " + username + " has just logged in!")
if user.selected_project is not None:
prj = user.selected_project
prj = ProjectService().find_project(prj)
self._mark_selected(prj)
raise cherrypy.HTTPRedirect('/user/profile')
else:
common.set_error_message('Wrong username/password, or user not yet validated...')
self.logger.debug("Wrong username " + username + " !!!")
except formencode.Invalid as excep:
template_specification[common.KEY_ERRORS] = excep.unpack_errors()
return self.fill_default_attributes(template_specification)
示例7: step_1
def step_1(self, do_reset=0, **kwargs):
"""
Generate the html for the first step of the local connectivity page.
:param do_reset: Boolean telling to start from empty page or not
:param kwargs: not actually used, but parameters are still submitted from UI since we just\
use the same js function for this. TODO: do this in a smarter way
"""
if int(do_reset) == 1:
new_context = ContextLocalConnectivity()
common.add2session(KEY_LCONN_CONTEXT, new_context)
context = common.get_from_session(KEY_LCONN_CONTEXT)
right_side_interface = self._get_lconn_interface()
left_side_interface = self.get_select_existent_entities('Load Local Connectivity', LocalConnectivity,
context.selected_entity)
# add interface to session, needed for filters
self.add_interface_to_session(left_side_interface, right_side_interface['inputList'])
template_specification = dict(title="Surface - Local Connectivity")
template_specification['mainContent'] = 'spatial/local_connectivity_step1_main'
template_specification.update(right_side_interface)
template_specification['displayCreateLocalConnectivityBtn'] = True
template_specification['loadExistentEntityUrl'] = LOAD_EXISTING_URL
template_specification['resetToDefaultUrl'] = RELOAD_DEFAULT_PAGE_URL
template_specification['existentEntitiesInputList'] = left_side_interface
template_specification['submit_parameters_url'] = '/spatial/localconnectivity/create_local_connectivity'
template_specification['equationViewerUrl'] = '/spatial/localconnectivity/get_equation_chart'
template_specification['equationsPrefixes'] = json.dumps(self.plotted_equations_prefixes)
template_specification['next_step_url'] = '/spatial/localconnectivity/step_2'
msg, msg_type = common.get_message_from_session()
template_specification['displayedMessage'] = msg
return self.fill_default_attributes(template_specification)
示例8: reset_burst
def reset_burst(self):
"""
Called when click on "New Burst" entry happens from UI.
This will generate an empty new Burst Configuration.
"""
common.remove_from_session(common.KEY_CACHED_SIMULATOR_TREE)
new_burst = self.burst_service.new_burst_configuration(common.get_current_project().id)
common.add2session(common.KEY_BURST_CONFIG, new_burst)
示例9: copy_burst
def copy_burst(self, burst_id):
"""
When currently selected entry is a valid Burst, create a clone of that Burst.
"""
common.remove_from_session(common.KEY_CACHED_SIMULATOR_TREE)
base_burst = self.burst_service.load_burst(burst_id)[0]
if (base_burst is None) or (base_burst.id is None):
return self.reset_burst()
common.add2session(common.KEY_BURST_CONFIG, base_burst.clone())
return base_burst.name
示例10: cached_simulator_input_tree
def cached_simulator_input_tree(self):
"""
Cache Simulator's input tree, for performance issues.
Anyway, without restart, the introspected tree will not be different on multiple executions.
:returns: Simulator's Input Tree (copy from cache or just loaded)
"""
cached_simulator_tree = common.get_from_session(common.KEY_CACHED_SIMULATOR_TREE)
if cached_simulator_tree is None:
cached_simulator_tree = self.flow_service.prepare_adapter(common.get_current_project().id,
self.cached_simulator_algorithm)
common.add2session(common.KEY_CACHED_SIMULATOR_TREE, cached_simulator_tree)
return copy.deepcopy(cached_simulator_tree)
示例11: step_1_submit
def step_1_submit(self, next_step, do_reset=0, **kwargs):
"""
Any submit from the first step should be handled here. Update the context then
go to the next step as required. In case a reset is needed create a clear context.
"""
if int(do_reset) == 1:
new_context = RegionStimulusContext()
common.add2session(KEY_REGION_CONTEXT, new_context)
context = common.get_from_session(KEY_REGION_CONTEXT)
if kwargs.get(CONNECTIVITY_PARAMETER) != context.get_session_connectivity():
context.set_weights([])
context.equation_kwargs = kwargs
return self.do_step(next_step)
示例12: step_1_submit
def step_1_submit(self, next_step, do_reset=0, **kwargs):
"""
Any submit from the first step should be handled here. Update the context then
go to the next step as required. In case a reset is needed create a clear context.
"""
if int(do_reset) == 1:
new_context = SurfaceStimulusContext()
common.add2session(KEY_SURFACE_CONTEXT, new_context)
context = common.get_from_session(KEY_SURFACE_CONTEXT)
if kwargs.get(SURFACE_PARAMETER) != context.get_session_surface():
context.set_focal_points('[]')
context.update_eq_kwargs(kwargs)
return self.do_step(next_step)
示例13: __get_operations_filters
def __get_operations_filters(self):
"""
Filters for VIEW_ALL_OPERATIONS page.
Get from session currently selected filters, or build a new set of filters.
"""
session_filtes = common.get_from_session(self.KEY_OPERATION_FILTERS)
if session_filtes:
return session_filtes
else:
sim_group = self.flow_service.get_algorithm_by_module_and_class(SIMULATOR_MODULE, SIMULATOR_CLASS)[1]
new_filters = StaticFiltersFactory.build_operations_filters(sim_group, common.get_logged_user().id)
common.add2session(self.KEY_OPERATION_FILTERS, new_filters)
return new_filters
示例14: apply_equation
def apply_equation(self, **kwargs):
"""
Applies an equations for computing a model parameter.
"""
submitted_data = collapse_params(kwargs, ['model_param'])
model_param, equation = self._compute_equation(submitted_data)
context_model_parameters = common.get_from_session(KEY_CONTEXT_MPS)
context_model_parameters.apply_equation(model_param, equation)
common.add2session(KEY_CONTEXT_MPS, context_model_parameters)
template_specification = self.get_surface_model_parameters_data(model_param)
template_specification = self._add_entra_equation_entries(template_specification,
kwargs['min_x'], kwargs['max_x'])
template_specification['equationViewerUrl'] = '/spatial/modelparameters/surface/get_equation_chart'
template_specification['equationsPrefixes'] = json.dumps(self.plotted_equations_prefixes)
return self.fill_default_attributes(template_specification)
示例15: reload_burst_operation
def reload_burst_operation(self, operation_id, is_group, **_):
"""
Find out from which burst was this operation launched. Set that burst as the selected one and
redirect to the burst page.
"""
is_group = int(is_group)
if not is_group:
operation = self.flow_service.load_operation(int(operation_id))
else:
op_group = ProjectService.get_operation_group_by_id(operation_id)
first_op = ProjectService.get_operations_in_group(op_group)[0]
operation = self.flow_service.load_operation(int(first_op.id))
operation.burst.prepare_after_load()
common.add2session(common.KEY_BURST_CONFIG, operation.burst)
raise cherrypy.HTTPRedirect("/burst/")