Mercurial > hgweb > health
changeset 5016:e41ff2ee6026
health_federation: migrate raise_user_error methods
| author | Luis Falcon <falcon@gnuhealth.org> |
|---|---|
| date | Mon, 24 Jan 2022 17:15:29 +0000 |
| parents | f1112c9943c6 |
| children | d6b0bef9be39 |
| files | tryton/health_federation/data/messages/messages.xml tryton/health_federation/exceptions.py tryton/health_federation/health_federation.py |
| diffstat | 3 files changed, 66 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/tryton/health_federation/data/messages/messages.xml @@ -0,0 +1,22 @@ +<?xml version="1.0"?> +<!-- This file is part of GNU Health. The COPYRIGHT file at the top level of +this repository contains the full copyright notices and license terms. --> +<tryton> + <data grouped="1"> + <record model="ir.message" id="msg_need_login_credentials"> + <field name="text">SM-FEDERATION-0001: Please setup the login credentials</field> + </record> + <record model="ir.message" id="msg_server_authentication_error"> + <field name="text">SM-FEDERATION-0002: ERROR authenticating to Server</field> + </record> + <record model="ir.message" id="msg_thalamus_connection_ok"> + <field name="text">SM-FEDERATION-0003: Connection to Thalamus Server OK!</field> + </record> + <record model="ir.message" id="msg_thalamus_connection_error"> + <field name="text">SM-FEDERATION-0004: Thalamus Connection error</field> + </record> + <record model="ir.message" id="msg_no_institution"> + <field name="text">SM-FEDERATION-0005: You need to create an institution</field> + </record> + </data> +</tryton>
new file mode 100644 --- /dev/null +++ b/tryton/health_federation/exceptions.py @@ -0,0 +1,23 @@ +# This file is part of GNU Health. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. +from trytond.exceptions import UserError, UserWarning + + +class NeedLoginCredentials(UserError): + pass + + +class ServerAuthenticationError(UserError): + pass + + +class ThalamusConnectionError(UserError): + pass + + +class ThalamusConnectionOK(UserWarning): + pass + + +class NoInstitution(UserError): + pass
--- a/tryton/health_federation/health_federation.py +++ b/tryton/health_federation/health_federation.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ############################################################################## # # GNU Health: The Free Health and Hospital Information System @@ -29,6 +28,12 @@ from trytond.rpc import RPC from datetime import datetime, date from trytond.modules.health.core import get_institution +from trytond.i18n import gettext + +from .exceptions import ( + NeedLoginCredentials, ServerAuthenticationError, + ThalamusConnectionError, ThalamusConnectionOK, + NoInstitution) __all__ = [ 'FederationNodeConfig', 'FederationQueue', 'FederationObject', @@ -120,7 +125,9 @@ protocol = 'http://' if (not user or not password): - cls.raise_user_error("Please setup the login credentials") + raise NeedLoginCredentials( + gettext('health_federation.need_login_credentials') + ) url = protocol + host + ':' + str(port) + '/people/' + user @@ -130,13 +137,19 @@ auth=(user, password), verify=verify_ssl) except: - cls.raise_user_error("ERROR authenticating to Server") + raise ServerAuthenticationError( + gettext('health_federation.server_authentication_error') + ) if conn: - cls.raise_user_error("Connection to Thalamus Server OK !") + raise ThalamusConnectionOK( + gettext('health_federation.thalamus_connection_ok') + ) else: - cls.raise_user_error("ERROR authenticating to Server") + raise ThalamusConnectionError( + gettext('health_federation.thalamus_connection_error') + ) @classmethod def get_conn_params(cls): @@ -214,8 +227,9 @@ institution_code = HealthInst(institution).code else: - FederationQueue.raise_user_error( - "You need to create a health Institution first") + raise NoInstitution( + gettext('health_federation.no_institution') + ) return institution_code
