• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python common.add2session函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tvb.interfaces.web.controllers.common.add2session函数的典型用法代码示例。如果您正苦于以下问题:Python add2session函数的具体用法?Python add2session怎么用?Python add2session使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了add2session函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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/')
开发者ID:maedoc,项目名称:tvb-framework,代码行数:25,代码来源:burst_controller.py


示例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!!")
开发者ID:sdiazpier,项目名称:tvb-framework,代码行数:33,代码来源:users_controller.py


示例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/")
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:27,代码来源:surface_model_parameters_controller.py


示例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)
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:25,代码来源:settings_controller.py


示例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"
开发者ID:maedoc,项目名称:tvb-framework,代码行数:30,代码来源:burst_controller.py


示例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)
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:28,代码来源:users_controller.py


示例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)
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:30,代码来源:local_connectivity_controller.py


示例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)
开发者ID:maedoc,项目名称:tvb-framework,代码行数:8,代码来源:burst_controller.py


示例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
开发者ID:maedoc,项目名称:tvb-framework,代码行数:10,代码来源:burst_controller.py


示例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)
开发者ID:maedoc,项目名称:tvb-framework,代码行数:12,代码来源:burst_controller.py


示例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)
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:13,代码来源:region_stimulus_controller.py


示例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)
开发者ID:amitsaroj001,项目名称:tvb-framework,代码行数:13,代码来源:surface_stimulus_controller.py


示例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
开发者ID:unimauro,项目名称:tvb-framework,代码行数:14,代码来源:project_controller.py


示例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)
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:15,代码来源:surface_model_parameters_controller.py


示例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/")
开发者ID:transpersonify,项目名称:tvb-framework,代码行数:15,代码来源:flow_controller.py


示例16: get_visualizers_for_operation_id

 def get_visualizers_for_operation_id(self, op_id, width, height):
     """
     Method called from parameters exploration page in case a burst with a range of parameters
     for the simulator was launched. 
     :param op_id: the selected operation id from the parameter space exploration.
     :param width: the width of the right side display
     :param height: the height of the right side display
     
     Given these parameters first get the workflow to which op_id belongs, then load the portlets
     from that workflow as the current burst configuration. Width and height are used to get the
     proper sizes for the visualization iFrames. 
     """
     burst_config = common.get_from_session(common.KEY_BURST_CONFIG)
     burst_config = self.burst_service.load_tab_configuration(burst_config, op_id)
     common.add2session(common.KEY_BURST_CONFIG, burst_config)
     return self.load_configured_visualizers(width, height)
开发者ID:maedoc,项目名称:tvb-framework,代码行数:16,代码来源:burst_controller.py


示例17: update_operations_count

 def update_operations_count(self):
     """
     If a project is selected, update Operation Numbers in call-out.
     """
     project = common.get_current_project()
     if project is not None:
         fns, sta, err, canceled, pending = self.flow_service.get_operation_numbers(project.id)
         project.operations_finished = fns
         project.operations_started = sta
         project.operations_error = err
         project.operations_canceled = canceled
         project.operations_pending = pending
         common.add2session(common.KEY_PROJECT, project)
         
                 
         
         
         
开发者ID:amitsaroj001,项目名称:tvb-framework,代码行数:13,代码来源:base_controller.py


示例18: display_surface

    def display_surface(surface_gid):
        """
        Generates the HTML for displaying the surface with the given ID.
        """
        surface = ABCAdapter.load_entity_by_gid(surface_gid)
        common.add2session(PARAM_SURFACE, surface_gid)
        url_vertices_pick, url_normals_pick, url_triangles_pick = surface.get_urls_for_pick_rendering()
        url_vertices, url_normals, _, url_triangles = surface.get_urls_for_rendering()

        return {
            'urlVerticesPick': json.dumps(url_vertices_pick),
            'urlTrianglesPick': json.dumps(url_triangles_pick),
            'urlNormalsPick': json.dumps(url_normals_pick),
            'urlVertices': json.dumps(url_vertices),
            'urlTriangles': json.dumps(url_triangles),
            'urlNormals': json.dumps(url_normals),
            'brainCenter': json.dumps(surface.center())
        }
开发者ID:amitsaroj001,项目名称:tvb-framework,代码行数:18,代码来源:base_spatio_temporal_controller.py


示例19: index

    def index(self):
        """Get on burst main page"""
        # todo : reuse load_burst here for consistency.
        template_specification = dict(mainContent="burst/main_burst", title="Simulation Cockpit",
                                      baseUrl=TvbProfile.current.web.BASE_URL,
                                      includedResources='project/included_resources')
        portlets_list = self.burst_service.get_available_portlets()
        session_stored_burst = common.get_from_session(common.KEY_BURST_CONFIG)
        if session_stored_burst is None or session_stored_burst.id is None:
            if session_stored_burst is None:
                session_stored_burst = self.burst_service.new_burst_configuration(common.get_current_project().id)
                common.add2session(common.KEY_BURST_CONFIG, session_stored_burst)

            adapter_interface = self.cached_simulator_input_tree
            if session_stored_burst is not None:
                current_data = session_stored_burst.get_all_simulator_values()[0]
                adapter_interface = ABCAdapter.fill_defaults(adapter_interface, current_data, True)
                ### Add simulator tree to session to be available in filters
                self.context.add_adapter_to_session(self.cached_simulator_algo_group, adapter_interface, current_data)
            template_specification['inputList'] = adapter_interface

        selected_portlets = session_stored_burst.update_selected_portlets()
        template_specification['burst_list'] = self.burst_service.get_available_bursts(common.get_current_project().id)
        template_specification['portletList'] = portlets_list
        template_specification['selectedPortlets'] = json.dumps(selected_portlets)
        template_specification['draw_hidden_ranges'] = True
        template_specification['burstConfig'] = session_stored_burst

        ### Prepare PSE available metrics
        ### We put here all available algorithms, because the metrics select area is a generic one, 
        ### and not loaded with every Burst Group change in history.
        algo_group = self.flow_service.get_algorithm_by_module_and_class(MEASURE_METRICS_MODULE,
                                                                         MEASURE_METRICS_CLASS)[1]
        adapter_instance = ABCAdapter.build_adapter(algo_group)
        if adapter_instance is not None and hasattr(adapter_instance, 'available_algorithms'):
            template_specification['available_metrics'] = [metric_name for metric_name
                                                           in adapter_instance.available_algorithms.keys()]
        else:
            template_specification['available_metrics'] = []

        template_specification[common.KEY_PARAMETERS_CONFIG] = False
        template_specification[common.KEY_SECTION] = 'burst'
        return self.fill_default_attributes(template_specification)
开发者ID:amitsaroj001,项目名称:tvb-framework,代码行数:43,代码来源:burst_controller.py


示例20: 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 as excep:
                template_specification[common.KEY_ERRORS] = excep.unpack_errors()
            except UsernameException as 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!!")
        else:
            #Update session user since disk size might have changed from last time to profile.
            user = self.user_service.get_user_by_id(user.id)
            common.add2session(common.KEY_USER, user)

        template_specification['user_used_disk_human'] = format_bytes_human(
            self.user_service.compute_user_generated_disk_size(user.id))
        return self.fill_default_attributes(template_specification)
开发者ID:LauHoiYanGladys,项目名称:tvb-framework,代码行数:41,代码来源:users_controller.py



注:本文中的tvb.interfaces.web.controllers.common.add2session函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python common.get_current_project函数代码示例发布时间:2022-05-27
下一篇:
Python base_controller.get_from_session函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap