WIP: axel-caluire: load schemas when needed only (#81826) #359

Draft
pducroquet wants to merge 1 commits from wip/81826-axel-caluire-on_demand into main
1 changed files with 30 additions and 21 deletions

View File

@ -31,7 +31,7 @@ from passerelle.contrib.utils import axel
from passerelle.utils.api import endpoint
from passerelle.utils.jsonresponse import APIError
from . import schemas, utils
from . import utils
WEEKDAYS = {
0: 'monday',
@ -44,6 +44,15 @@ WEEKDAYS = {
}
_schemas_module = None
def schemas():
global _schemas_module
if _schemas_module is None:
from . import schemas
_schemas_module = schemas
return _schemas_module
class CaluireAxel(BaseResource):
wsdl_url = models.CharField(
max_length=128, blank=False, verbose_name=_('WSDL URL'), help_text=_('Caluire Axel WSDL URL')
@ -64,7 +73,7 @@ class CaluireAxel(BaseResource):
for key in ['NAISSANCE', 'CODEPOSTAL', 'VILLE', 'TEL', 'MAIL']:
post_data[key] = None
try:
result = schemas.find_individus(self, {'PORTAIL': {'FINDINDIVIDU': post_data}})
result = schemas().find_individus(self, {'PORTAIL': {'FINDINDIVIDU': post_data}})
except axel.AxelError as e:
raise APIError(
'Axel error: %s' % e,
@ -93,7 +102,7 @@ class CaluireAxel(BaseResource):
post={
'request_body': {
'schema': {
'application/json': schemas.LINK_SCHEMA,
'application/json': schemas().LINK_SCHEMA,
}
}
},
@ -152,7 +161,7 @@ class CaluireAxel(BaseResource):
if result is not None:
return result
try:
result = schemas.get_famille_individus(
result = schemas().get_famille_individus(
self, {'PORTAIL': {'GETFAMILLE': {'IDENTFAMILLE': family_id}}}
)
except axel.AxelError as e:
@ -238,7 +247,7 @@ class CaluireAxel(BaseResource):
post={
'request_body': {
'schema': {
'application/json': schemas.UPLOAD_ATTACHMENTS_SCHEMA,
'application/json': schemas().UPLOAD_ATTACHMENTS_SCHEMA,
}
}
},
@ -272,7 +281,7 @@ class CaluireAxel(BaseResource):
data['PIECE'] = attachments
try:
result = schemas.set_pieces(self, {'PORTAIL': {'SETPIECES': data}})
result = schemas().set_pieces(self, {'PORTAIL': {'SETPIECES': data}})
except axel.AxelError as e:
raise APIError(
'Axel error: %s' % e,
@ -316,7 +325,7 @@ class CaluireAxel(BaseResource):
reference_year = utils.get_reference_year_from_date(schooling_date)
try:
result = schemas.get_list_ecole(
result = schemas().get_list_ecole(
self,
{
'PORTAIL': {
@ -368,7 +377,7 @@ class CaluireAxel(BaseResource):
reference_year = utils.get_reference_year_from_date(schooling_date)
try:
result = schemas.get_individu(
result = schemas().get_individu(
self,
{'PORTAIL': {'GETINDIVIDU': {'IDENTINDIVIDU': idpersonne, 'ANNEE': str(reference_year)}}},
)
@ -390,7 +399,7 @@ class CaluireAxel(BaseResource):
return result
try:
result = schemas.get_list_activites(
result = schemas().get_list_activites(
self,
{'PORTAIL': {'GETLISTACTIVITES': {'IDENTINDIVIDU': child_id, 'ANNEE': str(reference_year)}}},
)
@ -484,7 +493,7 @@ class CaluireAxel(BaseResource):
post={
'request_body': {
'schema': {
'application/json': schemas.REGISTER_ACTIVITY_SCHEMA,
'application/json': schemas().REGISTER_ACTIVITY_SCHEMA,
}
}
},
@ -515,7 +524,7 @@ class CaluireAxel(BaseResource):
}
try:
result = schemas.create_inscription_activite(
result = schemas().create_inscription_activite(
self, {'PORTAIL': {'CREATEINSCRIPTIONACTIVITE': data}}
)
except axel.AxelError as e:
@ -569,7 +578,7 @@ class CaluireAxel(BaseResource):
}
try:
result = schemas.get_agenda(self, {'PORTAIL': {'GETAGENDA': data}})
result = schemas().get_agenda(self, {'PORTAIL': {'GETAGENDA': data}})
except axel.AxelError as e:
raise APIError(
'Axel error: %s' % e,
@ -819,7 +828,7 @@ class CaluireAxel(BaseResource):
}
}
}
result = schemas.set_agenda(self, data)
result = schemas().set_agenda(self, data)
except axel.AxelError as e:
raise APIError(
'Axel error: %s' % e,
@ -930,7 +939,7 @@ class CaluireAxel(BaseResource):
post={
'request_body': {
'schema': {
'application/json': schemas.BOOKING_SCHEMA,
'application/json': schemas().BOOKING_SCHEMA,
}
}
},
@ -969,7 +978,7 @@ class CaluireAxel(BaseResource):
post={
'request_body': {
'schema': {
'application/json': schemas.CHANGES_SCHEMA,
'application/json': schemas().CHANGES_SCHEMA,
}
}
},
@ -1047,7 +1056,7 @@ class CaluireAxel(BaseResource):
post={
'request_body': {
'schema': {
'application/json': schemas.TYPICAL_WEEK_BOOKING_SCHEMA,
'application/json': schemas().TYPICAL_WEEK_BOOKING_SCHEMA,
}
}
},
@ -1087,7 +1096,7 @@ class CaluireAxel(BaseResource):
def get_invoices(self, regie_id, family_id):
try:
result = schemas.get_factures_a_payer(
result = schemas().get_factures_a_payer(
self,
{
'PORTAIL': {
@ -1126,7 +1135,7 @@ class CaluireAxel(BaseResource):
except ValueError:
raise APIError('nb_mounts_limit must be an integer', err_code='bad-request', http_status=400)
try:
result = schemas.get_list_factures(
result = schemas().get_list_factures(
self,
{
'PORTAIL': {
@ -1278,7 +1287,7 @@ class CaluireAxel(BaseResource):
raise APIError('PDF not available', err_code='not-available', http_status=404)
try:
result = schemas.get_pdf_facture(
result = schemas().get_pdf_facture(
self, {'PORTAIL': {'GETPDFFACTURE': {'IDFACTURE': int(invoice['display_id'])}}}
)
except axel.AxelError as e:
@ -1313,7 +1322,7 @@ class CaluireAxel(BaseResource):
post={
'request_body': {
'schema': {
'application/json': schemas.PAYMENT_SCHEMA,
'application/json': schemas().PAYMENT_SCHEMA,
}
}
},
@ -1333,7 +1342,7 @@ class CaluireAxel(BaseResource):
'IDENTMODEREGLEMENT': 'INCB',
}
try:
result = schemas.set_paiement(self, {'PORTAIL': {'SETPAIEMENT': post_data}})
result = schemas().set_paiement(self, {'PORTAIL': {'SETPAIEMENT': post_data}})
except axel.AxelError as e:
raise APIError(
'Axel error: %s' % e,