dosubot[bot] commented on issue #30308:
URL: https://github.com/apache/superset/issues/30308#issuecomment-2355841469
<!-- Greeting -->
Hey @FraterCRC! I'm here to help you with any bugs, questions, or
contributions you have for Superset. Let's tackle this together!
<!-- Answer -->
To address the issue where non-English model names result in filenames like
'_{id}' that are not exported, you can modify the `get_filename` function to
handle non-English characters more gracefully. Here's an improved version of
the function:
```python
import unicodedata
import re
from werkzeug.utils import secure_filename
def slugify(value: str) -> str:
value = unicodedata.normalize('NFKD', value).encode('ascii',
'ignore').decode('ascii')
value = re.sub(r'[^\w\s-]', '', value).strip().lower()
return re.sub(r'[-\s]+', '-', value)
def get_filename(model_name: str, model_id: int, skip_id: bool = False) ->
str:
slug = slugify(model_name)
filename = slug if skip_id else f"{slug}_{model_id}"
return filename if slug else str(model_id)
```
This `slugify` function normalizes the string to ASCII, removes non-word
characters, and replaces spaces and hyphens with a single hyphen. This should
handle non-English characters more gracefully and avoid the issue of filenames
like '_{id}'.
In the context of Superset, you can see that the `get_filename` function is
used in the `ExportDashboardsCommand` class to generate filenames for exported
dashboards. By modifying the `get_filename` function as shown above, you can
ensure that non-English model names are handled correctly when exporting
dashboards
<sup>[[1]](https://github.com/apache/superset/blob/master/superset/utils/file.py)</sup><sup>[[2]](https://github.com/apache/superset/blob/master/superset/commands/dashboard/export.py)</sup>.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]