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 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 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 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 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 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