0001-general-switch-to-json-api-wrap_response-False-as-en.patch
passerelle/apps/base_adresse/models.py | ||
---|---|---|
97 | 97 |
result['address']['road'] = value |
98 | 98 |
return result |
99 | 99 | |
100 |
@endpoint(serializer_type='json-api')
|
|
100 |
@endpoint() |
|
101 | 101 |
def streets(self, request, zipcode=None, q=None, page_limit=None): |
102 | 102 |
result = [] |
103 | 103 |
streets = StreetModel.objects.all() |
... | ... | |
119 | 119 |
'citycode': street.citycode, |
120 | 120 |
'zipcode': street.zipcode}) |
121 | 121 | |
122 |
return result
|
|
122 |
return {'data': result}
|
|
123 | 123 | |
124 | 124 |
def daily(self): |
125 | 125 |
super(BaseAdresse, self).daily() |
passerelle/apps/clicrdv/models.py | ||
---|---|---|
66 | 66 |
req = self.get_request(uri) |
67 | 67 |
return json.load(urllib2.urlopen(req)) |
68 | 68 | |
69 |
@endpoint(name='interventionsets', serializer_type='json-api')
|
|
69 |
@endpoint(name='interventionsets') |
|
70 | 70 |
def get_interventionsets(self, request, **kwargs): |
71 | 71 |
records = self.get_json('interventionsets').get('records') |
72 | 72 |
records.sort(lambda x,y: cmp(x['sort'], y['sort'])) |
... | ... | |
74 | 74 |
for record in records: |
75 | 75 |
if record.get('publicname'): |
76 | 76 |
ret.append({'id': record['id'], 'text': record['publicname'], 'details': record}) |
77 |
return ret
|
|
77 |
return {'data': ret}
|
|
78 | 78 | |
79 |
@endpoint(name='interventionsets', pattern='(?P<set>\d+)/', serializer_type='json-api')
|
|
79 |
@endpoint(name='interventionsets', pattern='(?P<set>\d+)/') |
|
80 | 80 |
def get_interventions(self, request, set, **kwargs): |
81 | 81 |
ret = [] |
82 | 82 |
records = self.get_json('interventions?interventionset_id=%s' % set).get('records') |
... | ... | |
84 | 84 |
for record in records: |
85 | 85 |
if record.get('publicname'): |
86 | 86 |
ret.append({'id': record['id'], 'text': record['publicname'], 'details': record}) |
87 |
return ret
|
|
87 |
return {'data': ret}
|
|
88 | 88 | |
89 | 89 |
def get_available_timeslots(self, intervention, date_start=None, date_end=None): |
90 | 90 |
timeslots = [] |
passerelle/apps/cmis/models.py | ||
---|---|---|
48 | 48 |
fields = super(CmisConnector, self).get_description_fields() |
49 | 49 |
return [(x[0], x[1]) for x in fields if x[0].name != 'password'] |
50 | 50 | |
51 |
@endpoint(serializer_type='json-api', methods=['post'], perm='can_upload_file')
|
|
51 |
@endpoint(methods=['post'], perm='can_upload_file') |
|
52 | 52 |
def upload_file(self, request, **kwargs): |
53 | 53 |
try: |
54 | 54 |
data = json.loads(request.body) |
... | ... | |
82 | 82 |
except UpdateConflictException: |
83 | 83 |
raise CMISError('the document already exists on platform.') |
84 | 84 | |
85 |
return doc.properties
|
|
85 |
return {'data': doc.properties}
|
|
86 | 86 | |
87 | 87 |
def cmis_connection_repository(self, repo_name): |
88 | 88 |
try: |
passerelle/apps/csvdatasource/models.py | ||
---|---|---|
248 | 248 |
def titles(self): |
249 | 249 |
return [smart_text(t.strip()) for t in self.columns_keynames.split(',')] |
250 | 250 | |
251 |
@endpoint('json-api', perm='can_access', methods=['get'],
|
|
251 |
@endpoint(perm='can_access', methods=['get'], |
|
252 | 252 |
name='query', pattern='^(?P<query_name>[\w-]+)/$') |
253 | 253 |
def select(self, request, query_name, **kwargs): |
254 | 254 |
try: |
... | ... | |
358 | 358 |
if new_row[0]] |
359 | 359 | |
360 | 360 |
if query.structure == 'array': |
361 |
return [[row[t] for t in titles] for row in data]
|
|
361 |
return {'data': [[row[t] for t in titles] for row in data]}
|
|
362 | 362 |
elif query.structure == 'dict': |
363 |
return data
|
|
363 |
return {'data': data}
|
|
364 | 364 |
elif query.structure == 'tuples': |
365 |
return [[[t, row[t]] for t in titles] for row in data]
|
|
365 |
return {'data': [[[t, row[t]] for t in titles] for row in data]}
|
|
366 | 366 |
elif query.structure == 'onerow': |
367 | 367 |
if len(data) != 1: |
368 | 368 |
raise APIError('more or less than one row', data=data) |
369 |
return data[0]
|
|
369 |
return {'data': data[0]}
|
|
370 | 370 |
elif query.structure == 'one': |
371 | 371 |
if len(data) != 1: |
372 | 372 |
raise APIError('more or less than one row', data=data) |
373 | 373 |
if len(data[0]) != 1: |
374 | 374 |
raise APIError('more or less than one column', data=data) |
375 |
return data[0].values()[0]
|
|
375 |
return {'data': data[0].values()[0]}
|
|
376 | 376 | |
377 | 377 |
def export_json(self): |
378 | 378 |
d = super(CsvDataSource, self).export_json() |
passerelle/apps/family/models.py | ||
---|---|---|
244 | 244 |
except FamilyLink.DoesNotExist: |
245 | 245 |
return None |
246 | 246 | |
247 |
@endpoint(serializer_type='json-api', name='family', perm='can_access', pattern='^link/$')
|
|
247 |
@endpoint(name='family', perm='can_access', pattern='^link/$') |
|
248 | 248 |
def family_link(self, request, NameID=None, login=None, password=None, **kwargs): |
249 | 249 |
""" |
250 | 250 |
Links a NameID to a person |
... | ... | |
252 | 252 |
try: |
253 | 253 |
f = Family.objects.get(login=login, password=password, resource=self) |
254 | 254 |
except Family.DoesNotExist: |
255 |
return False
|
|
255 |
return {'data': False}
|
|
256 | 256 |
FamilyLink.objects.get_or_create(resource=self, name_id=NameID, family=f) |
257 |
return True
|
|
257 |
return {'data': True}
|
|
258 | 258 | |
259 |
@endpoint(serializer_type='json-api', name='family', perm='can_access', pattern='^unlink/$')
|
|
259 |
@endpoint(name='family', perm='can_access', pattern='^unlink/$') |
|
260 | 260 |
def family_unlink(self, request, NameID=None, **kwargs): |
261 | 261 |
""" |
262 | 262 |
Unlinks a NameID from a person |
... | ... | |
264 | 264 |
print "Unlink" |
265 | 265 |
try: |
266 | 266 |
FamilyLink.objects.get(resource=self, name_id=NameID).delete() |
267 |
return True
|
|
267 |
return {'data': True}
|
|
268 | 268 |
except FamilyLink.DoesNotExist: |
269 |
return False
|
|
269 |
return {'data': False}
|
|
270 | 270 | |
271 |
@endpoint(serializer_type='json-api', perm='can_access', name='family')
|
|
271 |
@endpoint(perm='can_access', name='family') |
|
272 | 272 |
def family_infos(self, request, NameID, **kwargs): |
273 | 273 |
""" |
274 | 274 |
Displays the information of person's family |
275 | 275 |
""" |
276 | 276 |
family = self.get_family_by_nameid(NameID) |
277 | 277 |
if not family: |
278 |
return |
|
278 |
return {'data': None}
|
|
279 | 279 | |
280 | 280 |
data = {'id': family.get_display_id(), 'adults': [], 'children': []} |
281 | 281 |
for adult in family.adult_set.all(): |
282 | 282 |
data['adults'].append(format_person(adult)) |
283 | 283 |
for child in family.child_set.all(): |
284 | 284 |
data['children'].append(format_person(child)) |
285 |
return data
|
|
285 |
return {'data': data}
|
|
286 | 286 | |
287 |
@endpoint(serializer_type='json-api', name='family', perm='can_access', pattern='^adults/$')
|
|
287 |
@endpoint(name='family', perm='can_access', pattern='^adults/$') |
|
288 | 288 |
def adults_infos(self, request, NameID): |
289 | 289 |
data = self.family_infos(request, NameID) |
290 |
return data['adults']
|
|
290 |
return {'data': data['data']['adults']}
|
|
291 | 291 | |
292 |
@endpoint(serializer_type='json-api', name='family', perm='can_access', pattern='^children/$')
|
|
292 |
@endpoint(name='family', perm='can_access', pattern='^children/$') |
|
293 | 293 |
def children_infos(self, request, NameID, **kwargs): |
294 | 294 |
data = self.family_infos(request, NameID) |
295 |
return data['children']
|
|
295 |
return {'data': data['data']['children']}
|
|
296 | 296 | |
297 | 297 |
def get_invoices(self, NameID, paid=False): |
298 | 298 |
family = self.get_family_by_nameid(NameID) |
... | ... | |
303 | 303 |
invoices.append(format_invoice(i)) |
304 | 304 |
return invoices |
305 | 305 | |
306 |
@endpoint(serializer_type='json-api', name='regie', pattern='^invoices/$')
|
|
306 |
@endpoint(name='regie', pattern='^invoices/$') |
|
307 | 307 |
def active_invoices(self, request, NameID): |
308 |
return self.get_invoices(NameID)
|
|
308 |
return {'data': self.get_invoices(NameID)}
|
|
309 | 309 | |
310 |
@endpoint(serializer_type='json-api', name='regie', perm='can_access', pattern='^invoices/history/$')
|
|
310 |
@endpoint(name='regie', perm='can_access', pattern='^invoices/history/$') |
|
311 | 311 |
def invoices_history(self, request, NameID, **kwargs): |
312 |
return self.get_invoices(NameID, paid=True)
|
|
312 |
return {'data': self.get_invoices(NameID, paid=True)}
|
|
313 | 313 | |
314 | 314 |
def get_invoice(self, invoice_id): |
315 | 315 |
try: |
... | ... | |
317 | 317 |
except Invoice.DoesNotExist: |
318 | 318 |
return None |
319 | 319 | |
320 |
@endpoint(serializer_type='json-api', name='regie', perm='can_access',
|
|
320 |
@endpoint(name='regie', perm='can_access', |
|
321 | 321 |
pattern='^invoice/(?P<invoice_id>\w+)/$') |
322 | 322 |
def get_invoice_details(self, request, invoice_id, NameID=None, email=None, **kwargs): |
323 | 323 |
invoice = self.get_invoice(invoice_id) |
324 | 324 |
if not invoice: |
325 |
return |
|
326 |
return format_invoice(invoice)
|
|
325 |
return {'data': None}
|
|
326 |
return {'data': format_invoice(invoice)}
|
|
327 | 327 | |
328 |
@endpoint(serializer_type='json-api', name='regie', perm='can_access',
|
|
328 |
@endpoint(name='regie', perm='can_access', |
|
329 | 329 |
pattern='^invoice/(?P<invoice_id>\w+)/pdf/$') |
330 | 330 |
def get_invoice_pdf(self, request, invoice_id, **kwargs): |
331 | 331 |
invoice = self.get_invoice(invoice_id) |
... | ... | |
333 | 333 |
raise FileNotFoundError |
334 | 334 |
return invoice.get_pdf() |
335 | 335 | |
336 |
@endpoint(serializer_type='json-api', name='regie', methods=['post'],
|
|
336 |
@endpoint(name='regie', methods=['post'], |
|
337 | 337 |
perm='can_access', pattern='^invoice/(?P<invoice_id>\w+)/pay/$') |
338 | 338 |
def pay_invoice(self, request, invoice_id, **kwargs): |
339 | 339 |
data = json.loads(request.body) |
340 | 340 |
invoice = self.get_invoice(invoice_id) |
341 | 341 |
if not invoice: |
342 |
return False
|
|
342 |
return {'data': False}
|
|
343 | 343 |
transaction_date = get_datetime(data['transaction_date']) |
344 | 344 |
invoice.paid = True |
345 | 345 |
invoice.payment_date = transaction_date |
346 | 346 |
invoice.amount = 0 |
347 | 347 |
invoice.payment_transaction_id = data['transaction_id'] |
348 | 348 |
invoice.save() |
349 |
return True
|
|
349 |
return {'data': True}
|
|
350 | 350 | |
351 | 351 | |
352 | 352 |
class FamilyLink(models.Model): |
passerelle/apps/okina/models.py | ||
---|---|---|
53 | 53 |
else: |
54 | 54 |
return result |
55 | 55 | |
56 |
@endpoint(serializer_type='json-api')
|
|
56 |
@endpoint() |
|
57 | 57 |
def cities(self, request): |
58 | 58 |
okina_cities = self.request('cities') |
59 | 59 |
cities = [] |
... | ... | |
63 | 63 |
city['text'] = '%(nameCity)s (%(zipCode)s)' % city |
64 | 64 |
cities.append(city) |
65 | 65 |
cities.sort(lambda x,y: cmp(x['text'], y['text'])) |
66 |
return cities
|
|
66 |
return {'data': cities}
|
|
67 | 67 | |
68 |
@endpoint(serializer_type='json-api')
|
|
68 |
@endpoint() |
|
69 | 69 |
def classes(self, request): |
70 |
return [{ |
|
70 |
return {'data': [{
|
|
71 | 71 |
'id': '%s' % item['id'], |
72 | 72 |
'text': item['label'] |
73 |
} for item in self.request('classes')] |
|
73 |
} for item in self.request('classes')]}
|
|
74 | 74 | |
75 | 75 |
def get_institutions(self, endpoint=''): |
76 | 76 |
okina_institutions = self.request('institutions' + endpoint) |
... | ... | |
84 | 84 |
institutions.sort(lambda x,y: cmp(x['text'], y['text'])) |
85 | 85 |
return institutions |
86 | 86 | |
87 |
@endpoint(serializer_type='json-api')
|
|
87 |
@endpoint() |
|
88 | 88 |
def institutions(self, request): |
89 |
return self.get_institutions()
|
|
89 |
return {'data': self.get_institutions()}
|
|
90 | 90 | |
91 |
@endpoint(name='institutions', pattern='^from-city/(?P<city_insee_code>\d+)/*$', |
|
92 |
serializer_type='json-api') |
|
91 |
@endpoint(name='institutions', pattern='^from-city/(?P<city_insee_code>\d+)/*$') |
|
93 | 92 |
def institutions_from_city(self, request, city_insee_code): |
94 |
return self.get_institutions('/subscriberCity/%s' % city_insee_code)
|
|
93 |
return {'data': self.get_institutions('/subscriberCity/%s' % city_insee_code)}
|
|
95 | 94 | |
96 | 95 |
@endpoint(name='stop-areas', |
97 |
pattern='^from-city/(?P<city_insee_code>\d+)/to-institution/(?P<institution_id>\d+)/*$', |
|
98 |
serializer_type='json-api') |
|
96 |
pattern='^from-city/(?P<city_insee_code>\d+)/to-institution/(?P<institution_id>\d+)/*$') |
|
99 | 97 |
def stop_areas(self, request, city_insee_code, institution_id): |
100 | 98 |
stops = self.request('stop-areas/subscriberCity/%s/institution/%s' % (city_insee_code, |
101 | 99 |
institution_id)) |
102 | 100 |
for stop in stops: |
103 | 101 |
stop['id'] = '%s' % stop['id'] |
104 | 102 |
stop['text'] = stop['commercial_name'] |
105 |
return stops
|
|
103 |
return {'data': stops}
|
|
106 | 104 | |
107 | 105 |
def get_ods(self, endpoint=''): |
108 | 106 |
# ods = origin/destinations |
... | ... | |
124 | 122 |
'object_id': journey['okinaVehicleJourney']['objectId'], |
125 | 123 |
'identifier': identifier |
126 | 124 |
}) |
127 |
return ods
|
|
125 |
return {'data': ods}
|
|
128 | 126 | |
129 |
@endpoint(name='origin-destinations', serializer_type='json-api')
|
|
127 |
@endpoint(name='origin-destinations') |
|
130 | 128 |
def origin_destinations(self, request): |
131 | 129 |
return self.get_ods() |
132 | 130 | |
133 | 131 |
@endpoint(name='origin-destinations', |
134 |
pattern='^to-institution/(?P<institution_id>\d+)/*$', |
|
135 |
serializer_type='json-api') |
|
132 |
pattern='^to-institution/(?P<institution_id>\d+)/*$') |
|
136 | 133 |
def origin_destinations_to_institution(self, request, institution_id): |
137 | 134 |
return self.get_ods('/institution/%s' % institution_id) |
138 | 135 | |
139 | 136 |
@endpoint(name='origin-destinations', |
140 |
pattern='^from-stop-area/(?P<stop_area_id>\d+)/to-institution/(?P<institution_id>\d+)/*$', |
|
141 |
serializer_type='json-api') |
|
137 |
pattern='^from-stop-area/(?P<stop_area_id>\d+)/to-institution/(?P<institution_id>\d+)/*$') |
|
142 | 138 |
def origin_destinations_from_stop_to_institution(self, request, stop_area_id, institution_id): |
143 | 139 |
endpoint = 'ods/institution/%s/stop-area/%s' % (institution_id, stop_area_id) |
144 | 140 |
okina_journeys = self.request(endpoint) |
... | ... | |
153 | 149 |
} for line in okina_journey], |
154 | 150 |
} |
155 | 151 |
journeys.append(journey) |
156 |
return journeys
|
|
152 |
return {'data': journeys}
|
|
157 | 153 | |
158 | 154 |
@endpoint(name='origin-destinations', |
159 |
pattern='^from-city/(?P<city_insee_code>\d+)/to-institution/(?P<institution_id>\d+)/*$', |
|
160 |
serializer_type='json-api') |
|
155 |
pattern='^from-city/(?P<city_insee_code>\d+)/to-institution/(?P<institution_id>\d+)/*$') |
|
161 | 156 |
def origin_destinations_from_city_to_institution(self, request, city_insee_code, institution_id): |
162 | 157 |
return self.get_ods('/institution/%s/subscriberCity/%s' % (institution_id, city_insee_code)) |
163 | 158 | |
164 | 159 |
@endpoint(name='origin-destinations', |
165 |
pattern='^from-city/(?P<city_insee_code>\d+)/*$', |
|
166 |
serializer_type='json-api') |
|
160 |
pattern='^from-city/(?P<city_insee_code>\d+)/*$') |
|
167 | 161 |
def origin_destinations_from_city(self, request, city_insee_code): |
168 | 162 |
return self.get_ods('/subscriberCity/%s' % city_insee_code) |
169 | 163 | |
170 |
@endpoint(name='topology', pattern='^(?P<kind>(lines|networks|vehicle-journeys))/*$', |
|
171 |
serializer_type='json-api') |
|
164 |
@endpoint(name='topology', pattern='^(?P<kind>(lines|networks|vehicle-journeys))/*$') |
|
172 | 165 |
def topology(self, request, kind): |
173 |
return [{ |
|
166 |
return {'data': [{
|
|
174 | 167 |
'id': '%s' % item['id'], |
175 | 168 |
'text': item['name'] |
176 |
} for item in self.request('topology/%s' % kind)] |
|
169 |
} for item in self.request('topology/%s' % kind)]}
|
|
177 | 170 | |
178 |
@endpoint(name='subscriber', serializer_type='json-api', methods=['post'], perm='can_access')
|
|
171 |
@endpoint(name='subscriber', methods=['post'], perm='can_access') |
|
179 | 172 |
def create_subscriber(self, request): |
180 | 173 |
try: |
181 | 174 |
payload = json.loads(request.body) |
... | ... | |
183 | 176 |
raise APIError('payload must be a JSON object', http_status=400) |
184 | 177 |
if not isinstance(payload, dict): |
185 | 178 |
raise APIError('payload must be a dict', http_status=400) |
186 |
return self.request('subscribers', payload)
|
|
179 |
return {'data': self.request('subscribers', payload)}
|
|
187 | 180 | |
188 | 181 |
@endpoint(name='subscriber', pattern='^(?P<subscriber_id>\d+)/*$', |
189 |
serializer_type='json-api', methods=['get'], perm='can_access')
|
|
182 |
methods=['get'], perm='can_access') |
|
190 | 183 |
def get_subscriber(self, request, subscriber_id): |
191 |
return self.request('subscribers/%s' % subscriber_id)
|
|
184 |
return {'data': self.request('subscribers/%s' % subscriber_id)}
|
|
192 | 185 | |
193 | 186 |
@endpoint(name='subscriber', pattern='^(?P<subscriber_id>\d+)/qrcode/*$', |
194 |
serializer_type='json-api', perm='can_access')
|
|
187 |
perm='can_access') |
|
195 | 188 |
def get_subscriber_qrcode(self, request, subscriber_id): |
196 | 189 |
qrcode = self.request('subscribers/%s/qrcode' % subscriber_id, result_is_json=False) |
197 | 190 |
content_type = qrcode.headers.get('Content-Type') |
... | ... | |
202 | 195 |
err=response['code']) |
203 | 196 |
return HttpResponse(qrcode.content, content_type=content_type) |
204 | 197 | |
205 |
@endpoint(name='subscription', serializer_type='json-api', methods=['post'], perm='can_access')
|
|
198 |
@endpoint(name='subscription', methods=['post'], perm='can_access') |
|
206 | 199 |
def create_subscription(self, request): |
207 | 200 |
try: |
208 | 201 |
payload = json.loads(request.body) |
... | ... | |
210 | 203 |
raise APIError('payload must be a JSON object', http_status=400) |
211 | 204 |
if not isinstance(payload, dict): |
212 | 205 |
raise APIError('payload must be a dict', http_status=400) |
213 |
return self.request('subscriptions', payload)
|
|
206 |
return {'data': self.request('subscriptions', payload)}
|
|
214 | 207 | |
215 | 208 |
@endpoint(name='subscription', pattern='^(?P<subscription_id>\d+)/*$', |
216 |
serializer_type='json-api', methods=['get'], perm='can_access')
|
|
209 |
methods=['get'], perm='can_access') |
|
217 | 210 |
def get_subscription(self, request, subscription_id): |
218 |
return self.request('subscriptions/%s' % subscription_id) |
|
211 |
return {'data': self.request('subscriptions/%s' % subscription_id)} |
passerelle/contrib/arcgis/models.py | ||
---|---|---|
37 | 37 |
def get_icon_class(cls): |
38 | 38 |
return 'gis' |
39 | 39 | |
40 |
@endpoint(serializer_type='json-api')
|
|
40 |
@endpoint() |
|
41 | 41 |
def district(self, request, lon=None, lat=None): |
42 | 42 |
if lon and lat: |
43 | 43 |
try: |
... | ... | |
79 | 79 |
{'id': feature['attributes'].get('NUMERO'), 'text': feature['attributes'].get('NOM')} for feature in features] |
80 | 80 | |
81 | 81 |
if len(data) == 1: |
82 |
return data[0] |
|
83 |
return data |
|
82 |
return {'data': data[0]} |
|
83 |
return {'data': data} |
passerelle/contrib/greco/models.py | ||
---|---|---|
118 | 118 |
return Client(url=self.wsdl_url, transport=Transport(self)) |
119 | 119 | |
120 | 120 | |
121 |
@endpoint(serializer_type='json-api', perm='can_access')
|
|
121 |
@endpoint(perm='can_access') |
|
122 | 122 |
def ping(self, request): |
123 |
return self.get_client().service.communicationTest('ping')
|
|
123 |
return {'data': self.get_client().service.communicationTest('ping')}
|
|
124 | 124 | |
125 |
@endpoint(serializer_type='json-api', perm='can_access', methods=['post'])
|
|
125 |
@endpoint(perm='can_access', methods=['post']) |
|
126 | 126 |
def create(self, request): |
127 | 127 |
# get creation fields from payload |
128 | 128 |
try: |
... | ... | |
136 | 136 |
fill_sudsobject_with_dict(creation, formdata.fields) |
137 | 137 |
# send it to "creer" |
138 | 138 |
resp = client.service.creer(creation) |
139 |
return sudsobject_to_dict(resp)
|
|
139 |
return {'data': sudsobject_to_dict(resp)}
|
|
140 | 140 | |
141 | 141 |
@classmethod |
142 | 142 |
def creation_fields(cls): |
143 | 143 |
'''used in greco_detail.html template''' |
144 | 144 |
return list_schema_fields(CREATION_SCHEMA) |
145 | 145 | |
146 |
@endpoint(serializer_type='json-api', perm='can_access')
|
|
146 |
@endpoint(perm='can_access') |
|
147 | 147 |
def status(self, request, iddemande, idgreco): |
148 | 148 |
resp = self.get_client().service.consulter({ |
149 | 149 |
'idgreco': idgreco, |
150 | 150 |
'iddemande': iddemande, |
151 | 151 |
}) |
152 |
return sudsobject_to_dict(resp)
|
|
152 |
return {'data': sudsobject_to_dict(resp)}
|
|
153 | 153 | |
154 |
@endpoint(name='add-information', serializer_type='json-api', perm='can_access',
|
|
154 |
@endpoint(name='add-information', perm='can_access', |
|
155 | 155 |
methods=['get', 'post', 'put', 'patch']) |
156 | 156 |
def add_information(self, request, iddemande=None, idgreco=None, information=None): |
157 | 157 |
if request.body: |
... | ... | |
166 | 166 |
'iddemande': iddemande, |
167 | 167 |
'complementInfo': information, |
168 | 168 |
}) |
169 |
return sudsobject_to_dict(resp)
|
|
169 |
return {'data': sudsobject_to_dict(resp)}
|
|
170 | 170 | |
171 |
@endpoint(serializer_type='json-api', perm='can_access',
|
|
171 |
@endpoint(perm='can_access', |
|
172 | 172 |
methods=['get', 'post', 'put', 'patch']) |
173 | 173 |
def update(self, request, iddemande=None, idgreco=None, comment=None): |
174 | 174 |
if request.body: |
... | ... | |
183 | 183 |
'iddemande': iddemande, |
184 | 184 |
'commentaire': comment, |
185 | 185 |
}) |
186 |
return sudsobject_to_dict(resp) |
|
186 |
return {'data': sudsobject_to_dict(resp)} |
passerelle/contrib/iparapheur/models.py | ||
---|---|---|
75 | 75 |
def get_verbose_name(cls): |
76 | 76 |
return cls._meta.verbose_name |
77 | 77 | |
78 |
@endpoint(serializer_type='json-api', perm='can_access')
|
|
78 |
@endpoint(perm='can_access') |
|
79 | 79 |
def types(self, request): |
80 | 80 |
c = get_client(self) |
81 |
return [format_type(t) for t in c.service.GetListeTypes()]
|
|
81 |
return {'data': [format_type(t) for t in c.service.GetListeTypes()]}
|
|
82 | 82 | |
83 |
@endpoint(serializer_type='json-api', perm='can_access')
|
|
83 |
@endpoint(perm='can_access') |
|
84 | 84 |
def ping(self, request): |
85 | 85 |
c = get_client(self) |
86 |
return c.service.echo('ping')
|
|
86 |
return {'data': c.service.echo('ping')}
|
|
87 | 87 | |
88 |
@endpoint(serializer_type='json-api', perm='can_access')
|
|
88 |
@endpoint(perm='can_access') |
|
89 | 89 |
def subtypes(self, request, type=None): |
90 | 90 |
c = get_client(self) |
91 | 91 |
if type: |
92 |
return [format_type(t) for t in c.service.GetListeSousTypes(type)]
|
|
93 |
return [format_type(t) for t in c.service.GetListeSousTypes()]
|
|
92 |
return {'data': [format_type(t) for t in c.service.GetListeSousTypes(type)]}
|
|
93 |
return {'data': [format_type(t) for t in c.service.GetListeSousTypes()]}
|
|
94 | 94 | |
95 |
@endpoint(serializer_type='json-api', perm='can_access')
|
|
95 |
@endpoint(perm='can_access') |
|
96 | 96 |
def files(self, request, status=None): |
97 | 97 |
c = get_client(self) |
98 | 98 |
if status: |
99 |
return [format_file(f) for f in c.service.RechercherDossiers(Status=status)]
|
|
100 |
return [format_file(f) for f in c.service.RechercherDossiers()]
|
|
99 |
return {'data': [format_file(f) for f in c.service.RechercherDossiers(Status=status)]}
|
|
100 |
return {'data': [format_file(f) for f in c.service.RechercherDossiers()]}
|
|
101 | 101 | |
102 |
@endpoint(serializer_type='json-api', perm='can_access', name='create-file', methods=['post'])
|
|
102 |
@endpoint(perm='can_access', name='create-file', methods=['post']) |
|
103 | 103 |
def create_file(self, request, email=None): |
104 | 104 |
data = json.loads(request.body) |
105 | 105 |
title = data['title'] |
... | ... | |
130 | 130 |
r = c.service.CreerDossier(**d) |
131 | 131 |
if r.MessageRetour.codeRetour == 'KO': |
132 | 132 |
raise FileError(r.MessageRetour.message) |
133 |
return {'RecordId': r.DossierID, |
|
134 |
'message': r.MessageRetour.message} |
|
133 |
return {'data': {'RecordId': r.DossierID, 'message': r.MessageRetour.message}} |
|
135 | 134 | |
136 |
@endpoint(serializer_type='json-api', perm='can_access', name='get-file', pattern='(?P<file_id>[\w-]+)')
|
|
135 |
@endpoint(perm='can_access', name='get-file', pattern='(?P<file_id>[\w-]+)') |
|
137 | 136 |
def get_file(self, request, file_id): |
138 | 137 |
client = get_client(self) |
139 | 138 |
resp = client.service.GetDossier(file_id) |
... | ... | |
146 | 145 |
return HttpResponse(base64.b64decode(fichier['value']), |
147 | 146 |
content_type=fichier['_contentType']) |
148 | 147 | |
149 |
@endpoint(serializer_type='json-api', perm='can_access', name='get-file-status', pattern='(?P<file_id>[\w-]+)')
|
|
148 |
@endpoint(perm='can_access', name='get-file-status', pattern='(?P<file_id>[\w-]+)') |
|
150 | 149 |
def get_file_status(self, request, file_id): |
151 | 150 |
c = get_client(self) |
152 | 151 |
resp = c.service.GetHistoDossier(file_id) |
... | ... | |
155 | 154 |
raise Http404(resp.MessageRetour.message) |
156 | 155 |
raise FileError(resp.MessageRetour.message) |
157 | 156 |
last = resp.LogDossier[-1] |
158 |
return {'annotation': last.annotation, 'nom': last.nom, |
|
157 |
return {'data': { |
|
158 |
'annotation': last.annotation, 'nom': last.nom, |
|
159 | 159 |
'status': last.status, 'timestamp': last.timestamp |
160 |
} |
|
160 |
}} |
passerelle/contrib/mdel/models.py | ||
---|---|---|
84 | 84 |
def get_verbose_name(cls): |
85 | 85 |
return cls._meta.verbose_name |
86 | 86 | |
87 |
@endpoint(serializer_type='json-api', perm='can_access', methods=['post'])
|
|
87 |
@endpoint(perm='can_access', methods=['post']) |
|
88 | 88 |
def create(self, request, *args, **kwargs): |
89 | 89 |
"""Create a demand |
90 | 90 |
""" |
... | ... | |
121 | 121 | |
122 | 122 |
demand.save() |
123 | 123 | |
124 |
return {'demand_id': demand.demand_id}
|
|
124 |
return {'data': {'demand_id': demand.demand_id}}
|
|
125 | 125 | |
126 |
@endpoint(serializer_type='json-api', perm='can_access')
|
|
126 |
@endpoint(perm='can_access') |
|
127 | 127 |
def status(self, request, *args, **kwargs): |
128 | 128 |
"""Return demand's statutes |
129 | 129 |
""" |
... | ... | |
136 | 136 |
status = demand.get_status() |
137 | 137 | |
138 | 138 |
demand.save() |
139 |
return status
|
|
139 |
return {'data': status}
|
|
140 | 140 | |
141 |
@endpoint(serializer_type='json-api', perm='can_access')
|
|
141 |
@endpoint(perm='can_access') |
|
142 | 142 |
def applicants(self, request, without=''): |
143 |
return [item for item in APPLICANTS |
|
144 |
if item.get('id') not in without.split(',')] |
|
143 |
return {'data': [item for item in APPLICANTS
|
|
144 |
if item.get('id') not in without.split(',')]}
|
|
145 | 145 | |
146 |
@endpoint(serializer_type='json-api', perm='can_access')
|
|
146 |
@endpoint(perm='can_access') |
|
147 | 147 |
def certificates(self, request): |
148 |
return CERTIFICATES
|
|
148 |
return {'data': CERTIFICATES}
|
|
149 | 149 | |
150 |
@endpoint(name='certificate-types', serializer_type='json-api', perm='can_access')
|
|
150 |
@endpoint(name='certificate-types', perm='can_access') |
|
151 | 151 |
def certificate_types(self, request, without=''): |
152 |
return [item for item in CERTIFICATE_TYPES |
|
153 |
if item.get('id') not in without.split(',')] |
|
152 |
return {'data': [item for item in CERTIFICATE_TYPES
|
|
153 |
if item.get('id') not in without.split(',')]}
|
|
154 | 154 | |
155 | 155 | |
156 | 156 |
class Demand(models.Model): |
passerelle/contrib/nancypoll/models.py | ||
---|---|---|
31 | 31 |
def get_icon_class(cls): |
32 | 32 |
return 'grid' |
33 | 33 | |
34 |
@endpoint(serializer_type='json-api')
|
|
34 |
@endpoint() |
|
35 | 35 |
def data(self, request, *args, **kwargs): |
36 | 36 |
street_no = request.GET.get('street_no') |
37 | 37 |
street_name = request.GET.get('street_name') |
... | ... | |
71 | 71 |
if row[idx_side] == 'P' and int(street_no) % 2 == 1: |
72 | 72 |
continue |
73 | 73 | |
74 |
return { |
|
74 |
return {'data': {
|
|
75 | 75 |
'id': row[titles.index('id')], |
76 | 76 |
'text': row[titles.index('text')], |
77 | 77 |
'code': row[titles.index('code')], |
78 | 78 |
'address': row[titles.index('address')], |
79 | 79 |
'canton': row[titles.index('canton')], |
80 |
} |
|
80 |
}}
|
|
81 | 81 | |
82 | 82 |
raise APIError('Polling Station Not Found') |
83 | 83 |
passerelle/sms/__init__.py | ||
---|---|---|
33 | 33 |
numbers.append(number) |
34 | 34 |
return numbers |
35 | 35 | |
36 |
@endpoint('json-api', perm='can_send_messages', methods=['post'])
|
|
36 |
@endpoint(perm='can_send_messages', methods=['post']) |
|
37 | 37 |
def send(self, request, *args, **kwargs): |
38 | 38 |
try: |
39 | 39 |
data = json.loads(request.body) |
... | ... | |
50 | 50 |
logging.info('sending message %r to %r with sending number %r', |
51 | 51 |
data['message'], data['to'], data['from']) |
52 | 52 |
if 'nostop' in request.GET: |
53 |
return self.send_msg(data['message'], data['from'], data['to'], stop=False) |
|
54 |
return self.send_msg(data['message'], data['from'], data['to'], stop=True) |
|
53 |
return {'data': self.send_msg(data['message'], data['from'], data['to'], stop=False)} |
|
54 |
return {'data': self.send_msg(data['message'], data['from'], data['to'], stop=True)} |
passerelle/utils/api.py | ||
---|---|---|
16 | 16 | |
17 | 17 | |
18 | 18 |
class endpoint(object): |
19 |
def __init__(self, serializer_type='json', perm=None, methods=['get'], name=None, pattern=None, |
|
20 |
wrap_response=True):
|
|
19 |
def __init__(self, serializer_type='json-api', perm=None, methods=['get'], name=None, pattern=None,
|
|
20 |
wrap_response=False):
|
|
21 | 21 |
self.perm = perm |
22 | 22 |
self.methods = methods |
23 | 23 |
self.serializer_type = serializer_type |
passerelle/utils/jsonresponse.py | ||
---|---|---|
309 | 309 |
d.update({"data": obj}) |
310 | 310 |
return d |
311 | 311 |
else: |
312 |
if isinstance(obj, dict) and not 'err' in obj: |
|
313 |
obj['err'] = 0 |
|
312 | 314 |
return obj |
313 | 315 | |
314 | 316 |
def err_to_response(self, err): |
tests/test_base_adresse.py | ||
---|---|---|
50 | 50 | |
51 | 51 |
def test_base_adresse_search_qs_parameters_error(app, base_adresse, |
52 | 52 |
mock_api_adresse_data_gouv_fr_search): |
53 |
# plain serializer
|
|
54 |
with pytest.raises(WrongParameter):
|
|
55 |
app.get('/base-adresse/%s/search' % base_adresse.slug, status=400)
|
|
53 |
resp = app.get('/base-adresse/%s/search' % base_adresse.slug, status=400)
|
|
54 |
assert resp.json['err'] == 1
|
|
55 |
assert resp.json['err_class'] == 'passerelle.views.WrongParameter'
|
|
56 | 56 |
# json-api serializer |
57 | 57 |
resp = app.get('/base-adresse/%s/streets?zipcode=13400&coin=zz' % base_adresse.slug, status=400) |
58 | 58 |
assert resp.json['err'] == 1 |
tests/test_jsondatastore.py | ||
---|---|---|
27 | 27 | |
28 | 28 |
def test_jsondatastore(app, jsondatastore, jsondatastore2): |
29 | 29 |
resp = app.get('/jsondatastore/foobar/data/') |
30 |
assert resp.json == {'data': []} |
|
30 |
assert resp.json == {'data': [], 'err': 0}
|
|
31 | 31 | |
32 | 32 |
resp = app.post_json('/jsondatastore/foobar/data/create', params={'foo': 'bar'}) |
33 | 33 |
uuid = resp.json['id'] |
... | ... | |
62 | 62 | |
63 | 63 |
def test_jsondatastore_name_id(app, jsondatastore): |
64 | 64 |
resp = app.get('/jsondatastore/foobar/data/') |
65 |
assert resp.json == {'data': []} |
|
65 |
assert resp.json == {'data': [], 'err': 0}
|
|
66 | 66 | |
67 | 67 |
resp = app.post_json('/jsondatastore/foobar/data/create?name_id=xxx', params={'foo': 'bar'}) |
68 | 68 |
uuid = resp.json['id'] |
tests/test_jsonresponse.py | ||
---|---|---|
143 | 143 |
return {"foo": "bar"} |
144 | 144 |
result = test_func(req) |
145 | 145 |
data = json.loads(result.content) |
146 |
assert data == {"foo": "bar"} |
|
146 |
assert data == {"foo": "bar", "err": 0}
|
|
147 | 147 | |
148 | 148 |
def test_jsonresponse_with_callback(): |
149 | 149 |
request = RequestFactory() |
150 |
- |