Skip to content

Commit

Permalink
person: filter by view
Browse files Browse the repository at this point in the history
* Allows filtering persons by view (organisation)
* Closes #550

Co-Authored-by: Alicia Zangger <alicia.zangger@rero.ch>
  • Loading branch information
Alicia Zangger authored and AoNoOokami committed Jan 8, 2020
1 parent 365ba62 commit 7110a77
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ def _(x):
item_route='/persons/<pid(pers, record_class="rero_ils.modules.persons.api:Person"):pid_value>',
default_media_type='application/json',
max_result_window=10000,
search_factory_imp='rero_ils.query:search_factory',
search_factory_imp='rero_ils.query:person_view_search_factory',
read_permission_factory_imp=allow_all,
list_permission_factory_imp=allow_all,
create_permission_factory_imp=deny_all,
Expand Down
11 changes: 11 additions & 0 deletions rero_ils/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ def view_search_factory(self, search, query_parser=None):
return (search, urlkwargs)


def person_view_search_factory(self, search, query_parser=None):
"""Search factory with view code parameter."""
view = request.args.get(
'view', current_app.config.get('RERO_ILS_SEARCH_GLOBAL_VIEW_CODE'))
search, urlkwargs = search_factory(self, search)
if view != current_app.config.get('RERO_ILS_SEARCH_GLOBAL_VIEW_CODE'):
org = Organisation.get_record_by_viewcode(view)
search = search.filter('term', organisations=org['pid'])
return (search, urlkwargs)


def organisation_search_factory(self, search, query_parser=None):
"""Search factory."""
search, urlkwargs = search_factory(self, search)
Expand Down

0 comments on commit 7110a77

Please sign in to comment.