feat: added redirect rule to redirect /profile_/foo to the profile url

Hack to allow redirecting to profile url from JS as it doesn't know
the `profile_url_prefix`.

Issue #192
This commit is contained in:
Anand Chitipothu
2021-09-07 16:30:14 +05:30
parent 035a674cff
commit 77c4b53b71
2 changed files with 15 additions and 0 deletions

View File

@@ -174,6 +174,7 @@ community_markdown_macro_renderers = {
# page_renderer to manage profile pages
page_renderer = [
"community.page_renderers.ProfileRedirectPage",
"community.page_renderers.ProfilePage"
]

View File

@@ -40,6 +40,20 @@ def get_profile_url_prefix():
RE_USERNAME = re.compile("[a-zA-Z0-9_]{4,}")
class ProfileRedirectPage(BaseRenderer):
"""Renderer to redirect /profile_/foo to <profile_prefix>/foo.
This is useful to redirect to profile pages from javascript as there is no
easy to find the profile prefix.
"""
def can_render(self):
return self.path.startswith("profile_/")
def render(self):
username = self.path[len("profile_/"):]
frappe.flags.redirect_location = get_profile_url_prefix() + username
return RedirectPage(self.path).render()
class ProfilePage(BaseRenderer):
def __init__(self, path, http_status_code):
super().__init__(path, http_status_code)