ascii Encoding error

22 views
Skip to first unread message

jssevestre

unread,
Mar 2, 2011, 2:31:30 PM3/2/11
to Django Photologue
Hello
Thank you for photologue, it's a great app.

Maybe I found a solution for this bad things:
""" 'ascii' codec can't encode characters """
when upload a file ( single image ) with non-ascii characters ( accent
français in my case )
I have this error with django 1.2.5 and photologue svn.
This error is present when I run my apache server but not when I run ./
manage.py runserver (!)
I have test many tips but none work, expect:

http://source.mihelac.org/2011/02/6/rename-uploaded-files-ascii-character-set-django/
using only this methode don't work with photologue . So,

in models.py put:

import unicodedata

then add/replace line 76
def get_storage_path(instance, filename):
safefilename = unicodedata.normalize('NFKD',
filename).encode('ascii', 'ignore')
return os.path.join(PHOTOLOGUE_DIR, 'photos', safefilename)

I hope it's useful ,
I try to get it work for gallery upload now

Aljosa Mohorovic

unread,
Mar 2, 2011, 5:46:15 PM3/2/11
to Django Photologue
probably a problem with apache configuration, try this:
http://groups.google.com/group/modwsgi/browse_thread/thread/a5be1657d101a11a/

Aljosa Mohorovic

jssevestre

unread,
Mar 4, 2011, 12:30:21 PM3/4/11
to Django Photologue
Thanks,
but it doesn't work for me ( I try locally )
And I can't modify this file for my production server.

Here is my code with gallery upload support:

file : models.py

import unicodedata

line 75:
else:
def get_storage_path(instance, filename):
safefilename = unicodedata.normalize('NFKD',
unicode(filename)).encode('ascii', 'ignore')
return os.path.join(PHOTOLOGUE_DIR, 'photos', safefilename)

def get_zip_tmp_path(instance,filename):
safefilename = unicodedata.normalize('NFKD',
filename).encode('ascii', 'ignore')
return os.path.join(PHOTOLOGUE_DIR, 'temp', safefilename)

line 182:
class GalleryUpload(models.Model):
zip_file = models.FileField(_('images file (.zip)'),
upload_to=get_zip_tmp_path,


By the way I found that you raise an error if the gallery upload name
already exist in gallery name, here a solution :
def process_zipfile(self):
if os.path.isfile(self.zip_file.path):
# TODO: implement try-except here
zip = zipfile.ZipFile(self.zip_file.path)
bad_file = zip.testzip()
if bad_file:
raise Exception('"%s" in the .zip archive is corrupt.'
% bad_file)
count = 1
if self.gallery:
gallery = self.gallery
else:
----> Search = Gallery.objects.filter(title =self.title)
----> if Search.count() > 0:
----> safetitle = '_'.join([self.title,str(Search.count()
+1)])
----> else:
----> safetitle = self.title
----> gallery = Gallery.objects.create(title=safetitle,
---->
title_slug=slugify(safetitle),

description=self.description,

is_public=self.is_public,
tags=self.tags)

On 2 mar, 23:46, Aljosa Mohorovic <aljosa.mohoro...@gmail.com> wrote:
> probably a problem with apache configuration, try this:http://groups.google.com/group/modwsgi/browse_thread/thread/a5be1657d...
>
> Aljosa Mohorovic
Reply all
Reply to author
Forward
0 new messages