def go(id, uid, ids, datas, context): cr = pooler.get_db(db).cursor() import traceback import sys try: obj = netsvc.LocalService('report.'+object) (result, format) = obj.create(cr, uid, ids, datas, context) if not result: tb = sys.exc_info() self._reports[id]['exception'] = ExceptionWithTraceback('RML is not available at specified location or not enough data to print!', tb) self._reports[id]['result'] = result self._reports[id]['format'] = format self._reports[id]['state'] = True except Exception, exception: tb = sys.exc_info() tb_s = "".join(traceback.format_exception(*tb)) logger = netsvc.Logger() logger.notifyChannel('web-services', netsvc.LOG_ERROR, 'Exception: %s\n%s' % (str(exception), tb_s)) if hasattr(exception, 'name') and hasattr(exception, 'value'): self._reports[id]['exception'] = ExceptionWithTraceback(tools.ustr(exception.name), tools.ustr(exception.value)) else: self._reports[id]['exception'] = ExceptionWithTraceback(tools.exception_to_unicode(exception), tb) self._reports[id]['state'] = True
def exp_render_report(db, uid, object, ids, datas=None, context=None): if not datas: datas={} if not context: context={} self_id_protect.acquire() global self_id self_id += 1 id = self_id self_id_protect.release() self_reports[id] = {'uid': uid, 'result': False, 'state': False, 'exception': None} cr = openerp.registry(db).cursor() try: result, format = openerp.report.render_report(cr, uid, ids, object, datas, context) if not result: tb = sys.exc_info() self_reports[id]['exception'] = openerp.exceptions.DeferredException('RML is not available at specified location or not enough data to print!', tb) self_reports[id]['result'] = result self_reports[id]['format'] = format self_reports[id]['state'] = True except Exception, exception: _logger.exception('Exception: %s\n', exception) if hasattr(exception, 'name') and hasattr(exception, 'value'): self_reports[id]['exception'] = openerp.exceptions.DeferredException(tools.ustr(exception.name), tools.ustr(exception.value)) else: tb = sys.exc_info() self_reports[id]['exception'] = openerp.exceptions.DeferredException(tools.exception_to_unicode(exception), tb) self_reports[id]['state'] = True
def go(id, uid, ids, datas, context): cr = pooler.get_db(db).cursor() try: obj = netsvc.LocalService("report." + object) (result, format) = obj.create(cr, uid, ids, datas, context) if not result: tb = sys.exc_info() self._reports[id]["exception"] = openerp.exceptions.DeferredException( "RML is not available at specified location or not enough data to print!", tb ) self._reports[id]["result"] = result self._reports[id]["format"] = format self._reports[id]["state"] = True except Exception, exception: _logger.exception("Exception: %s\n", exception) if hasattr(exception, "name") and hasattr(exception, "value"): self._reports[id]["exception"] = openerp.exceptions.DeferredException( tools.ustr(exception.name), tools.ustr(exception.value) ) else: tb = sys.exc_info() self._reports[id]["exception"] = openerp.exceptions.DeferredException( tools.exception_to_unicode(exception), tb ) self._reports[id]["state"] = True
def import_zipfile(self, cr, uid, module_file, force=False, context=None): if not module_file: raise Exception("No file sent.") if not zipfile.is_zipfile(module_file): raise UserError(_('File is not a zip file!')) success = [] errors = dict() module_names = [] with zipfile.ZipFile(module_file, "r") as z: for zf in z.filelist: if zf.file_size > MAX_FILE_SIZE: msg = _("File '%s' exceed maximum allowed file size") raise UserError(msg % zf.filename) with openerp.tools.osutil.tempdir() as module_dir: z.extractall(module_dir) dirs = [ d for d in os.listdir(module_dir) if os.path.isdir(opj(module_dir, d)) ] for mod_name in dirs: module_names.append(mod_name) try: # assert mod_name.startswith('theme_') path = opj(module_dir, mod_name) self.import_module(cr, uid, mod_name, path, force=force, context=context) success.append(mod_name) except Exception, e: errors[mod_name] = exception_to_unicode(e)
def go(id, uid, ids, datas, context): with openerp.api.Environment.manage(): cr = openerp.registry(db).cursor() try: result, format = openerp.report.render_report(cr, uid, ids, object, datas, context) if not result: tb = sys.exc_info() self_reports[id]["exception"] = openerp.exceptions.DeferredException( "RML is not available at specified location or not enough data to print!", tb ) self_reports[id]["result"] = result self_reports[id]["format"] = format self_reports[id]["state"] = True except Exception, exception: _logger.exception("Exception: %s\n", exception) if hasattr(exception, "name") and hasattr(exception, "value"): self_reports[id]["exception"] = openerp.exceptions.DeferredException( tools.ustr(exception.name), tools.ustr(exception.value) ) else: tb = sys.exc_info() self_reports[id]["exception"] = openerp.exceptions.DeferredException( tools.exception_to_unicode(exception), tb ) self_reports[id]["state"] = True cr.commit() cr.close()
def go(id, uid, ids, datas, context): with openerp.api.Environment.manage(): cr = openerp.registry(db).cursor() try: result, format = openerp.report.render_report( cr, uid, ids, object, datas, context) if not result: tb = sys.exc_info() self_reports[id][ 'exception'] = openerp.exceptions.DeferredException( 'RML is not available at specified location or not enough data to print!', tb) self_reports[id]['result'] = result self_reports[id]['format'] = format self_reports[id]['state'] = True except Exception, exception: _logger.exception('Exception: %s\n', exception) if hasattr(exception, 'name') and hasattr(exception, 'value'): self_reports[id][ 'exception'] = openerp.exceptions.DeferredException( tools.ustr(exception.name), tools.ustr(exception.value)) else: tb = sys.exc_info() self_reports[id][ 'exception'] = openerp.exceptions.DeferredException( tools.exception_to_unicode(exception), tb) self_reports[id]['state'] = True cr.commit() cr.close()
def import_zipfile(self, cr, uid, module_file, force=False, context=None): if not module_file: raise Exception("No file sent.") if not zipfile.is_zipfile(module_file): raise UserError(_('File is not a zip file!')) success = [] errors = dict() module_names = [] with zipfile.ZipFile(module_file, "r") as z: for zf in z.filelist: if zf.file_size > MAX_FILE_SIZE: msg = _("File '%s' exceed maximum allowed file size") raise UserError(msg % zf.filename) with openerp.tools.osutil.tempdir() as module_dir: z.extractall(module_dir) dirs = [d for d in os.listdir(module_dir) if os.path.isdir(opj(module_dir, d))] for mod_name in dirs: module_names.append(mod_name) try: # assert mod_name.startswith('theme_') path = opj(module_dir, mod_name) self.import_module(cr, uid, mod_name, path, force=force, context=context) success.append(mod_name) except Exception, e: _logger.exception('Error while importing module') errors[mod_name] = exception_to_unicode(e)
def go(id, uid, ids, datas, context): cr = pooler.get_db(db).cursor() try: obj = netsvc.LocalService('report.' + object) (result, format) = obj.create(cr, uid, ids, datas, context) if not result: tb = sys.exc_info() self._reports[id][ 'exception'] = openerp.exceptions.DeferredException( 'RML is not available at specified location or not enough data to print!', tb) self._reports[id]['result'] = result self._reports[id]['format'] = format self._reports[id]['state'] = True except Exception, exception: _logger.exception('Exception: %s\n', exception) if hasattr(exception, 'name') and hasattr(exception, 'value'): self._reports[id][ 'exception'] = openerp.exceptions.DeferredException( tools.ustr(exception.name), tools.ustr(exception.value)) else: tb = sys.exc_info() self._reports[id][ 'exception'] = openerp.exceptions.DeferredException( tools.exception_to_unicode(exception), tb) self._reports[id]['state'] = True
def web_login(self, *args, **kw): mode = request.params.get('mode') qcontext = request.params.copy() super_response = None if request.httprequest.method == 'GET' and request.session.uid and request.params.get('redirect'): # Redirect if already logged in and redirect param is present return http.redirect_with_hash(request.params.get('redirect')) if request.httprequest.method != 'POST' or mode not in ('reset', 'signup'): # Default behavior is to try to login, which in reset or signup mode in a non-sense. super_response = super(AuthSignup, self).web_login(*args, **kw) response = webmain.render_bootstrap_template(request.session.db, 'auth_signup.signup', qcontext, lazy=True) if isinstance(super_response, LazyResponse): response.params['values'].update(super_response.params['values']) token = qcontext.get('token', None) token_infos = None if token: try: # retrieve the user info (name, login or email) corresponding to a signup token res_partner = request.registry.get('res.partner') token_infos = res_partner.signup_retrieve_info(request.cr, openerp.SUPERUSER_ID, token) for k, v in token_infos.items(): qcontext.setdefault(k, v) except: qcontext['error'] = _("Invalid signup token") response.params['template'] = 'web.login' return response # retrieve the module config (which features are enabled) for the login page icp = request.registry.get('ir.config_parameter') config = { 'signup': icp.get_param(request.cr, openerp.SUPERUSER_ID, 'auth_signup.allow_uninvited') == 'True', 'reset': icp.get_param(request.cr, openerp.SUPERUSER_ID, 'auth_signup.reset_password') == 'True', } qcontext.update(config) if 'error' in request.params or mode not in ('reset', 'signup') or (not token and not config[mode]): if isinstance(super_response, LazyResponse): super_response.params['values'].update(config) return super_response if request.httprequest.method == 'GET': if token_infos: qcontext.update(token_infos) else: res_users = request.registry.get('res.users') login = request.params.get('login') if mode == 'reset' and not token: try: res_users.reset_password(request.cr, openerp.SUPERUSER_ID, login) qcontext['message'] = _("An email has been sent with credentials to reset your password") response.params['template'] = 'web.login' except Exception, e: qcontext['error'] = exception_to_unicode(e) or _("Could not reset your password") _logger.exception('error when resetting password') else:
def web_login(self, *args, **kw): mode = request.params.get('mode') qcontext = request.params.copy() response = webmain.render_bootstrap_template(request.session.db, 'auth_signup.signup', qcontext, lazy=True) token = qcontext.get('token', None) token_infos = None if token: try: # retrieve the user info (name, login or email) corresponding to a signup token res_partner = request.registry.get('res.partner') token_infos = res_partner.signup_retrieve_info(request.cr, openerp.SUPERUSER_ID, token) for k, v in token_infos.items(): qcontext.setdefault(k, v) except: qcontext['error'] = _("Invalid signup token") response.params['template'] = 'web.login' return response # retrieve the module config (which features are enabled) for the login page icp = request.registry.get('ir.config_parameter') config = { 'signup': icp.get_param(request.cr, openerp.SUPERUSER_ID, 'auth_signup.allow_uninvited') == 'True', 'reset': icp.get_param(request.cr, openerp.SUPERUSER_ID, 'auth_signup.reset_password') == 'True', } qcontext.update(config) if 'error' in qcontext or mode not in ('reset', 'signup') or (not token and not config[mode]): response = super(Home, self).web_login(*args, **kw) if isinstance(response, LazyResponse): response.params['values'].update(config) return response if request.httprequest.method == 'GET': if token_infos: qcontext.update(token_infos) else: res_users = request.registry.get('res.users') login = request.params.get('login') if mode == 'reset' and not token: try: res_users.reset_password(request.cr, openerp.SUPERUSER_ID, login) qcontext['message'] = _("An email has been sent with credentials to reset your password") response.params['template'] = 'web.login' except Exception: qcontext['error'] = _("Could not reset your password") _logger.exception('error when resetting password') else: values = dict((key, qcontext.get(key)) for key in ('login', 'name', 'password')) try: self._signup_with_values(token, values) request.cr.commit() except SignupError, e: qcontext['error'] = exception_to_unicode(e) return super(Home, self).web_login(*args, **kw)
def import_zipfile(self, cr, uid, module_file, force=False, context=None): if not module_file: raise Exception("No file sent.") if not zipfile.is_zipfile(module_file): raise UserError(_('File is not a zip file!')) success = [] errors = dict() module_names = [] with zipfile.ZipFile(module_file, "r") as z: for zf in z.filelist: if zf.file_size > MAX_FILE_SIZE: msg = _("File '%s' exceed maximum allowed file size") raise UserError(msg % zf.filename) with openerp.tools.osutil.tempdir() as module_dir: import openerp.modules as addons try: addons.module.ad_paths.append(module_dir) z.extractall(module_dir) dirs = [ d for d in os.listdir(module_dir) if os.path.isdir(opj(module_dir, d)) ] for mod_name in dirs: module_names.append(mod_name) try: # assert mod_name.startswith('theme_') path = opj(module_dir, mod_name) self.import_module(cr, uid, mod_name, path, force=force, context=context) success.append(mod_name) except Exception, e: _logger.exception('Error while importing module') errors[mod_name] = exception_to_unicode(e) finally: addons.module.ad_paths.remove(module_dir) r = ["Successfully imported module '%s'" % mod for mod in success] for mod, error in errors.items(): r.append("Error while importing module '%s': %r" % (mod, error)) return '\n'.join(r), module_names
def go(id, uid, ids, datas, context): cr = openerp.registry(db).db.cursor() try: result, format = openerp.report.render_report(cr, uid, ids, object, datas, context) if not result: tb = sys.exc_info() self_reports[id]['exception'] = openerp.exceptions.DeferredException('RML is not available at specified location or not enough data to print!', tb) self_reports[id]['result'] = result self_reports[id]['format'] = format self_reports[id]['state'] = True except Exception, exception: _logger.exception('Exception: %s\n', exception) if hasattr(exception, 'name') and hasattr(exception, 'value'): self_reports[id]['exception'] = openerp.exceptions.DeferredException(tools.ustr(exception.name), tools.ustr(exception.value)) else: tb = sys.exc_info() self_reports[id]['exception'] = openerp.exceptions.DeferredException(tools.exception_to_unicode(exception), tb) self_reports[id]['state'] = True
def go(id, uid, ids, datas, context): with openerp.api.Environment.manage(): cr = openerp.registry(db).cursor() try: # funkring.net - begin context["report_meta"] = {} # funkrnig.net - end result, format = openerp.report.render_report( cr, uid, ids, object, datas, context) if not result: tb = sys.exc_info() self_reports[id][ 'exception'] = openerp.exceptions.DeferredException( 'RML is not available at specified location or not enough data to print!', tb) self_reports[id]['result'] = result self_reports[id]['format'] = format # funkring.net - begin report_meta = context.get("report_meta") if report_meta: name = report_meta.get('name') last_name = report_meta.get('last_name') if name and last_name and name != last_name: self_reports[id]['name'] = "%s_%s" % (name, last_name) else: self_reports[id]['name'] = name # funkrnig.net - end self_reports[id]['state'] = True except Exception, exception: _logger.exception('Exception: %s\n', exception) if hasattr(exception, 'name') and hasattr(exception, 'value'): self_reports[id][ 'exception'] = openerp.exceptions.DeferredException( tools.ustr(exception.name), tools.ustr(exception.value)) else: tb = sys.exc_info() self_reports[id][ 'exception'] = openerp.exceptions.DeferredException( tools.exception_to_unicode(exception), tb) self_reports[id]['state'] = True cr.commit() cr.close()
def go(id, uid, ids, datas, context): cr = openerp.pooler.get_db(db).cursor() try: obj = openerp.netsvc.LocalService('report.'+object) (result, format) = obj.create(cr, uid, ids, datas, context) if not result: tb = sys.exc_info() self_reports[id]['exception'] = openerp.exceptions.DeferredException('RML is not available at specified location or not enough data to print!', tb) self_reports[id]['result'] = result self_reports[id]['format'] = format self_reports[id]['state'] = True except Exception, exception: _logger.exception('Exception: %s\n', exception) if hasattr(exception, 'name') and hasattr(exception, 'value'): self_reports[id]['exception'] = openerp.exceptions.DeferredException(tools.ustr(exception.name), tools.ustr(exception.value)) else: tb = sys.exc_info() self_reports[id]['exception'] = openerp.exceptions.DeferredException(tools.exception_to_unicode(exception), tb) self_reports[id]['state'] = True
def exp_render_report(db, uid, object, ids, datas=None, context=None): if not datas: datas = {} if not context: context = {} self_id_protect.acquire() global self_id self_id += 1 id = self_id self_id_protect.release() self_reports[id] = {"uid": uid, "result": False, "state": False, "exception": None} cr = openerp.registry(db).cursor() try: result, format = openerp.report.render_report(cr, uid, ids, object, datas, context) if not result: tb = sys.exc_info() self_reports[id]["exception"] = openerp.exceptions.DeferredException( "RML is not available at specified location or not enough data to print!", tb ) self_reports[id]["result"] = result self_reports[id]["format"] = format self_reports[id]["state"] = True except Exception, exception: _logger.exception("Exception: %s\n", exception) if hasattr(exception, "name") and hasattr(exception, "value"): self_reports[id]["exception"] = openerp.exceptions.DeferredException( tools.ustr(exception.name), tools.ustr(exception.value) ) else: tb = sys.exc_info() self_reports[id]["exception"] = openerp.exceptions.DeferredException( tools.exception_to_unicode(exception), tb ) self_reports[id]["state"] = True
def run(self): self.running = True try: ts = tiny_socket.mysocket(self.sock) except Exception: self.threads.remove(self) self.running = False return False while self.running: try: msg = ts.myreceive() result = self.dispatch(msg[0], msg[1], msg[2:]) ts.mysend(result) except socket.timeout: #terminate this channel because other endpoint is gone break except netsvc.OpenERPDispatcherException, e: try: new_e = Exception(tools.exception_to_unicode(e.exception)) # avoid problems of pickeling logging.getLogger('web-services').debug("netrpc: rpc-dispatching exception", exc_info=True) ts.mysend(new_e, exception=True, traceback=e.traceback) except Exception: #terminate this channel if we can't properly send back the error logging.getLogger('web-services').exception("netrpc: cannot deliver exception message to client") break except Exception, e: try: tb = getattr(e, 'traceback', sys.exc_info()) tb_s = "".join(traceback.format_exception(*tb)) logging.getLogger('web-services').debug("netrpc: communication-level exception", exc_info=True) ts.mysend(e, exception=True, traceback=tb_s) break except Exception, ex: #terminate this channel if we can't properly send back the error logging.getLogger('web-services').exception("netrpc: cannot deliver exception message to client") break
if mode == 'reset' and not token: try: res_users.reset_password(request.cr, openerp.SUPERUSER_ID, login) qcontext['message'] = _("An email has been sent with credentials to reset your password") response.params['template'] = 'web.login' except Exception, e: qcontext['error'] = exception_to_unicode(e) or _("Could not reset your password") _logger.exception('error when resetting password') else: values = dict((key, qcontext.get(key)) for key in ('login', 'name', 'password')) try: self._signup_with_values(token, values) redirect = request.params.get('redirect') if not redirect: redirect = '/web?' + request.httprequest.query_string return http.redirect_with_hash(redirect) except SignupError, e: qcontext['error'] = exception_to_unicode(e) return response def _signup_with_values(self, token, values): db, login, password = request.registry['res.users'].signup(request.cr, openerp.SUPERUSER_ID, values, token) request.cr.commit() # as authenticate will use its own cursor we need to commit the current transaction uid = request.session.authenticate(db, login, password) if not uid: raise SignupError(_('Authentification Failed.')) # vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
def _dispatch(self, method, params): try: service_name = self.path.split("/")[-1] return self.dispatch(service_name, method, params) except netsvc.OpenERPDispatcherException, e: raise xmlrpclib.Fault(tools.exception_to_unicode(e.exception), e.traceback)
def web_login(self, *args, **kw): mode = request.params.get('mode') qcontext = request.params.copy() response = webmain.render_bootstrap_template(request.session.db, 'auth_signup.signup', qcontext, lazy=True) token = qcontext.get('token', None) token_infos = None if token: try: # retrieve the user info (name, login or email) corresponding to a signup token res_partner = request.registry.get('res.partner') token_infos = res_partner.signup_retrieve_info( request.cr, openerp.SUPERUSER_ID, token) for k, v in token_infos.items(): qcontext.setdefault(k, v) except: qcontext['error'] = _("Invalid signup token") response.params['template'] = 'web.login' return response # retrieve the module config (which features are enabled) for the login page icp = request.registry.get('ir.config_parameter') config = { 'signup': icp.get_param(request.cr, openerp.SUPERUSER_ID, 'auth_signup.allow_uninvited') == 'True', 'reset': icp.get_param(request.cr, openerp.SUPERUSER_ID, 'auth_signup.reset_password') == 'True', } qcontext.update(config) if 'error' in qcontext or mode not in ('reset', 'signup') or ( not token and not config[mode]): response = super(Home, self).web_login(*args, **kw) if isinstance(response, LazyResponse): response.params['values'].update(config) return response if request.httprequest.method == 'GET': if token_infos: qcontext.update(token_infos) else: res_users = request.registry.get('res.users') login = request.params.get('login') if mode == 'reset' and not token: try: res_users.reset_password(request.cr, openerp.SUPERUSER_ID, login) qcontext['message'] = _( "An email has been sent with credentials to reset your password" ) response.params['template'] = 'web.login' except Exception: qcontext['error'] = _("Could not reset your password") _logger.exception('error when resetting password') else: values = dict((key, qcontext.get(key)) for key in ('login', 'name', 'password')) try: self._signup_with_values(token, values) request.cr.commit() except SignupError, e: qcontext['error'] = exception_to_unicode(e) return super(Home, self).web_login(*args, **kw)
def synchronize_events_cron(self, cr, uid, context=None): ids = self.pool['res.users'].search(cr, uid, [('google_calendar_last_sync_date', '!=', False)], context=context) _logger.info("Calendar Synchro - Started by cron") for user_to_sync in ids: _logger.info("Calendar Synchro - Starting synchronization for a new user [%s] " % user_to_sync) try: resp = self.synchronize_events(cr, user_to_sync, False, lastSync=True, context=None) if resp.get("status") == "need_reset": _logger.info("[%s] Calendar Synchro - Failed - NEED RESET !" % user_to_sync) else: _logger.info("[%s] Calendar Synchro - Done with status : %s !" % (user_to_sync, resp.get("status"))) except Exception, e: _logger.info("[%s] Calendar Synchro - Exception : %s !" % (user_to_sync, exception_to_unicode(e)))