0003-base_adresse-move-endpoint-documentation-to-decorato.patch
passerelle/apps/base_adresse/models.py | ||
---|---|---|
25 | 25 | |
26 | 26 |
category = _('Geographic information system') |
27 | 27 | |
28 |
api_description = _("The API is a partial view of OpenStreetMap's Nominatim " |
|
29 |
"own API; it currently doesn't support all parameters and " |
|
30 |
"is limited to the JSON format.") |
|
31 | ||
28 | 32 |
zipcode = models.CharField( |
29 | 33 |
max_length=600, |
30 | 34 |
blank=True, |
... | ... | |
33 | 37 |
class Meta: |
34 | 38 |
verbose_name = _('Base Adresse Web Service') |
35 | 39 | |
36 |
@endpoint(pattern='(?P<q>.+)?$') |
|
40 |
@endpoint(pattern='(?P<q>.+)?$', |
|
41 |
description=_('Geocoding'), |
|
42 |
parameters={ |
|
43 |
'q': {'description': _('Address'), 'example_value': '169 rue du chateau, paris'} |
|
44 |
}) |
|
37 | 45 |
def search(self, request, q, zipcode='', lat=None, lon=None, **kwargs): |
38 | 46 |
if kwargs.get('format', 'json') != 'json': |
39 | 47 |
raise NotImplementedError() |
... | ... | |
67 | 75 | |
68 | 76 |
return result |
69 | 77 | |
70 |
@endpoint() |
|
78 |
@endpoint(description=_('Reverse geocoding'), |
|
79 |
parameters={ |
|
80 |
'lat': {'description': _('Latitude'), 'example_value': 48.833708}, |
|
81 |
'lon': {'description': _('Longitude'), 'example_value': 2.323349}, |
|
82 |
}) |
|
71 | 83 |
def reverse(self, request, lat, lon, **kwargs): |
72 | 84 |
if kwargs.get('format', 'json') != 'json': |
73 | 85 |
raise NotImplementedError() |
... | ... | |
102 | 114 |
result['address']['road'] = value |
103 | 115 |
return result |
104 | 116 | |
105 |
@endpoint() |
|
117 |
@endpoint(description=_('Streets from zipcode'), |
|
118 |
parameters={ |
|
119 |
'q': {'description': _("Street name")}, |
|
120 |
'zipcode': {'description': _('Zipcode')}, |
|
121 |
'page_limit': {'description': _('Maximum number of results to return'), |
|
122 |
'example_value': 30}, |
|
123 |
'distinct': {'description': _('Remove duplicate streets')}, |
|
124 |
}) |
|
106 | 125 |
def streets(self, request, zipcode=None, q=None, id=None, distinct=True, page_limit=None): |
107 | 126 |
result = [] |
108 | 127 |
if id is not None: |
passerelle/apps/base_adresse/templates/base_adresse/baseadresse_detail.html | ||
---|---|---|
10 | 10 |
{% endif %} |
11 | 11 |
{% endblock %} |
12 | 12 | |
13 |
{% block endpoints %} |
|
14 |
<p> |
|
15 |
{% blocktrans %} |
|
16 |
The API is a partial view of <a href="http://wiki.openstreetmap.org/wiki/Nominatim">Nominatim</a> |
|
17 |
own API; it currently doesn't support all parameters and is limited to the JSON |
|
18 |
format. |
|
19 |
{% endblocktrans %} |
|
20 |
</p> |
|
21 | ||
22 |
<ul> |
|
23 |
<li>{% trans 'Geocoding:' %} <a href="search?q=169 rue du chateau, paris&format=json" |
|
24 |
>{{ site_base_uri }}{{ object.get_absolute_url }}search</a>?q=<i>q</i>&format=json</li> |
|
25 |
<li>{% trans 'Reverse geocoding:' %} <a href="reverse?lat=48.833708&lon=2.323349&format=json" |
|
26 |
>{{ site_base_uri }}{{ object.get_absolute_url }}reverse</a>?lat=<i>lat</i>&lon=<i>lon</i>&format=json</li> |
|
27 |
<li>{% trans 'Streets from zipcode:' %} <a href="streets?zipcode={{object.zipcode}}&format=json" |
|
28 |
>{{ site_base_uri }}{{ object.get_absolute_url }}streets</a>?zipcode=<i>zipcode</i>&format=json</li> |
|
29 |
</ul> |
|
30 |
{% endblock %} |
|
31 | ||
32 | 13 |
{% block security %} |
33 | 14 |
<p> |
34 | 15 |
{% trans 'Accessing the listings is open.' %} |
35 |
- |