Created
February 15, 2016 12:30
-
-
Save atelenga/bb698ac749506fd50833 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.utils.deconstruct import deconstructible | |
| @deconstructible | |
| class PathAndRename(object): | |
| def __init__(self, sub_path): | |
| self.path = sub_path | |
| def __call__(self, instance, filename, prefix=None, unique=False): | |
| """ | |
| Transliteration of Russian characters | |
| """ | |
| symbols = (u"абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ", | |
| u"abvgdeejzijklmnoprstufhzcss_y_euaABVGDEEJZIJKLMNOPRSTUFHZCSS_Y_EUA") | |
| tr = {ord(a): ord(b) for a, b in zip(*symbols)} | |
| return op.join(self.path, filename.translate(tr)) | |
| path_and_rename = PathAndRename("uploads/") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment