parent
a1d08fb705
commit
558fefdfb5
|
@ -123,6 +123,8 @@ class Resource(BaseResource):
|
|||
'code_insee': {'type': 'string'},
|
||||
})
|
||||
base_schema.setdefault('required', []).append('display_id')
|
||||
if hasattr(cls, 'pre_process_create'):
|
||||
base_schema['pre_process'] = cls.pre_process_create
|
||||
return base_schema
|
||||
|
||||
def _handle_create(self, request, payload):
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from decimal import Decimal
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils import six
|
||||
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.xml import JSONSchemaFromXMLSchema
|
||||
|
@ -102,6 +102,32 @@ class Resource(abstract.Resource):
|
|||
def create(self, request, post_data):
|
||||
return self._handle_create(request, post_data)
|
||||
|
||||
def pre_process_create(self, data):
|
||||
def helper(d):
|
||||
if not isinstance(d, dict):
|
||||
return
|
||||
# choose between conventionType and conventionSpecifique
|
||||
if 'conventionSpecifique' in d:
|
||||
if d['conventionSpecifique']:
|
||||
d.pop('conventionType', None)
|
||||
else:
|
||||
del d['conventionSpecifique']
|
||||
# choose between filiationInconnu and filiationConnu
|
||||
if 'filiationInconnu' in d:
|
||||
if d['filiationInconnu']:
|
||||
d.pop('filiationConnu', None)
|
||||
else:
|
||||
del d['filiationInconnu']
|
||||
# convert codeNationalite to array of strings
|
||||
if isinstance(d.get('codeNationalite'), six.text_type):
|
||||
d['codeNationalite'] = [d['codeNationalite']]
|
||||
for key in d:
|
||||
if key in ('anneeNaissance', 'jourNaissance', 'moisNaissance'):
|
||||
d[key] = int(d[key])
|
||||
for key in d:
|
||||
helper(d[key])
|
||||
helper(data)
|
||||
|
||||
Resource.create.endpoint_info.post['request_body']['schema']['application/json'] = Resource.get_create_schema()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue