Skip to content

Commit

Permalink
community: add theme.enabled flag
Browse files Browse the repository at this point in the history
  • Loading branch information
kpsherva committed Feb 8, 2024
1 parent a94f155 commit 9f287d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@
"brand": {
"description": "Theme brand name.",
"type": "string"
},
"enabled": {
"description": "Theme brand enabled flag.",
"type": "boolean"
}
}
},
Expand Down
25 changes: 13 additions & 12 deletions invenio_communities/views/communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@
]


def render_community_theme_template(template_name_or_list, theme_brand=None, **context):
def render_community_theme_template(template_name_or_list, theme=None, **context):
"""Render community theme."""
if theme_brand:
if theme and theme.get("enabled", False):
brand = theme.get("brand")
if isinstance(template_name_or_list, str):
loader = CommunityThemeChoiceJinjaLoader(theme_brand)
loader = CommunityThemeChoiceJinjaLoader(brand)

community_theme_view_env = current_app.jinja_env.overlay(loader=loader)

Expand Down Expand Up @@ -237,7 +238,7 @@ def communities_settings(pid_value, community, community_ui):

return render_community_theme_template(
"invenio_communities/details/settings/profile.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community,
community_ui=community_ui,
has_logo=True if logo else False,
Expand All @@ -260,7 +261,7 @@ def communities_requests(pid_value, community, community_ui):

return render_community_theme_template(
"invenio_communities/details/requests/index.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
permissions=permissions,
)
Expand All @@ -285,7 +286,7 @@ def communities_settings_privileges(pid_value, community, community_ui):

return render_community_theme_template(
"invenio_communities/details/settings/privileges.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
form_config=dict(
access=dict(visibility=VISIBILITY_FIELDS),
Expand All @@ -306,7 +307,7 @@ def communities_settings_curation_policy(pid_value, community, community_ui):

return render_community_theme_template(
"invenio_communities/details/settings/curation_policy.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
permissions=permissions,
form_config=dict(
Expand All @@ -333,7 +334,7 @@ def communities_settings_pages(pid_value, community, community_ui):

return render_community_theme_template(
"invenio_communities/details/settings/pages.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
permissions=permissions,
form_config=dict(
Expand Down Expand Up @@ -363,7 +364,7 @@ def members(pid_value, community, community_ui):

return render_community_theme_template(
"invenio_communities/details/members/members.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
permissions=permissions,
roles_can_update=_get_roles_can_update(community.id),
Expand All @@ -388,7 +389,7 @@ def invitations(pid_value, community, community_ui):
raise PermissionDeniedError()
return render_community_theme_template(
"invenio_communities/details/members/invitations.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
roles_can_invite=_get_roles_can_invite(community.id),
permissions=permissions,
Expand All @@ -411,7 +412,7 @@ def communities_about(pid_value, community, community_ui):

return render_community_theme_template(
"invenio_communities/details/about/index.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
permissions=permissions,
custom_fields_ui=load_custom_fields(dump_only_required=False)["ui"],
Expand All @@ -433,7 +434,7 @@ def communities_curation_policy(pid_value, community, community_ui):
raise PermissionDeniedError()
return render_community_theme_template(
"invenio_communities/details/curation_policy/index.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
permissions=permissions,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/communities/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_template_loader(theme_app):
@theme_app.route("/community_theme")
def community_theme():
return render_community_theme_template(
"invenio_test/frontpage.html", theme_brand="horizon"
"invenio_test/frontpage.html", theme={"brand": "horizon", "enabled": True}
)

@theme_app.route("/")
Expand Down

0 comments on commit 9f287d8

Please sign in to comment.