Projet

Général

Profil

0003-base_adresse-move-endpoint-documentation-to-decorato.patch

Valentin Deniaud, 06 décembre 2019 12:49

Télécharger (4,26 ko)

Voir les différences:

Subject: [PATCH 3/6] base_adresse: move endpoint documentation to decorator
 (#11497)

 passerelle/apps/base_adresse/models.py        | 26 ++++++++++++++++---
 .../base_adresse/baseadresse_detail.html      | 19 --------------
 2 files changed, 23 insertions(+), 22 deletions(-)
passerelle/apps/base_adresse/models.py
26 26

  
27 27
    category = _('Geographic information system')
28 28

  
29
    api_description = _("The API is a partial view of OpenStreetMap's Nominatim "
30
                        "own API; it currently doesn't support all parameters and "
31
                        "is limited to the JSON format.")
32

  
29 33
    zipcode = models.CharField(
30 34
        max_length=600,
31 35
        blank=True,
......
34 38
    class Meta:
35 39
        verbose_name = _('Base Adresse Web Service')
36 40

  
37
    @endpoint(pattern='(?P<q>.+)?$')
41
    @endpoint(pattern='(?P<q>.+)?$',
42
              description=_('Geocoding'),
43
              parameters={
44
                  'q': {'description': _('Address'), 'example_value': '169 rue du chateau, paris'}
45
              })
38 46
    def search(self, request, q, zipcode='', lat=None, lon=None, **kwargs):
39 47
        if kwargs.get('format', 'json') != 'json':
40 48
            raise NotImplementedError()
......
68 76

  
69 77
        return result
70 78

  
71
    @endpoint()
79
    @endpoint(description=_('Reverse geocoding'),
80
              parameters={
81
                  'lat': {'description': _('Latitude'), 'example_value': 48.833708},
82
                  'lon': {'description': _('Longitude'), 'example_value': 2.323349},
83
              })
72 84
    def reverse(self, request, lat, lon, **kwargs):
73 85
        if kwargs.get('format', 'json') != 'json':
74 86
            raise NotImplementedError()
......
103 115
                    result['address']['road'] = value
104 116
        return result
105 117

  
106
    @endpoint()
118
    @endpoint(description=_('Streets from zipcode'),
119
              parameters={
120
                  'id': {'description': _('Get exactly one street')},
121
                  'q': {'description': _("Street name")},
122
                  'zipcode': {'description': _('Zipcode')},
123
                  'page_limit': {'description': _('Maximum number of results to return'),
124
                                 'example_value': 30},
125
                  'distinct': {'description': _('Remove duplicate streets')},
126
              })
107 127
    def streets(self, request, zipcode=None, q=None, id=None, distinct=True, page_limit=None):
108 128
        result = []
109 129
        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>&amp;format=json</li>
25
<li>{% trans 'Reverse geocoding:' %} <a href="reverse?lat=48.833708&amp;lon=2.323349&amp;format=json"
26
  >{{ site_base_uri }}{{ object.get_absolute_url }}reverse</a>?lat=<i>lat</i>&amp;lon=<i>lon</i>&amp;format=json</li>
27
<li>{% trans 'Streets from zipcode:' %} <a href="streets?zipcode={{object.zipcode}}&amp;format=json"
28
  >{{ site_base_uri }}{{ object.get_absolute_url }}streets</a>?zipcode=<i>zipcode</i>&amp;format=json</li>
29
</ul>
30
{% endblock %}
31

  
32 13
{% block security %}
33 14
<p>
34 15
{% trans 'Accessing the listings is open.' %}
35
-