12月2日
HowTo Feedjack Support no-ascii tag names With Truck Django
Truck Django changes lots about unicode,so as feedjack.
Version 40# of feedjack has some bug with truck django below.
1.ERROR : 'module' object has no attribute 'quote_name'
replace all "backend.quote_name" with "connection.ops.quote_name" in fjlib.py.
2.no-ascii tags error : UnicodeDecodeError at /tag/互联网络/
'ascii' codec can't decode byte 0xe4 in position 21: ordinal not in range(128)
2.1 add a new line in fjlib.py below:
from django.utils.encoding import smart_unicode
2.2 in fjlib.py replace :
url = 'http://%s/%s' % (http_post.rstrip('/'), \
path_info.lstrip('/'))
pagecachekey = '%s?%s' % (path_info, query_string)
with :
url = u'http://%s/%s' % (smart_unicode(http_post.rstrip('/')), smart_unicode(path_info.lstrip('/')))
pagecachekey = u'%s?%s' % (smart_unicode(path_info), smart_unicode(query_string))
2.3 replace "ctx.update(key)" with "ctx.update(key.encode('utf-8'))" in fjcache.py
That's all.patch is below.
##########################
Index: fjcache.py
===================================================================
--- fjcache.py (revision 41)
+++ fjcache.py (working copy)
@@ -22,7 +22,7 @@
""" Returns the md5 hash of a string.
"""
ctx = md5.new()
- ctx.update(key)
+ ctx.update(key.encode('utf-8'))
return ctx.hexdigest()
def getkey(stype, site_id=None, key=None):
Index: fjlib.py
===================================================================
--- fjlib.py (revision 41)
+++ fjlib.py (working copy)
@@ -11,6 +11,7 @@
from django.core.paginator import ObjectPaginator, InvalidPage
from django.db import backend
from django.http import Http404
+from django.utils.encoding import smart_unicode
from feedjack import models
from feedjack import fjcache
@@ -71,18 +72,18 @@
tag_obj = None
tags = models.Tag.objects.extra(\
select={'post_id':'%s.%s' % (\
- backend.quote_name('feedjack_post_tags'), \
- backend.quote_name('post_id'))}, \
+ connection.ops.quote_name('feedjack_post_tags'), \
+ connection.ops.quote_name('post_id'))}, \
tables=['feedjack_post_tags'], \
where=[\
'%s.%s=%s.%s' % (\
- backend.quote_name('feedjack_tag'), \
- backend.quote_name('id'), \
- backend.quote_name('feedjack_post_tags'), \
- backend.quote_name('tag_id')), \
+ connection.ops.quote_name('feedjack_tag'), \
+ connection.ops.quote_name('id'), \
+ connection.ops.quote_name('feedjack_post_tags'), \
+ connection.ops.quote_name('tag_id')), \
'%s.%s IN (%s)' % (\
- backend.quote_name('feedjack_post_tags'), \
- backend.quote_name('post_id'), \
+ connection.ops.quote_name('feedjack_post_tags'), \
+ connection.ops.quote_name('post_id'), \
', '.join([str(post.id) for post in object_list]))])
for tag in tags:
if tag.post_id not in tagd:
@@ -106,9 +107,9 @@
def getcurrentsite(http_post, path_info, query_string):
""" Returns the site id and the page cache key based on the request.
"""
- url = 'http://%s/%s' % (http_post.rstrip('/'), \
- path_info.lstrip('/'))
- pagecachekey = '%s?%s' % (path_info, query_string)
+ url = u'http://%s/%s' % (smart_unicode(http_post.rstrip('/')),\
+ smart_unicode(path_info.lstrip('/')))
+ pagecachekey = u'%s?%s' % (smart_unicode(path_info), smart_unicode(query_string))
hostdict = fjcache.hostcache_get()
if not hostdict: