Skip to content

Commit

Permalink
Merge pull request #50 in SWFT/django-rql from ~MKOLYUBYAKIN/django-r…
Browse files Browse the repository at this point in the history
…ql:feature/LITE-13699 to master

* commit '28bf0f80515354b4b568b914b3b0d5f80eff7cd2':
  Added support for default: hidden in OpenAPI spec.
  • Loading branch information
maxipavlovic committed May 21, 2020
2 parents 83ef2fa + 28bf0f8 commit de54f67
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dj_rql/filter_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def _build_filters(self, filters, filter_route='', orm_route='',
field = item.get('field')
kwargs = {
prop: item.get(prop)
for prop in ('lookups', 'use_repr', 'null_values', 'distinct', 'openapi')
for prop in ('lookups', 'use_repr', 'null_values', 'distinct', 'openapi', 'hidden')
}

if 'sources' in item:
Expand Down Expand Up @@ -644,6 +644,7 @@ def _build_mapped_item(cls, field, field_orm_route, **kwargs):
null_values = kwargs.get('null_values')
distinct = kwargs.get('distinct')
openapi = kwargs.get('openapi')
hidden = kwargs.get('hidden')

possible_lookups = lookups or FilterTypes.default_field_filter_lookups(field)
if not (field.null or cls._is_pk_field(field)):
Expand All @@ -655,6 +656,7 @@ def _build_mapped_item(cls, field, field_orm_route, **kwargs):
'lookups': possible_lookups,
'null_values': null_values or {RQL_NULL},
'distinct': distinct or False,
'hidden': hidden or False,
}

if use_repr is not None:
Expand Down
8 changes: 8 additions & 0 deletions dj_rql/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class RQLFilterDescriptionTemplate:
'_render_search_inplace',
'_render_ordering_inplace',
'_render_null_inplace',
'_render_default_inplace',
)

@classmethod
Expand Down Expand Up @@ -80,6 +81,13 @@ def _render_null_inplace(cls, base, filter_item, filter_instance):

return base

@classmethod
def _render_default_inplace(cls, base, filter_item, filter_instance):
if filter_item.get('hidden', False):
return cls._render_common_key_inplace(base, 'default', '**hidden**',)

return base

@classmethod
def _render_common_key_inplace(cls, base, key, value):
return '{base}\n{key}: {value}'.format(base=base, key=key, value=value)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def test_description_null_overridden_render():
'null: NULL_ID, null()'


def test_description_hidden_render():
result = RQLFilterDescriptionTemplate.render(*filter_data('select_author'))
assert result == '**Filter for: select_author**\n\n' \
'lookups: eq, ne, like, ilike, in, out\ndefault: **hidden**'


def test_description_custom_render():
class Cls(RQLFilterDescriptionTemplate):
IN_PLACE_RENDERERS = ('_render_custom_inplace',)
Expand Down

0 comments on commit de54f67

Please sign in to comment.