getpelican / pelican

Static site generator that supports Markdown and reST syntax. Powered by Python.
https://getpelican.com
GNU Affero General Public License v3.0
12.48k stars 1.81k forks source link

Unicode issue with new date formatting option #65

Closed brunobord closed 13 years ago

brunobord commented 13 years ago

I've got a problem, probably caused by a Unicode / ascii issue caused by the brand-new-shiny locale date formatting.

I guess, the "december" month becoming "Décembre" spits out the following message:

File "/home/bruno/Projets/[redacted]/pelican/pelican/themes/simple/templates/article.html", line 7, in block "content"
    {{ article.locale_date }}
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)

the chosen formatting is:

DEFAULT_DATE_FORMAT = u'%a %d %B %Y'
brunobord commented 13 years ago

this bug occurs with every template I've tried.

brunobord commented 13 years ago

Here is my patch

diff --git a/pelican/contents.py b/pelican/contents.py
index 1ace659..1112349 100644
--- a/pelican/contents.py
+++ b/pelican/contents.py
@@ -1,3 +1,4 @@
+#-*- coding: utf-8 -*-
 from pelican.utils import slugify, truncate_html_words

@@ -76,7 +77,7 @@ class Page(object):

     @property
     def locale_date(self):
-        return self.date.strftime(self.date_format)
+        return self.date.strftime(self.date_format).decode('utf')
almet commented 13 years ago

Hmm, thanks for the report. I HATE unicode problems, it was too easy :p

I'm not sure to understand why it's doing that but I can reproduce it. It's probably caused by the use of setlocale, I'm trying to understand what's happening !

almet commented 13 years ago

Fixed in the last head. Thanks.