Open a5net opened 3 years ago
I have same problem, how to fix it? thank you!
I encountered the same problem and solved it with a monkey patch. It is effective but not elegant enough. I also submit a PR to Flask-AppBuilder as a improvement.
It is because not all pages call update_redirect
which changing the page history stack, turning out it will jump to other page at the top of the page history stack after switching language.
What I did
Add a monkey patch function in class SupersetAppInitializer
at superset/app.py
.
def monkey_patch(self) -> None:
@expose("/<string:locale>")
def patch_flask_locale_index(self, locale):
from flask import abort, redirect, session, request
from flask_babel import refresh
from flask_appbuilder.urltools import Stack
if locale not in self.appbuilder.bm.languages:
abort(404, description="Locale not supported.")
if request.referrer is not None:
page_history = Stack(session.get("page_history", []))
page_history.push(request.referrer)
session["page_history"] = page_history.to_json()
session["locale"] = locale
refresh()
self.update_redirect()
return redirect(self.get_redirect())
from flask_appbuilder.babel.views import LocaleView
LocaleView.index = patch_flask_locale_index
Call the function in configure_fab
function in class SupersetAppInitializer
before init appbuilder, that is
def configure_fab(self) -> None:
if self.config["SILENCE_FAB"]:
logging.getLogger("flask_appbuilder").setLevel(logging.ERROR)
custom_sm = self.config["CUSTOM_SECURITY_MANAGER"] or SupersetSecurityManager
if not issubclass(custom_sm, SupersetSecurityManager):
raise Exception(
"""Your CUSTOM_SECURITY_MANAGER must now extend SupersetSecurityManager,
not FAB's security manager.
See [4565] in UPDATING.md"""
)
self.monkey_patch()
appbuilder.indexview = SupersetIndexView
appbuilder.base_template = "superset/base.html"
appbuilder.security_manager_class = custom_sm
appbuilder.init_app(self.flask_app, db.session)
That's it.
Can you please confirm you are still facing this bug / close it not --thanks!
This Bug continues to exist in V 1.4.2
I just tried this on master, and it still exists. I'll assign this to a couple people that might know a way to resolve this, but I think in general, I'll leave this open and in the unfortunate ol' "PRs welcome" status.
Any update? Bug still exists in version 2.1.0.
Probably still an issue... I don't think I've seen anyone working on it, strangely.
This issue is at risk of being closed as stale, though the behavior still exists as of 4.0.1. All the links just point to their relative language URL (e.g. http://localhost:8088/lang/zh_TW) which by default navigates to the Welcome page.
@tianhe1986 would you want to open a PR making a solution along the lines you suggest more official,
@dpgaspar do you know of any better/easier way to keep the user on their current page/URL when changing language?
This was just reported again on the linked issue. Not so stale anymore :)
I have the same problem, but when I change the language, it doesn't redirect me to the user section; instead, it takes me to the homepage.
I suggest this option, it works well for me
Add it to config.py:
class SupersetIndexView(IndexView):
@expose("/lang/<string:locale>")
def patch_flask_locale(self, locale):
from flask import redirect, request, session
referrer = request.headers.get("Referer")
session["locale"] = locale
return redirect(referrer)
FAB_INDEX_VIEW = f"{SupersetIndexView.__module__}.{SupersetIndexView.__name__}"
When the user presses on change language a redirect to
/users/list
happens. I think, in terms of UX, it should remain on the same page as before changing the language.Expected results
Remain on the same page, but translated into a different language.
Actual results
Redirects to
users/list
.Screenshots
How to reproduce the bug
Environment
(please complete the following information):
0.999.0dev
3.7.4
v14.11.0
Checklist
Make sure to follow these steps before submitting your issue - thank you!