slugify report filename

This ensure that the file name will always work on any file-system.

issue3497
review1511002
This commit is contained in:
Cédric Krier committed 2013-11-15 12:25:20 +01:00
1 parent ad1be012d1
commit 71ead2327f
2 files changed
+16 -4

No files matched your search

+3 -4
View File
@@ -9,7 +9,7 @@ import tempfile
import os
import webbrowser
from tryton.pyson import PYSONEncoder
from tryton.common import RPCProgress, RPCExecute, RPCException
from tryton.common import RPCProgress, RPCExecute, RPCException, slugify
_ = gettext.gettext
@@ -40,10 +40,9 @@ class Action(object):
if not print_p and direct_print:
print_p = True
dtemp = tempfile.mkdtemp(prefix='tryton_')
fp_name = os.path.join(dtemp,
name.replace(os.sep, '_').replace(os.altsep or os.sep, '_')
+ os.extsep
+ type.replace(os.sep, '_').replace(os.altsep or os.sep, '_'))
slugify(name) + os.extsep + slugify(type))
with open(fp_name, 'wb') as file_d:
file_d.write(data)
if email_print:
+13
View File
@@ -10,6 +10,7 @@ import os
import subprocess
import re
import logging
import unicodedata
from functools import partial
from tryton.config import CONFIG
from tryton.config import TRYTON_ICON, PIXMAPS_DIR
@@ -490,6 +491,18 @@ def file_selection(title, filename='',
return filenames
_slugify_strip_re = re.compile(r'[^\w\s-]')
_slugify_hyphenate_re = re.compile(r'[-\s]+')
def slugify(value):
if not isinstance(value, unicode):
value = unicode(value)
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
value = unicode(_slugify_strip_re.sub('', value).strip().lower())
return _slugify_hyphenate_re.sub('-', value)
def file_open(filename, type, print_p=False):
def save():
save_name = file_selection(_('Save As...'),