Skip to content

Commit

Permalink
Merge pull request #97 from oarepo/alzbetapokorna/ep-34-fix-search-pa…
Browse files Browse the repository at this point in the history
…ge-rendering

autoescape fix
  • Loading branch information
mirekys authored Oct 18, 2023
2 parents ecaad47 + d8bcce4 commit ee62841
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions oarepo_ui/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def _catalog_config(self, catalog, env):
env.policies.setdefault("json.dumps_kwargs", {}).setdefault("default", str)
self.app.update_template_context(context)
catalog.jinja_env.loader = env.loader
catalog.jinja_env.autoescape = env.autoescape
context.update(catalog.jinja_env.globals)
context.update(env.globals)
catalog.jinja_env.globals = context
Expand Down
5 changes: 4 additions & 1 deletion oarepo_ui/resources/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def _get_component_path(
f"Unable to find a file named {name}{file_ext} "
f"or one following the pattern {name_dot}*{file_ext}"
)

def _get_from_file(self, *, prefix: str, name: str, url_prefix: str, file_ext: str) -> "Component":
root_path, path = self._get_component_path(prefix, name, file_ext=file_ext)
component = Component(
Expand All @@ -87,7 +88,9 @@ def _get_from_file(self, *, prefix: str, name: str, url_prefix: str, file_ext: s
return component


def get_jinja_template(_catalog, template_def, fields=[]):
def get_jinja_template(_catalog, template_def, fields=None):
if fields is None:
fields = []
jinja_content = None
for component in _catalog.jinja_env.loader.searchpath:
if component["component_file"].endswith(template_def["layout"]):
Expand Down
4 changes: 2 additions & 2 deletions oarepo_ui/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ def search(self):
)

search_config = partial(self.config.search_app_config, **search_options)

search_app_config = search_config(app_id=app_id)
json_data = json.dumps(search_app_config, default=lazy_string_encoder, indent=4)

return _catalog.render(
"search",
__source=source,
search_app_config=json_data,
search_app_config=search_app_config,
ui_config=self.config,
ui_resource=self,
layout=layout,
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-ui
version = 5.0.72
version = 5.0.73
description = UI module for invenio 3.5+
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
12 changes: 7 additions & 5 deletions tests/test_ui_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ def test_permissions_on_detail(
with client.get(f"/simple-model/{simple_record.id}") as c:
assert c.status_code == 200
assert (
"permissions={'can_edit': False, 'can_new_version': False, 'can_manage': "
"False, 'can_update_draft': False, 'can_read_files': True, 'can_review': "
"False, 'can_view': False, 'can_delete_draft': False, 'can_manage_files': "
"False, 'can_manage_record_access': False}"
'permissions={'can_edit': False, 'can_new_version': False, '
''can_manage': False, 'can_update_draft': False, '
''can_read_files': True, 'can_review': False, '
''can_view': False, 'can_delete_draft': False, '
''can_manage_files': False, 'can_manage_record_access': '
'False}'
) in c.text


Expand All @@ -36,7 +38,7 @@ def test_permissions_on_search(
):
with client.get(f"/simple-model/") as c:
assert c.status_code == 200
assert ("permissions={'can_create': True}") in c.text
assert ("permissions={'can_create': True}") in c.text


def test_filter_on_search(
Expand Down

0 comments on commit ee62841

Please sign in to comment.