File Manager: fixed unicode decode error

This commit is contained in:
Anand Doshi 2015-03-23 16:07:23 +05:30
parent fd6639b1bf
commit 2d6fec5954
2 changed files with 7 additions and 4 deletions

View file

@ -143,11 +143,11 @@ def serve(port=8000, profile=False, site=None, sites_path='.'):
if not os.environ.get('NO_STATICS'):
application = SharedDataMiddleware(application, {
'/assets': os.path.join(sites_path, 'assets'),
b'/assets': os.path.join(sites_path, 'assets').encode("utf-8"),
})
application = StaticDataMiddleware(application, {
'/files': os.path.abspath(sites_path)
b'/files': os.path.abspath(sites_path).encode("utf-8")
})
run_simple('0.0.0.0', int(port), application, use_reloader=True,

View file

@ -6,7 +6,7 @@ import frappe
import os, base64, re
import hashlib
import mimetypes
from frappe.utils import get_site_path, get_hook_method, get_files_path, random_string
from frappe.utils import get_site_path, get_hook_method, get_files_path, random_string, encode, cstr
from frappe import _
from frappe import conf
from copy import copy
@ -258,8 +258,11 @@ def get_content_hash(content):
return hashlib.md5(content).hexdigest()
def get_file_name(fname, optional_suffix):
# convert to unicode
fname = cstr(fname)
n_records = frappe.db.sql("select name from `tabFile Data` where file_name=%s", fname)
if len(n_records) > 0 or os.path.exists(get_files_path(fname).encode('utf-8')):
if len(n_records) > 0 or os.path.exists(encode(get_files_path(fname))):
f = fname.rsplit('.', 1)
if len(f) == 1:
partial, extn = f[0], ""