|
1 |
# -*- coding: utf-8 -*-
|
|
2 |
# Passerelle - uniform access to data and services
|
|
3 |
# Copyright (C) 2018 Entr'ouvert
|
|
4 |
#
|
|
5 |
# This program is free software: you can redistribute it and/or modify it
|
|
6 |
# under the terms of the GNU Affero General Public License as published
|
|
7 |
# by the Free Software Foundation, either version 3 of the License, or
|
|
8 |
# (at your option) any later version.
|
|
9 |
#
|
|
10 |
# This program is distributed in the hope that it will be useful,
|
|
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
# GNU Affero General Public License for more details.
|
|
14 |
#
|
|
15 |
# You should have received a copy of the GNU Affero General Public License
|
|
16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17 |
import json
|
|
18 |
|
|
19 |
from django.utils.translation import ugettext_lazy as _
|
|
20 |
|
|
21 |
from passerelle.utils.api import endpoint
|
|
22 |
from passerelle.utils.jsonresponse import APIError
|
|
23 |
|
|
24 |
MANDATORY_DATA = {
|
|
25 |
'applicant_firstnames': None,
|
|
26 |
'applicant_lastname': None,
|
|
27 |
'application_id': None,
|
|
28 |
'application_time': None,
|
|
29 |
'certificate_type': ('birth', 'mariage', 'death', 'other'),
|
|
30 |
'concerned_firstnames': None,
|
|
31 |
'concerned_lastname': None,
|
|
32 |
'document_type': ('full', 'multilingual', 'with-filiation', 'without-filiation'),
|
|
33 |
}
|
|
34 |
|
|
35 |
|
|
36 |
class EndpointNotAvailable(APIError):
|
|
37 |
http_status = 400
|
|
38 |
|
|
39 |
|
|
40 |
class CivilStatusMixin(object):
|
|
41 |
|
|
42 |
category = _('Civil Status')
|
|
43 |
|
|
44 |
def create_demand(self, formdata, *args, **kwargs):
|
|
45 |
raise EndpointNotAvailable('<create> endpoint is not available')
|
|
46 |
|
|
47 |
def get_status(self, demand_id, **kwargs):
|
|
48 |
raise EndpointNotAvailable('<status> endpoint is not available')
|
|
49 |
|
|
50 |
@endpoint(perm='can_access', methods=['post'])
|
|
51 |
def create(self, request, *args, **kwargs):
|
|
52 |
payload = json.loads(request.body)
|
|
53 |
for key, values in MANDATORY_DATA.iteritems():
|
|
54 |
if (key not in payload):
|
|
55 |
raise APIError('<%s> is required.' % key)
|
|
56 |
if values and payload[key] not in values:
|
|
57 |
raise APIError('<%s> value must be one of %s' % (key, values))
|
|
58 |
return self.create_demand(request, payload, *args, **kwargs)
|
|
59 |
|
|
60 |
@endpoint(perm='can_access', methods=['get'], pattern='(?P<demand_id>[\w-]+)/')
|
|
61 |
def status(self, request, demand_id, **kwargs):
|
|
62 |
return self.get_status(demand_id)
|
0 |
|
-
|