issue 626 fixes unicode and truncattion, thanks mweissen

This commit is contained in:
Massimo Di Pierro committed 2012-01-20 11:36:42 -06:00
1 parent 1356e5b73f
commit 6837da0917
3 files changed
+16 -14

No files matched your search

+1 -1
View File
@@ -1 +1 @@
Version 1.99.4 (2012-01-20 11:23:12) stable Version 1.99.4 (2012-01-20 11:36:35) stable
+6
View File
@@ -124,6 +124,12 @@ def xmlescape(data, quote = True):
return data return data
def truncate_string(text, length, dots='...'):
text = text.decode('utf-8')
if len(text)>length:
text = text[:length-len(dots)].encode('utf-8')+dots
return text
def URL( def URL(
a=None, a=None,
c=None, c=None,
+9 -13
View File
@@ -18,7 +18,7 @@ from http import HTTP
from html import XML, SPAN, TAG, A, DIV, CAT, UL, LI, TEXTAREA, BR, IMG, SCRIPT from html import XML, SPAN, TAG, A, DIV, CAT, UL, LI, TEXTAREA, BR, IMG, SCRIPT
from html import FORM, INPUT, LABEL, OPTION, SELECT, MENU from html import FORM, INPUT, LABEL, OPTION, SELECT, MENU
from html import TABLE, THEAD, TBODY, TR, TD, TH from html import TABLE, THEAD, TBODY, TR, TD, TH
from html import URL from html import URL, truncate_string
from dal import DAL, Table, Row, CALLABLETYPES, smart_query from dal import DAL, Table, Row, CALLABLETYPES, smart_query
from storage import Storage from storage import Storage
from utils import md5_hash from utils import md5_hash
@@ -1800,11 +1800,11 @@ class SQLFORM(FORM):
value = A('File', value = A('File',
_href='%s/%s' % (upload, value)) _href='%s/%s' % (upload, value))
else: else:
value = '' value = ''
elif isinstance(value,str) and len(value)>maxlength: elif isinstance(value,str):
value=value[:maxlength]+'...' value = truncate_string(value,maxlength)
else: else:
value=field.formatter(value) value = field.formatter(value)
tr.append(TD(value)) tr.append(TD(value))
row_buttons = TD(_class='row_buttons') row_buttons = TD(_class='row_buttons')
if links and links_in_grid: if links and links_in_grid:
@@ -2195,16 +2195,12 @@ class SQLTABLE(TABLE):
r = '' r = ''
elif field.type in ['string','text']: elif field.type in ['string','text']:
r = str(field.formatter(r)) r = str(field.formatter(r))
ur = unicode(r, 'utf8')
if headers!={}: #new implement dict if headers!={}: #new implement dict
if isinstance(headers[colname],dict): if isinstance(headers[colname],dict):
if isinstance(headers[colname]['truncate'], int) \ if isinstance(headers[colname]['truncate'], int):
and len(ur)>headers[colname]['truncate']: r = truncate_string(r, headers[colname]['truncate'])
r = ur[:headers[colname]['truncate'] - 3] elif not truncate is None:
r = r.encode('utf8') + '...' r = truncate_string(r, truncate)
elif not truncate is None and len(ur) > truncate:
r = ur[:truncate - 3].encode('utf8') + '...'
attrcol = dict()#new implement dict attrcol = dict()#new implement dict
if headers!={}: if headers!={}:
if isinstance(headers[colname],dict): if isinstance(headers[colname],dict):