Skip to content

Search Resources in Dataset Read View Func#225

Open
JVickery-TBS wants to merge 2 commits intocanada-v2.10from
feature/resource-search
Open

Search Resources in Dataset Read View Func#225
JVickery-TBS wants to merge 2 commits intocanada-v2.10from
feature/resource-search

Conversation

@JVickery-TBS
Copy link

feat(views): resource search;

  • Dataset resource search view arg.

- Dataset resource search view arg.
- Added change log file.
# TODO: upstream contrib??
resource_query = request.args.get("resource_query")
if resource_query:
resource_query = html_escape(resource_query)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be needed. Flask has already converted any url-encoded characters here and the resource name we're comparing against is not escaped.

Suggested change
resource_query = html_escape(resource_query)

Comment on lines +500 to +506
filtered_resources = []
for res_dict in pkg_dict['resources']:
res_name = h.get_translated(res_dict, 'name')
if resource_query.lower() not in res_name.lower():
continue
filtered_resources.append(res_dict)
pkg_dict['resources'] = filtered_resources
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to save some steps and temporary variables:

Suggested change
filtered_resources = []
for res_dict in pkg_dict['resources']:
res_name = h.get_translated(res_dict, 'name')
if resource_query.lower() not in res_name.lower():
continue
filtered_resources.append(res_dict)
pkg_dict['resources'] = filtered_resources
pkg_dict['resources'] = [
r for r in pkg_dict['resources']
if resource_query.lower() in h.get_translated(r, 'name').lower()
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants