def invokeadaptermethod(self, adapter_id, method_name, **data): """ Public web method, to be used when invoking specific methods from external Adapters/Algorithms. """ algo_group = self.flow_service.get_algo_group_by_identifier(adapter_id) try: adapter_instance = self.flow_service.build_adapter_instance( algo_group) result = self.flow_service.fire_operation( adapter_instance, common.get_logged_user(), common.get_current_project().id, method_name, **data) common.set_info_message("Submit OK!") if isinstance(adapter_instance, ABCDisplayer) and isinstance( result, dict): common.pop_message_from_session() result[ABCDisplayer.KEY_IS_ADAPTER] = True result[common.KEY_DISPLAY_MENU] = True result[common.KEY_OPERATION_ID] = adapter_instance.operation_id result[common.KEY_ADAPTER] = adapter_id if KEY_CONTROLLS not in result: result[KEY_CONTROLLS] = None self._populate_section(algo_group, result) return self.fill_default_attributes(result, algo_group.displayname) except OperationException, excep: common.set_warning_message('Problem when submitting data!') self.logger.error( "Invalid method, or wrong parameters when invoking external method on post!" ) self.logger.exception(excep)
def invokeadaptermethod(self, adapter_id, method_name, **data): """ Public web method, to be used when invoking specific methods from external Adapters/Algorithms. """ algo_group = self.flow_service.get_algo_group_by_identifier(adapter_id) try: adapter_instance = self.flow_service.build_adapter_instance(algo_group) result = self.flow_service.fire_operation(adapter_instance, common.get_logged_user(), common.get_current_project().id, method_name, **data) common.set_info_message("Submit OK!") if isinstance(adapter_instance, ABCDisplayer) and isinstance(result, dict): common.pop_message_from_session() result[ABCDisplayer.KEY_IS_ADAPTER] = True result[common.KEY_DISPLAY_MENU] = True result[common.KEY_OPERATION_ID] = adapter_instance.operation_id result[common.KEY_ADAPTER] = adapter_id if KEY_CONTROLLS not in result: result[KEY_CONTROLLS] = None self._populate_section(algo_group, result) return self.fill_default_attributes(result, algo_group.displayname) except OperationException, excep: common.set_warning_message('Problem when submitting data!') self.logger.error("Invalid method, or wrong parameters when invoking external method on post!") self.logger.exception(excep)
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)
def recoverpassword(self, cancel=False, **data): """ This form should reset a password for a given userName/email and send a notification message to that email. """ template_specification = dict(mainContent="recover_password", title="Recover password", data=data) redirect = False if cherrypy.request.method == 'POST': if cancel: raise cherrypy.HTTPRedirect('/user') form = RecoveryForm() try: data = form.to_python(data) okmessage = self.user_service.reset_password(**data) common.set_info_message(okmessage) redirect = True except formencode.Invalid as excep: template_specification[common.KEY_ERRORS] = excep.unpack_errors() redirect = False except UsernameException as excep1: self.logger.exception("Could not reset password!") common.set_error_message(excep1.message) redirect = False if redirect: #Redirect to login page, with some success message to display raise cherrypy.HTTPRedirect('/user') else: #Stay on the same page return self.fill_default_attributes(template_specification)
def create_new(self, cancel=False, **data): """ Create new user with data submitted from UI. """ if cancel: raise cherrypy.HTTPRedirect('/user/usermanagement') template_specification = dict(mainContent="create_new", title="Create New", data=data) redirect = False if cherrypy.request.method == 'POST': try: data[KEY_COMMENT] = "Created by administrator." # User is created by administrator, should be validated automatically, and credentials # should be sent to user by email. email_msg = """A TVB account was just created for you by an administrator. \n Your credentials are username=%s, password=%s. \n You can log in here: %s. """ % (data[KEY_USERNAME], data[KEY_PASSWORD], TvbProfile.current.web.BASE_URL) self._create_user(email_msg=email_msg, validated=True, **data) common.set_info_message("New user created successfully.") redirect = True except formencode.Invalid as excep: template_specification[common.KEY_ERRORS] = excep.unpack_errors() except Exception as excep: self.logger.exception(excep) common.set_error_message("We are very sorry, but we could not create your user. Most probably is " "because it was impossible to sent emails. Please try again later...") if redirect: raise cherrypy.HTTPRedirect('/user/usermanagement') else: return self.fill_default_attributes(template_specification)
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!!")
def register(self, cancel=False, **data): """ This register form send an e-mail to the user and to the site admin. """ template_specification = dict(mainContent="user/register", title="Register", data=data) redirect = False if cherrypy.request.method == 'POST': if cancel: raise cherrypy.HTTPRedirect('/user') try: okmessage = self._create_user(**data) common.set_info_message(okmessage) redirect = True except formencode.Invalid as excep: template_specification[ common.KEY_ERRORS] = excep.unpack_errors() redirect = False except Exception as excep1: self.logger.error("Could not create user:"******"username"]) self.logger.exception(excep1) common.set_error_message( "We are very sorry, but we could not create your user. Most probably is " "because it was impossible to sent emails. Please try again later..." ) redirect = False if redirect: # Redirect to login page, with some success message to display raise cherrypy.HTTPRedirect('/user') else: # Stay on the same page return self.fill_default_attributes(template_specification)
def index(self, **data): """ Login page (with or without messages). """ template_specification = dict(mainContent="user/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)
def recoverpassword(self, cancel=False, **data): """ This form should reset a password for a given userName/email and send a notification message to that email. """ template_specification = dict(mainContent="user/recover_password", title="Recover password", data=data) redirect = False if cherrypy.request.method == 'POST': if cancel: raise cherrypy.HTTPRedirect('/user') form = RecoveryForm() try: data = form.to_python(data) okmessage = self.user_service.reset_password(**data) common.set_info_message(okmessage) redirect = True except formencode.Invalid as excep: template_specification[ common.KEY_ERRORS] = excep.unpack_errors() redirect = False except UsernameException as excep1: self.logger.exception("Could not reset password!") common.set_error_message(excep1.message) redirect = False if redirect: # Redirect to login page, with some success message to display raise cherrypy.HTTPRedirect('/user') else: # Stay on the same page return self.fill_default_attributes(template_specification)
def create_new(self, cancel=False, **data): """ Create new user with data submitted from UI. """ if cancel: raise cherrypy.HTTPRedirect('/user/usermanagement') template_specification = dict(mainContent="create_new", title="Create New", data=data) redirect = False if cherrypy.request.method == 'POST': try: data[KEY_COMMENT] = "Created by administrator." # User is created by administrator, should be validated automatically, and credentials # should be sent to user by email. email_msg = """A TVB account was just created for you by an administrator. Your credentials are username=%s, password=%s.""" % ( data[KEY_USERNAME], data[KEY_PASSWORD]) self._create_user(email_msg=email_msg, validated=True, **data) common.set_info_message("New user created successfully.") redirect = True except formencode.Invalid, excep: template_specification[ common.KEY_ERRORS] = excep.unpack_errors() except Exception, excep: self.logger.exception(excep) common.set_error_message( "We are very sorry, but we could not create your user. Most probably is " "because it was impossible to sent emails. Please try again later..." )
def _mark_selected(self, project): """ Set the project passed as parameter as the selected project. """ previous_project = common.get_current_project() # Update project stored in selection, with latest Project entity from DB. members = self.user_service.get_users_for_project("", project.id)[1] project.members = members if previous_project is None or previous_project.id != project.id: # Clean Burst selection from session in case of a different project. SimulatorContext().clean_project_data_from_session() # Store in DB new project selection user = common.get_from_session(common.KEY_USER) if user is not None: self.user_service.save_project_to_user(user.id, project.id) # Display info message about project change self.logger.debug("Selected project is now " + project.name) common.set_info_message("Your current working project is: " + str(project.name)) linked_dt = self.project_service.get_linked_datatypes_storage_path( project) storage_interface = StorageInterface() storage_interface.set_project_active(project, linked_dt) if previous_project is not None: storage_interface.set_project_inactive(previous_project) # Add the project entity to session every time, as it might be changed (e.g. after edit) common.add2session(common.KEY_PROJECT, project)
def register(self, cancel=False, **data): """ This register form send an e-mail to the user and to the site admin. """ template_specification = dict(mainContent="register", title="Register", data=data) redirect = False if cherrypy.request.method == 'POST': if cancel: raise cherrypy.HTTPRedirect('/user') try: okmessage = self._create_user(**data) common.set_info_message(okmessage) redirect = True except formencode.Invalid as excep: template_specification[common.KEY_ERRORS] = excep.unpack_errors() redirect = False except Exception as excep1: self.logger.error("Could not create user:"******"username"]) self.logger.exception(excep1) common.set_error_message("We are very sorry, but we could not create your user. Most probably is " "because it was impossible to sent emails. Please try again later...") redirect = False if redirect: #Redirect to login page, with some success message to display raise cherrypy.HTTPRedirect('/user') else: #Stay on the same page return self.fill_default_attributes(template_specification)
def validate(self, name): """ A link to this page will be sent to the administrator to validate the registration of each user. """ success = self.user_service.validate_user(name) if not success: common.set_error_message("Problem validating user:"******"!! Please check logs.") self.logger.error("Problem validating user " + name) else: common.set_info_message("User Validated successfully and notification email sent!") raise cherrypy.HTTPRedirect('/tvb')
def index(self, **data): """ Login page (with or without messages). """ template_specification = dict(mainContent="user/login", title="Login", data=data) self._set_base_url() if cherrypy.request.method == 'POST': keycloak_login = TvbProfile.current.KEYCLOAK_LOGIN_ENABLED form = LoginForm() if not keycloak_login else KeycloakLoginForm() try: data = form.to_python(data) if keycloak_login: auth_token = data[KEY_AUTH_TOKEN] kc_user_info = AuthorizationManager( TvbProfile.current.KEYCLOAK_WEB_CONFIG ).get_keycloak_instance().userinfo(auth_token) user = self.user_service.get_external_db_user(kc_user_info) else: 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 ' + user.display_name) self.logger.debug("User " + 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') elif not keycloak_login: common.set_error_message( 'Wrong username/password, or user not yet validated...' ) self.logger.debug("Wrong username " + username + " !!!") else: common.set_error_message( 'Your account is not validated. Please contact us at [email protected] for more details' ) self.logger.debug("Invalidated account") template_specification[common.KEY_ERRORS] = { 'invalid_user': True } except formencode.Invalid as excep: template_specification[ common.KEY_ERRORS] = excep.unpack_errors() return self.fill_default_attributes(template_specification)
def _update_figure(self, figure_id, **data): """ Updates the figure details to the given data. """ try: data = EditPreview().to_python(data) self.figure_service.edit_result_figure(figure_id, **data) common.set_info_message('Figure details updated successfully.') return True except formencode.Invalid as excep: self.logger.debug(excep) common.set_error_message(excep.message) return False
def logout(self): """ Logging out user and clean session """ user = common.remove_from_session(common.KEY_USER) if user is not None: self.logger.debug("User " + user.username + " is just logging out!") common.clean_project_data_from_session() common.set_info_message("Thank you for using The Virtual Brain!") common.expire_session() raise cherrypy.HTTPRedirect("/user")
def _update_figure(self, figure_id, **data): """ Updates the figure details to the given data. """ try: data = EditPreview().to_python(data) self.figure_service.edit_result_figure(figure_id, **data) common.set_info_message('Figure details updated successfully.') return True except formencode.Invalid, excep: self.logger.debug(excep) common.set_error_message(excep.message) return False
def logout(self): """ Logging out user and clean session """ user = common.remove_from_session(common.KEY_USER) if user is not None: self.logger.debug("User " + user.username + " is just logging out!") common.remove_from_session(common.KEY_PROJECT) common.remove_from_session(common.KEY_BURST_CONFIG) common.remove_from_session(common.KEY_CACHED_SIMULATOR_TREE) common.set_info_message("Thank you for using The Virtual Brain!") common.expire_session() raise cherrypy.HTTPRedirect("/user")
def logout(self): """ Logging out user and clean session """ user = common.remove_from_session(common.KEY_USER) if user is not None: self.logger.debug("User " + user.username + " is just logging out!") current_project = common.get_current_project() if current_project is not None and encryption_handler.encryption_enabled(): encryption_handler.set_project_inactive(current_project) SimulatorContext().clean_project_data_from_session() common.set_info_message("Thank you for using The Virtual Brain!") common.expire_session() raise cherrypy.HTTPRedirect("/user")
def do_step(self, step_idx, from_step=None): """ Go to the step given by :param step_idx. In case the next step is the create one (3), we want to remain on the same step as before so that is handled differently depending on the :param from_step. """ if int(step_idx) == 1: return self.step_1() if int(step_idx) == 2: return self.step_2() if int(step_idx) == 3: if self.create_stimulus(): common.set_info_message("Successfully created a new stimulus.") if from_step == 2: return self.step_2() return self.step_1()
def get_template_from_context(self): """ Return the parameters for the local connectivity in case one is stored in context. Load the entity and use it to populate the defaults from the interface accordingly. """ context = common.get_from_session(KEY_LCONN_CONTEXT) selected_local_conn = ABCAdapter.load_entity_by_gid( context.selected_entity) cutoff = selected_local_conn.cutoff equation = selected_local_conn.equation surface = selected_local_conn.surface default_dict = {'surface': surface.gid, 'cutoff': cutoff} if equation is not None: equation_type = equation.__class__.__name__ default_dict['equation'] = equation_type for param in equation.parameters: prepared_name = 'equation_parameters_option_' + str( equation_type) prepared_name = prepared_name + '_parameters_parameters_' + str( param) default_dict[prepared_name] = equation.parameters[param] else: msg = "There is no equation specified for this local connectivity. " msg += "The default equation is displayed into the spatial field." self.logger.warning(msg) common.set_info_message(msg) default_dict[ DataTypeMetaData.KEY_TAG_1] = selected_local_conn.user_tag_1 input_list = self.get_creator_and_interface(LOCAL_CONN_CREATOR_MODULE, LOCAL_CONN_CREATOR_CLASS, LocalConnectivity(), lock_midpoint_for_eq=[1 ])[1] input_list = self._add_extra_fields_to_interface(input_list) input_list = InputTreeManager.fill_defaults(input_list, default_dict) template_specification = { 'inputList': input_list, common.KEY_PARAMETERS_CONFIG: False, 'equationViewerUrl': '/spatial/localconnectivity/get_equation_chart', 'equationsPrefixes': json.dumps(self.plotted_equations_prefixes) } return template_specification
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="user/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 = hash_password(data[KEY_PASSWORD]) if data.get(KEY_EMAIL): user.email = data[KEY_EMAIL] old_password = None if data.get('old_password'): old_password = hash_password(data['old_password']) 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)
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)
def _mark_selected(self, project): """ Set the project passed as parameter as the selected project. """ previous_project = common.get_current_project() ### Update project stored in selection, with latest Project entity from DB. members = self.user_service.get_users_for_project("", project.id)[1] project.members = members common.remove_from_session(common.KEY_CACHED_SIMULATOR_TREE) common.add2session(common.KEY_PROJECT, project) if previous_project is None or previous_project.id != project.id: ### Clean Burst selection from session in case of a different project. common.remove_from_session(common.KEY_BURST_CONFIG) ### Store in DB new project selection user = common.get_from_session(common.KEY_USER) if user is not None: self.user_service.save_project_to_user(user.id, project.id) ### Display info message about project change self.logger.debug("Selected project is now " + project.name) common.set_info_message("Your current working project is: " + str(project.name))
def get_template_from_context(self): """ Return the parameters for the local connectivity in case one is stored in context. Load the entity and use it to populate the defaults from the interface accordingly. """ context = common.get_from_session(KEY_LCONN_CONTEXT) selected_local_conn = ABCAdapter.load_entity_by_gid(context.selected_entity) cutoff = selected_local_conn.cutoff equation = selected_local_conn.equation surface = selected_local_conn.surface default_dict = {"surface": surface.gid, "cutoff": cutoff} if equation is not None: equation_type = equation.__class__.__name__ default_dict["equation"] = equation_type for param in equation.parameters: prepared_name = "equation_parameters_option_" + str(equation_type) prepared_name = prepared_name + "_parameters_parameters_" + str(param) default_dict[prepared_name] = equation.parameters[param] else: msg = "There is no equation specified for this local connectivity. " msg += "The default equation is displayed into the spatial field." self.logger.warning(msg) common.set_info_message(msg) default_dict[DataTypeMetaData.KEY_TAG_1] = selected_local_conn.user_tag_1 input_list = self.get_creator_and_interface( LOCAL_CONN_CREATOR_MODULE, LOCAL_CONN_CREATOR_CLASS, LocalConnectivity(), lock_midpoint_for_eq=[1] )[1] input_list = self._add_extra_fields_to_interface(input_list) input_list = ABCAdapter.fill_defaults(input_list, default_dict) template_specification = { "inputList": input_list, common.KEY_PARAMETERS_CONFIG: False, "equationViewerUrl": "/spatial/localconnectivity/get_equation_chart", "equationsPrefixes": json.dumps(self.plotted_equations_prefixes), } return template_specification
def recoverpassword(self, cancel=False, **data): """ This form should reset a password for a given userName/email and send a notification message to that email. """ template_specification = dict(mainContent="recover_password", title="Recover password", data=data) redirect = False if cherrypy.request.method == "POST": if cancel: raise cherrypy.HTTPRedirect("/user") form = RecoveryForm() try: data = form.to_python(data) okmessage = self.user_service.reset_password(**data) common.set_info_message(okmessage) redirect = True except formencode.Invalid, excep: template_specification[common.KEY_ERRORS] = excep.unpack_errors() redirect = False except UsernameException, excep1: self.logger.exception("Could not reset password!") common.set_error_message(excep1.message) redirect = False
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!!")
def register(self, cancel=False, **data): """ This register form send an e-mail to the user and to the site admin. """ template_specification = dict(mainContent="register", title="Register", data=data) redirect = False if cherrypy.request.method == "POST": if cancel: raise cherrypy.HTTPRedirect("/user") try: okmessage = self._create_user(**data) common.set_info_message(okmessage) redirect = True except formencode.Invalid, excep: template_specification[common.KEY_ERRORS] = excep.unpack_errors() redirect = False except Exception, excep1: self.logger.error("Could not create user:"******"username"]) self.logger.exception(excep1) common.set_error_message( "We are very sorry, but we could not create your user. Most probably is " "because it was impossible to sent emails. Please try again later..." ) redirect = False
def editresultfigures(self, remove_figure=False, rename_session=False, remove_session=False, **data): """ This method knows how to handle the following actions: remove figure, update figure, remove session and update session. """ project = common.get_current_project() user = common.get_logged_user() redirect_url = '/project/figure/displayresultfigures' if "selected_session" in data and data["selected_session"] is not None and len(data["selected_session"]): redirect_url += '/' + data["selected_session"] del data["selected_session"] figure_id = None if "figure_id" in data: figure_id = data["figure_id"] del data["figure_id"] if cherrypy.request.method == 'POST' and rename_session: successfully_updated = True if "old_session_name" in data and "new_session_name" in data: figures_dict, _ = self.figure_service.retrieve_result_figures(project, user, data["old_session_name"]) for _key, value in figures_dict.iteritems(): for figure in value: new_data = {"name": figure.name, "session_name": data["new_session_name"]} success = self._update_figure(figure.id, **new_data) if not success: successfully_updated = False if successfully_updated: common.set_info_message("The session was successfully updated!") else: common.set_error_message("The session was not successfully updated! " "There could be some figures that still refer to the old session.") elif cherrypy.request.method == 'POST' and remove_session: successfully_removed = True if "old_session_name" in data: figures_dict, _ = self.figure_service.retrieve_result_figures(project, user, data["old_session_name"]) for _key, value in figures_dict.iteritems(): for figure in value: success = self.figure_service.remove_result_figure(figure.id) if not success: successfully_removed = False if successfully_removed: common.set_info_message("The session was removed successfully!") else: common.set_error_message("The session was not entirely removed!") elif cherrypy.request.method == 'POST' and remove_figure and figure_id is not None: success = self.figure_service.remove_result_figure(figure_id) if success: common.set_info_message("Figure removed successfully!") else: common.set_error_message("Figure could not be removed!") elif figure_id is not None: self._update_figure(figure_id, **data) raise cherrypy.HTTPRedirect(redirect_url)
def editresultfigures(self, remove_figure=False, rename_session=False, remove_session=False, **data): """ This method knows how to handle the following actions: remove figure, update figure, remove session and update session. """ project = common.get_current_project() user = common.get_logged_user() redirect_url = '/project/figure/displayresultfigures' if "selected_session" in data and data["selected_session"] is not None and len(data["selected_session"]): redirect_url += '/' + data["selected_session"] del data["selected_session"] figure_id = None if "figure_id" in data: figure_id = data["figure_id"] del data["figure_id"] if cherrypy.request.method == 'POST' and rename_session: successfully_updated = True if "old_session_name" in data and "new_session_name" in data: figures_dict, _ = self.figure_service.retrieve_result_figures(project, user, data["old_session_name"]) for _key, value in figures_dict.items(): for figure in value: new_data = {"name": figure.name, "session_name": data["new_session_name"]} success = self._update_figure(figure.id, **new_data) if not success: successfully_updated = False if successfully_updated: common.set_info_message("The session was successfully updated!") else: common.set_error_message("The session was not successfully updated! " "There could be some figures that still refer to the old session.") elif cherrypy.request.method == 'POST' and remove_session: successfully_removed = True if "old_session_name" in data: figures_dict, _ = self.figure_service.retrieve_result_figures(project, user, data["old_session_name"]) for _key, value in figures_dict.items(): for figure in value: success = self.figure_service.remove_result_figure(figure.id) if not success: successfully_removed = False if successfully_removed: common.set_info_message("The session was removed successfully!") else: common.set_error_message("The session was not entirely removed!") elif cherrypy.request.method == 'POST' and remove_figure and figure_id is not None: success = self.figure_service.remove_result_figure(figure_id) if success: common.set_info_message("Figure removed successfully!") else: common.set_error_message("Figure could not be removed!") elif figure_id is not None: self._update_figure(figure_id, **data) raise cherrypy.HTTPRedirect(redirect_url)