From 83f7685c3e20418a10e9609def2854b824c4aa7c Mon Sep 17 00:00:00 2001 From: Josue Kouka Date: Mon, 12 Mar 2018 16:41:01 +0100 Subject: [PATCH 1/2] add civil status connector interface (#16768) --- passerelle/civilstatus/__init__.py | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 passerelle/civilstatus/__init__.py diff --git a/passerelle/civilstatus/__init__.py b/passerelle/civilstatus/__init__.py new file mode 100644 index 0000000..3e30624 --- /dev/null +++ b/passerelle/civilstatus/__init__.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Passerelle - uniform access to data and services +# Copyright (C) 2018 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +import json + +from django.utils.translation import ugettext_lazy as _ + +from passerelle.utils.api import endpoint +from passerelle.utils.jsonresponse import APIError + +MANDATORY_DATA = { + 'applicant_firstnames': None, + 'applicant_lastname': None, + 'application_id': None, + 'application_time': None, + 'certificate_type': ('birth', 'mariage', 'death', 'other'), + 'concerned_firstnames': None, + 'concerned_lastname': None, + 'document_type': ('full', 'multilingual', 'with-filiation', 'without-filiation'), +} + + +class EndpointNotAvailable(APIError): + http_status = 400 + + +class CivilStatusMixin(object): + + category = _('Civil Status') + + def create_demand(self, formdata, *args, **kwargs): + raise EndpointNotAvailable(' endpoint is not available') + + def get_status(self, demand_id, **kwargs): + raise EndpointNotAvailable(' endpoint is not available') + + @endpoint(perm='can_access', methods=['post']) + def create(self, request, *args, **kwargs): + payload = json.loads(request.body) + for key, values in MANDATORY_DATA.iteritems(): + if (key not in payload): + raise APIError('<%s> is required.' % key) + if values and payload[key] not in values: + raise APIError('<%s> value must be one of %s' % (key, values)) + return self.create_demand(request, payload, *args, **kwargs) + + @endpoint(perm='can_access', methods=['get'], pattern='(?P[\w-]+)/') + def status(self, request, demand_id, **kwargs): + return self.get_status(demand_id) -- 2.11.0