def register_icon(self, iconname): # iconname might be '' when page do not define icon if (not iconname or iconname in (self._loaded_icons | self._locale_icons)): return if iconname not in self._name2id: self.load_icons(refresh=True) icon_ref = (self._name2id[iconname], iconname) idx = self._tryton_icons.index(icon_ref) to_load = slice(max(0, idx - self.batchnum // 2), idx + self.batchnum // 2) ids = [e[0] for e in self._tryton_icons[to_load]] try: icons = rpc.execute('model', 'ir.ui.icon', 'read', ids, ['name', 'icon'], rpc.CONTEXT) except TrytonServerError: icons = [] for icon in icons: # svg file cannot be loaded from data into a pixbuf fileno, path = tempfile.mkstemp() with os.fdopen(fileno, 'w') as svgfile: svgfile.write(icon['icon']) try: pixbuf = gtk.gdk.pixbuf_new_from_file(path.decode( sys.getfilesystemencoding().encode('utf-8'))) except glib.GError: continue finally: os.remove(path) self._tryton_icons.remove((icon['id'], icon['name'])) del self._name2id[icon['name']] self._loaded_icons.add(icon['name']) iconset = gtk.IconSet(pixbuf) self.add(icon['name'], iconset)
def load_models(self, refresh=False): if not refresh: self._access.clear() del self._models[:] try: self._models = rpc.execute('model', 'ir.model', 'list_models', rpc.CONTEXT) except TrytonServerError: pass
def process_exception(exception, *args, **kwargs): if isinstance(exception, TrytonError): if exception.faultCode == 'BadFingerprint': warning( _('The server fingerprint has changed since last connection!\n' 'The application will stop connecting to this server ' 'until its fingerprint is fixed.'), _('Security risk!')) from tryton.gui.main import Main Main.sig_quit() sys.exit() elif exception.faultCode == 'NotLogged': if rpc.CONNECTION is None: message(_('Connection error!\n' \ 'Unable to connect to the server!')) return False elif isinstance(exception, TrytonServerError): if exception.faultCode == 'UserWarning': name, msg, description = exception.args res = userwarning(description, msg) if res in ('always', 'ok'): args2 = ('model', 'res.user.warning', 'create', { 'user': rpc._USER, 'name': name, 'always': (res == 'always'), }, rpc.CONTEXT) try: rpc.execute(*args2) except TrytonServerError, exception: process_exception(exception, *args2) if args: try: return rpc.execute(*args) except TrytonServerError, exception: return process_exception(exception, *args) return True return False
def __getitem__(self, model): if model in self._access: return self._access[model] if model not in self._models: self.load_models(refresh=True) idx = self._models.index(model) to_load = slice(max(0, idx - self.batchnum // 2), idx + self.batchnum // 2) try: access = rpc.execute('model', 'ir.model.access', 'get_access', self._models[to_load], rpc.CONTEXT) except TrytonServerError: access = {} self._access.update(access) return self._access[model]
def load_icons(self, refresh=False): if not refresh: self._name2id.clear() self._loaded_icons.clear() del self._tryton_icons[:] try: icons = rpc.execute('model', 'ir.ui.icon', 'list_icons', rpc.CONTEXT) except TrytonServerError: icons = [] for icon_id, icon_name in icons: if refresh and icon_name in self._loaded_icons: continue self._tryton_icons.append((icon_id, icon_name)) self._name2id[icon_name] = icon_id
def load_searches(self): try: self.searches = rpc.execute('model', 'ir.ui.view_search', 'get_search', rpc.CONTEXT) except TrytonServerError: self.searches = {}
return rpc.execute(*args) except TrytonServerError, exception: return process_exception(exception, *args) return True return False elif exception.faultCode == 'UserError': msg, description = exception.args warning(description, msg) return False elif exception.faultCode == 'ConcurrencyException': if len(args) >= 6: if concurrency(args[1], args[3][0], args[5]): if '_timestamp' in args[5]: del args[5]['_timestamp'] try: return rpc.execute(*args) except TrytonServerError, exception: return process_exception(exception, *args) return False else: message(_('Concurrency Exception'), msg_type=gtk.MESSAGE_ERROR) return False elif exception.faultCode == 'NotLogged': from tryton.gui.main import Main if not PLOCK.acquire(False): return False hostname = rpc._HOST port = rpc._PORT try: while True: password = ask(_('Password:'), visibility=False)
def login(parameters): return rpc.execute('model', 'res.user', 'set_preferences', vals, parameters, context)
def load_names(self): try: self._names = rpc.execute( 'model', 'ir.model', 'get_names', rpc.CONTEXT) except TrytonServerError: pass
def sign_document(data): """ Retrieve the hash value of the serialized document and generates a clearsign signature using the user's private key on the client side via GNU Privacy Guard - GPG -""" gpg = gnupg.GPG() gpg.encoding = 'utf-8' document_model = data['model'] """ Don't allow signing more than one document at a time To avoid signing unwanted / unread documents """ if (len(data['ids']) > 1): warning( _('For security reasons, Please sign one document at a time'), _('Multiple records selected !'), ) return """ Verify that the document handles digital signatures """ try: record_vals = rpc.execute('model', document_model, 'read', data['ids'], ['document_digest', 'digital_signature'], rpc.CONTEXT) except: warning( _('Please enable the model for digital signature'), _('No Digest or Digital Signature fields found !'), ) return digest = record_vals[0]['document_digest'] """ Check that the document hasn't been signed already """ if record_vals[0]['digital_signature']: warning( _('Document already signed'), _('This record has been already signed'), ) return # Check that the document has the digest before trying to # to sign it. if digest: try: gpg_signature = gpg.sign(digest, clearsign=True) except: warning( _('Error when signing the document'), _('Please check your encryption settings'), ) else: warning( _('No Digest found for this document'), _('You need generate the digest'), ) return """ Set the clearsigned digest """ try: RPCExecute('model', document_model, 'set_signature', data, str(gpg_signature)) except: warning( _('Error when saving the digital signature'), _('The signature was generated but NOT saved !'), ) else: message(_('Document digitally signed'))
def search_resource(self, widget, *data): resource, query, fuzzy_search = data[0].get_text(), \ data[1].get_text(), data[2].get_active() query = query.upper() if resource: model='gnuhealth.federation.config' # Retrieve the connection params for Thalamus fconn,=rpc.execute( 'model', model , 'read', [0], ['host','port','user','password','ssl', \ 'verify_ssl'], rpc.CONTEXT) host, port, user, password, ssl, verify_ssl = \ fconn['host'], fconn['port'], fconn['user'], \ fconn['password'], fconn['ssl'], fconn['verify_ssl'] if (ssl): protocol = 'https://' else: protocol = 'http://' url = protocol + host + ':' + str(port) res = url + '/' + resource if resource == "people": res = res + '/' + query try: conn = requests.get(res, auth=(user, password), verify=verify_ssl) except: message(_('Unable to connect to Thalamus')) return if fuzzy_search: # Find the federation ID using fuzzy search msg = "Coming up" message(_(msg)) else: # Find the federation ID using deterministic algorithm # (exact match, return at most one record) self.federation_data = requests.get(res, params=query, auth=(user, password), verify=verify_ssl) if not self.federation_data: not_found_msg = "The ID "+ query +\ " does not exist on Federation" message(_(not_found_msg)) else: #Populate and pack the result r = [] fields = ['_id','name', 'lastname', 'gender', 'dob', 'phone', 'address'] record = self.federation_data.json() for fname in fields: if fname in record.keys(): field= record[fname] else: field= '' r.append(field) self.results.append(r)