0001-generic-endpoint-define-optional-category-for-displa.patch
passerelle/base/models.py | ||
---|---|---|
135 | 135 |
# permission descriptions |
136 | 136 |
_can_access_description = _('Access is limited to the following API users:') |
137 | 137 | |
138 |
# category ordering for display |
|
139 |
_category_ordering = [] |
|
140 | ||
138 | 141 |
class Meta: |
139 | 142 |
abstract = True |
140 | 143 | |
... | ... | |
256 | 259 |
endpoint_info = copy.copy(method.endpoint_info) |
257 | 260 |
endpoint_info.http_method = http_method |
258 | 261 |
endpoints.append(endpoint_info) |
259 |
endpoints.sort(key=lambda x: (x.display_order or 99999999, x.name or '', x.pattern or '')) |
|
262 |
endpoints.sort(key=lambda x: (x.display_category_order, x.display_category, x.display_order or 99999999, x.name or '', x.pattern or ''))
|
|
260 | 263 |
if hasattr(self, 'queries'): |
261 | 264 |
self.append_custom_queries(endpoints) |
262 | 265 |
return endpoints |
passerelle/templates/passerelle/manage/service_view.html | ||
---|---|---|
64 | 64 |
{% block endpoints %} |
65 | 65 |
<ul class="endpoints"> |
66 | 66 |
{% for endpoint in object.get_endpoints_infos %} |
67 |
{% ifchanged endpoint.display_category %} |
|
68 |
{% if endpoint.display_category %} |
|
69 |
</ul> |
|
70 |
<h4><span class="description">{{ endpoint.display_category }}</h4> |
|
71 |
<ul class="endpoints"> |
|
72 |
{% endif %} |
|
73 |
{% endifchanged %} |
|
67 | 74 |
{% if endpoint.show %} |
68 | 75 |
{% include "passerelle/manage/endpoint.html" with endpoint=endpoint %} |
69 | 76 |
{% endif %} |
passerelle/utils/api.py | ||
---|---|---|
45 | 45 |
post=None, |
46 | 46 |
show=True, |
47 | 47 |
show_undocumented_params=True, |
48 |
display_order=0): |
|
48 |
display_order=0, |
|
49 |
display_category=''): |
|
49 | 50 |
self.perm = perm |
50 | 51 |
self.methods = methods |
51 | 52 |
self.serializer_type = serializer_type |
... | ... | |
75 | 76 |
self.show = show |
76 | 77 |
self.show_undocumented_params = show_undocumented_params |
77 | 78 |
self.display_order = display_order |
79 |
self.display_category = display_category |
|
78 | 80 | |
79 | 81 |
def __call__(self, func): |
80 | 82 |
func.endpoint_info = self |
... | ... | |
83 | 85 |
self.func = func |
84 | 86 |
return func |
85 | 87 | |
88 |
@property |
|
89 |
def display_category_order(self): |
|
90 |
if not self.display_category: |
|
91 |
# not category, put it at the begining |
|
92 |
return 0 |
|
93 |
# self.object is attached in BaseResource.get_endpoints_infos method |
|
94 |
if self.display_category not in self.object._category_ordering: |
|
95 |
# category without ordering, put it at the end |
|
96 |
return 99999999 |
|
97 |
return self.object._category_ordering.index(self.display_category) |
|
98 | ||
86 | 99 |
def get_example_params(self): |
87 | 100 |
return dict([(x, self.parameters[x]['example_value']) for x in self.parameters or {} |
88 | 101 |
if x in self.parameters and 'example_value' in self.parameters[x]]) |
tests/test_generic_endpoint.py | ||
---|---|---|
752 | 752 |
pass |
753 | 753 | |
754 | 754 | |
755 |
class DummyConnectorWithOrderingAndCategory(DummyConnectorBase): |
|
756 |
_category_ordering = ['Foo', 'Bar'] |
|
757 | ||
758 |
@endpoint(display_category='Foo') |
|
759 |
def a(self, request): |
|
760 |
pass |
|
761 | ||
762 |
@endpoint(display_category='Bar', display_order=2) |
|
763 |
def b(self, request): |
|
764 |
pass |
|
765 | ||
766 |
@endpoint() |
|
767 |
def c(self, request): |
|
768 |
pass |
|
769 | ||
770 |
@endpoint(display_category='Bar', display_order=1) |
|
771 |
def d(self, request): |
|
772 |
pass |
|
773 | ||
774 |
@endpoint(display_category='Blah') |
|
775 |
def e(self, request): |
|
776 |
pass |
|
777 | ||
778 | ||
755 | 779 |
@pytest.mark.parametrize('connector_class, expected_ordering', [ |
756 | 780 |
(DummyConnectorWithoutOrdering, ['a', 'b', 'caa', 'cbb']), |
757 | 781 |
(DummyConnectorWithOrdering, ['caa', 'cbb', 'a', 'b']), |
782 |
(DummyConnectorWithOrderingAndCategory, ['c', 'a', 'd', 'b', 'e']), |
|
758 | 783 |
]) |
759 | 784 |
def test_generic_up_in_endpoints_ordering(db, app, connector_class, expected_ordering): |
760 | 785 |
connector = connector_class() |
761 |
- |