def printData(data, model, ids): if 'result' not in data: Notifier.notifyWarning( _('Report error'), _('There was an error trying to create the report.')) return if data.get('code', 'normal') == 'zlib': import zlib content = zlib.decompress(base64.decodestring(data['result'])) else: content = base64.decodestring(data['result']) # We'll always try to open the file and won't limit ourselves to # doc, html and pdf. For example, one might get odt, ods, etc. Before # we stored the report in a file if it wasn't one of the first three # formats. if data['format'] == 'html' and os.name == 'nt': data['format'] = 'doc' fp, fileName = tempfile.mkstemp('.%s' % data['format']) fp = os.fdopen(fp, 'wb+') try: fp.write(content) finally: fp.close() # Add semantic information before printing file because otherwise # it raises an exception in some systems. Semantic.addInformationToFile(fileName, model, ids) Printer.printFile(fileName, data['format'])
def __init__(self, url): Connection.__init__(self, url) self.url += '/rpc' from Koo.Common.Settings import Settings Pyro.config.PYRO_TRACELEVEL = int(Settings.value('pyro.tracelevel')) Pyro.config.PYRO_LOGFILE = Settings.value('pyro.logfile') Pyro.config.PYRO_DNS_URI = int(Settings.value('pyro.dns_uri')) if self.url.startswith('PYROLOCSSL'): Pyro.config.PYROSSL_CERTDIR = Settings.value('pyrossl.certdir') Pyro.config.PYROSSL_CERT = Settings.value('pyrossl.cert') Pyro.config.PYROSSL_KEY = Settings.value('pyrossl.key') Pyro.config.PYROSSL_CA_CERT = Settings.value('pyrossl.ca_cert') Pyro.config.PYROSSL_POSTCONNCHECK = int( Settings.value('pyrossl.postconncheck')) try: self.proxy = Pyro.core.getProxyForURI(self.url) except SSLError as e: title = _('SSL Error') if e.message == 'No such file or directory': msg = _('Please check your SSL certificate: ') msg += e.message msg += '\n%s' % os.path.join(Pyro.config.PYROSSL_CERTDIR, Pyro.config.PYROSSL_CERT) details = traceback.format_exc() Notifier.notifyError(title, msg, details) else: raise except Exception as e: raise
def click(self): if not self.record: return # TODO: Remove screen dependency and thus ViewForm.screen screen = self.view.screen self.view.store() if self.attrs.get('special', '') == 'quit': sys.exit(0) if self.attrs.get('special', '') == 'cancel': screen.close() if 'name' in list(self.attrs.keys()): result = Rpc.session.execute('/object', 'execute', screen.name, self.attrs['name'], [], self.record.context()) datas = {} Api.instance.executeAction(result, datas, screen.context) return if self.record.validate(): id = screen.save() if not self.attrs.get('confirm', False) or \ QMessageBox.question(self, _('Question'), self.attrs['confirm'], _("Yes"), _("No")) == 0: self.executeButton(screen, id) else: Notifier.notifyWarning('', _('Invalid Form, correct red fields!')) screen.display()
def callOnChange(self, callback): match = re.match('^(.*?)\((.*)\)$', callback) if not match: raise Exception, 'ERROR: Wrong on_change trigger: %s' % callback func_name = match.group(1) arg_names = [n.strip() for n in match.group(2).split(',')] args = [self.evaluateExpression(arg) for arg in arg_names] ids = self.id and [self.id] or [] response = getattr(self.rpc, func_name)(ids, *args) if response: self.set(response.get('value', {}), modified=True) if 'value_def' in response: is_updated = False for fieldname, val in response['value_def'].items(): if fieldname not in self.group.fieldObjects: continue if not self.group.fieldObjects[fieldname].get(self): self.group.fieldObjects[fieldname].set(self, val, modified=True) is_updated = True if is_updated: self.modified = True self.emit(SIGNAL('recordChanged( PyQt_PyObject )'), self) self.emit(SIGNAL('recordModified( PyQt_PyObject )'), self) if 'domain' in response: for fieldname, value in response['domain'].items(): if fieldname not in self.group.fieldObjects: continue self.group.fieldObjects[fieldname].attrs['domain'] = value warning = response.get('warning',{}) if warning: Notifier.notifyWarning(warning['title'], warning['message']) if 'focus' in response: self.emit(SIGNAL('setFocus(QString)'), response['focus'])
def callOnChange(self, callback): """ This function is called by the field when it's changed and has a 'on_change' attribute. The 'callback' parameter is the function that has to be executed on the server. So the function specified is called on the server whenever the field changes. :param callback: :return: """ match = re.match('^(.*?)\((.*)\)$', callback) if not match: raise Exception('ERROR: Wrong on_change trigger: %s' % callback) func_name = match.group(1) arg_names = [n.strip() for n in match.group(2).split(',')] args = [self.evaluateExpression(arg) for arg in arg_names] ids = self.id and [self.id] or [] response = getattr(self.rpc, func_name)(ids, *args) if response: self.set(response.get('value', {}), modified=True) if 'domain' in response: for fieldname, value in list(response['domain'].items()): if fieldname not in self.group.fieldObjects: continue self.group.fieldObjects[fieldname].attrs['domain'] = value warning = response.get('warning', {}) if warning: Notifier.notifyWarning(warning['title'], warning['message']) if 'focus' in response: self.setFocus.emit(response['focus'])
def execute(self, url, method, *args): res = False try: res = self.call(url, method, *args) except socket.error as msg: Notifier.notifyWarning('', _('Could not contact server!')) return res
def execute(self, obj, method, *args): """ Same as call() but uses the notify mechanism to notify exceptions. Note that you'll need to bind gettext as texts sent to the notify module are localized. :param obj: :param method: :param args: :return: """ count = 1 while True: try: return self.call(obj, method, *args) except RpcProtocolException as err: if not Notifier.notifyLostConnection(count): raise except RpcServerException as err: if err.type in ('warning', 'UserError'): if err.info in ('ConcurrencyException') and len(args) > 4: if Notifier.notifyConcurrencyError(args[0], args[2] and args[2][0], args[4]): if ConcurrencyCheckField in args[4]: del args[4][ConcurrencyCheckField] return self.execute(obj, method, *args) else: Notifier.notifyWarning(err.info, err.data) else: # Si venim a aquest punt l'error no es controlar i per tant # s'ha de fer raise i tractar on toqui del Qgis. raise return count += 1
def exceptionHook(type, value, backtrace): from PyQt4.QtGui import QApplication cursor = QApplication.overrideCursor() if cursor: QApplication.restoreOverrideCursor() from Settings import Settings import traceback backtrace = ''.join(traceback.format_tb(backtrace)) if Settings.value('client.debug'): from Koo.Common import Notifier Notifier.notifyError(type, value, backtrace) else: error('Error: %s\n%s\n%s' % (type, value, backtrace))
def execute(self, url, method, *args): """ Same as call() but uses the notify mechanism to notify exceptions. :param url: :param method: :param args: :return: """ res = False try: res = self.call(url, method, *args) except socket.error as msg: Notifier.notifyWarning('', _('Could not contact server!')) return res
def hasFinished(self): if self.exception: if self.useNotifications: # Note that if there's an error or warning # callback is called anyway with value None if self.error: Notifier.notifyError(*self.error) elif self.warning: Notifier.notifyWarning(*self.warning) else: raise self.exception self.exception.emit(self.exception) else: self.called.emit(self.result) if self.callback: self.callback(self.result, self.exception) # Free session and thus server as soon as possible self.session = None
def execute(self, obj, method, *args): """ Same as call() but uses the notify mechanism to notify exceptions. Note that you'll need to bind gettext as texts sent to the notify module are localized. :param obj: :param method: :param args: :return: """ count = 1 while True: try: return self.call(obj, method, *args) except RpcProtocolException as err: if not Notifier.notifyLostConnection(count): raise except RpcServerException as err: if err.type in ('warning', 'UserError'): if err.info in ('ConcurrencyException') and len(args) > 4: if Notifier.notifyConcurrencyError(args[0], args[2] and args[2][0], args[4]): if ConcurrencyCheckField in args[4]: del args[4][ConcurrencyCheckField] return self.execute(obj, method, *args) else: Notifier.notifyWarning(err.info, err.data) else: Notifier.notifyError(_('Application Error'), _( 'View details'), err.backtrace) raise count += 1
def execute(self, obj, method, *args): count = 1 while True: try: return self.call(obj, method, *args) except RpcProtocolException, err: if not Notifier.notifyLostConnection(count): raise except RpcServerException, err: if err.type in ('warning', 'UserError'): if err.args[0] in ( 'ConcurrencyException') and len(args) > 4: if Notifier.notifyConcurrencyError( args[0], args[2] and args[2][0], args[4]): if ConcurrencyCheckField in args[4]: del args[4][ConcurrencyCheckField] return self.execute(obj, method, *args) else: Notifier.notifyWarning(err.args[0], err.args[1]) else: Notifier.notifyError( _('Application Error: %s') % err.get_title(), _('View details: %s') % err.get_details(), err.backtrace) raise
def editorEvent(self, event, model, option, index): if event.type() != QEvent.MouseButtonPress: return AbstractFieldDelegate.editorEvent(self, event, model, option, index) record = index.model().recordFromIndex(index) if not record: return True if not self.isEnabled(record): return True # TODO: Remove screen dependency and thus ViewTree.screen view = self.parent().parent() screen = self.parent().parent().screen screen.setCurrentRecord(record) view.store() if self.attributes.get('special', '') == 'cancel': screen.close() if 'name' in list(self.attributes.keys()): result = Rpc.session.execute('/object', 'execute', screen.name, self.attributes['name'], [], record.context()) datas = {} Api.instance.executeAction(result, datas, screen.context) return if record.validate(): id = screen.save() if not self.attributes.get('confirm', False) or \ QMessageBox.question(self, _('Question'), self.attributes['confirm'], _("Yes"), _("No")) == 0: self.executeButton(screen, id, record) else: Notifier.notifyWarning('', _('Invalid Form, correct red fields!')) screen.display() return True
def exceptionHook(type, value, backtrace): from PyQt5.QtWidgets import QApplication from Koo.Common.Version import Version cursor = QApplication.overrideCursor() if cursor: QApplication.restoreOverrideCursor() from .Settings import Settings import traceback sentry_dsn = Settings.get("client.sentry_dsn") if sentry_dsn: client = Client(sentry_dsn) extra = Settings.options extra.update({"version": Version}) client.captureException(exc_info=(type, value, backtrace), extra=extra) backtrace = ''.join(traceback.format_tb(backtrace)) if Settings.value('client.debug'): from Koo.Common import Notifier Notifier.notifyError(type, value, backtrace) else: error('Error: %s\n%s\n%s' % (type, value, backtrace))
def executeButton(self, screen, id): type = self.attrs.get('type', 'workflow') if type == 'workflow': QApplication.setOverrideCursor(Qt.WaitCursor) try: # TODO: Uncomment when our patch will be applied in the server #result = Rpc.session.execute('/object', 'exec_workflow', screen.name, self.name, id, self.record.context()) result = Rpc.session.execute('/object', 'exec_workflow', screen.name, self.name, id) if isinstance(result, dict): if result['type'] == 'ir.actions.act_window_close': screen.close() else: if result['type'] == 'ir.actions.act_window': QApplication.setOverrideCursor(Qt.ArrowCursor) Api.instance.executeAction(result, {'ids': [id]}) if result['type'] == 'ir.actions.act_window': QApplication.restoreOverrideCursor() elif isinstance(result, list): for r in result: if result['type'] == 'ir.actions.act_window': QApplication.setOverrideCursor(Qt.ArrowCursor) Api.instance.executeAction(r, {'ids': [id]}) if result['type'] == 'ir.actions.act_window': QApplication.restoreOverrideCursor() except Rpc.RpcException as e: pass QApplication.restoreOverrideCursor() elif type == 'object': if not id: return QApplication.setOverrideCursor(Qt.WaitCursor) try: result = Rpc.session.execute('/object', 'execute', screen.name, self.name, [id], self.record.context()) except Rpc.RpcException as e: QApplication.restoreOverrideCursor() return QApplication.restoreOverrideCursor() if isinstance(result, dict): screen.close() datas = { 'ids': [id], 'model': screen.name, } Api.instance.executeAction(result, datas, screen.context) elif type == 'action': action_id = int(self.attrs['name']) Api.instance.execute(action_id, { 'model': screen.name, 'id': id, 'ids': [id] }, context=screen.context) else: Notifier.notifyError(_('Error in Button'), _('Button type not allowed'), _('Button type not allowed')) QApplication.setOverrideCursor(Qt.WaitCursor) try: screen.reload() except Rpc.RpcException as e: pass QApplication.restoreOverrideCursor()
} if 'datas' in result: datas.update(result['datas']) Api.instance.executeAction(result, datas, screen.context) elif type == 'action': action_id = int(self.attrs['name']) Api.instance.execute(action_id, { 'model': screen.name, 'id': id, 'ids': [id] }, context=screen.context) else: Notifier.notifyError(_('Error in Button'), _('Button type not allowed'), _('Button type not allowed')) QApplication.setOverrideCursor(Qt.WaitCursor) try: screen.reload() except Rpc.RpcException, e: pass QApplication.restoreOverrideCursor() def click(self): if not self.record: return # TODO: Remove screen dependency and thus ViewForm.screen screen = self.view.screen