-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
search_placeholder fails with TypeError when using lazy_gettext for column_labels #1790
Comments
I reviewed and merged #1728, see if the latest master fixes the issue for you. |
I have not tried the latest master but I do no think it will work since the cause of the exception is not resolved. Below a small test-program I used to reproduce the issue:
|
Last master version installed and this bug is still present. # break in 1.5.3, fine in 1.5.2
column_list = ['parent_table.child_table.name']
column_labels = {'parent_table.child_table.name': lazy_gettext('Name')} fix: column_list = ['parent_table.child_table']
column_labels = {'parent_table.child_table': lazy_gettext('Name')} For others views and as mentioned by @fwiersVANAD, a simple def search_placeholder(self):
return gettext('Search') is a simple and clean solution |
I can confirm that this bug is not fixed on latest release. I was able to work around it by using hints from previous comments and by looking at the current implementation in flask-admin. Just add this to your ModelView. def search_placeholder(self):
if self.column_searchable_list:
return ", ".join(
str(self.column_labels.get(col, col))
for col in self.column_searchable_list
) |
I was still running into this problem on current versions, and created a PR with a fix. If we evaluate the Lazy String to a string, then we no longer get the error, and we get properly translated column labels. |
For translations I use lazy_gettext in column_labels in a ModelView. With version 1.5.3 this results in an error (was working for version 1.5.2):
TypeError: sequence item 0: expected str instance, _LazyString found
at: lib\site-packages\flask_admin\contrib\sqla\view.py", line 608, in search_placeholder
at: return 'Search: %s' % u', '.join(placeholders)
Maybe I am doing translations for column-names wrong and there is another (better) way to provide translations for column-names?
I monkey-patched the method locally to use the the previous statements (i.e. just
return gettext('Search')
) after I also tried to overwrite the method (which worked but the result is not to my liking, see related issue #1728 ):The text was updated successfully, but these errors were encountered: