dvshnt / django-photologue

Automatically exported from code.google.com/p/django-photologue
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Support multibyte filename #119

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I got the following:
Caught an exception while rendering: 'ascii' codec can't decode byte 0xe3
in position 0: ordinal not in range(128)

models.py
Before:
290    def image_filename(self):
291        return os.path.basename(self.image.path)

After:
290    def image_filename(self):
291        return os.path.basename(self.image.path.decode('utf8'))
                                                   ^^^^^^^^^^^^^^

Original issue reported on code.google.com by pipp...@gmail.com on 13 Jun 2009 at 7:52

GoogleCodeExporter commented 8 years ago
290->289
291->290

Original comment by pipp...@gmail.com on 13 Jun 2009 at 8:05

GoogleCodeExporter commented 8 years ago
I have the same error.

Also, in admin  models.py:

Before:
293         size = getattr(size, 'name', size)
294         base, ext = os.path.splitext(self.image_filename())

After:
293         size = getattr(size, 'name', size)
294         base, ext = os.path.decode('utf8').splitext(self.image_filename())

Original comment by dreg...@gmail.com on 21 Jul 2009 at 1:58

GoogleCodeExporter commented 8 years ago

Original comment by justin.d...@gmail.com on 22 Jul 2009 at 12:26

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
@Report by pippejd
Works for me. I'm using Python 2.5, django 1.1 SVN-11368

@Comment 2 by dreglad:
Did not work. AttributeError: 'module' object has no attribute 'decode'

Original comment by mikaelmo...@gmail.com on 11 Aug 2009 at 12:44

GoogleCodeExporter commented 8 years ago
I had problem where thumbnails were missing from certain files due to either 
latin characters and spaces. To work around this I've used this code:

utils.py:
========

import unicodedata

def get_ascii_safe_path(test, filename):
    return unicodedata.normalize('NFKD', unicode(filename.replace(' ', '_'))).encode('ascii', 'ignore')

settings.py
===========

PHOTOLOGUE_PATH = 'utils.get_ascii_safe_path'

It resolves all encoding related issues with file names, but it would be nice 
to have photologue to do the sanitizing part out of the box..

Original comment by hainea...@gmail.com on 8 Feb 2011 at 7:02

GoogleCodeExporter commented 8 years ago
Just an update for the comment I left above. Here's an updated function that 
takes into account the storage path:

def get_ascii_safe_path(test, filename):
    folder = getattr(settings, 'PHOTOLOGUE_DIR', 'photologue')
    name   = unicodedata.normalize('NFKD', unicode(filename.replace(' ', '_'))).encode('ascii', 'ignore')
    return os.path.join(folder, 'photos', name)

This is not the end of the story thought, when deleting a photo the file and 
thumbnails are not deleted from the filesystem as it should anymore. This 
problem is getting messy...

Original comment by hainea...@gmail.com on 8 Feb 2011 at 8:20