[Mpuls-commits] r1009 - in wasko/branches/2.0: . waskaweb/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Jan 29 12:13:55 CET 2010
Author: bh
Date: 2010-01-29 12:13:54 +0100 (Fri, 29 Jan 2010)
New Revision: 1009
Modified:
wasko/branches/2.0/ChangeLog
wasko/branches/2.0/waskaweb/model/case.py
Log:
* waskaweb/model/case.py (ensure_unicode): New function to convert
objects to unicode.
(CaseFactory.loadById, CaseFactory.loadByName)
(CaseStringField.from_db, CaseDigest.getValue): Use ensure_unicode
to convert to unicode instead of hardcoding the conversion inline.
Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog 2010-01-29 11:10:49 UTC (rev 1008)
+++ wasko/branches/2.0/ChangeLog 2010-01-29 11:13:54 UTC (rev 1009)
@@ -1,3 +1,11 @@
+2010-01-29 Bernhard Herzog <bh at intevation.de>
+
+ * waskaweb/model/case.py (ensure_unicode): New function to convert
+ objects to unicode.
+ (CaseFactory.loadById, CaseFactory.loadByName)
+ (CaseStringField.from_db, CaseDigest.getValue): Use ensure_unicode
+ to convert to unicode instead of hardcoding the conversion inline.
+
2010-01-29 Torsten Irländer <torsten.irlaender at intevation.de>
Reestablish workflow in caselifetime controller. Not data is actuella
Modified: wasko/branches/2.0/waskaweb/model/case.py
===================================================================
--- wasko/branches/2.0/waskaweb/model/case.py 2010-01-29 11:10:49 UTC (rev 1008)
+++ wasko/branches/2.0/waskaweb/model/case.py 2010-01-29 11:13:54 UTC (rev 1009)
@@ -67,6 +67,16 @@
log = logging.getLogger(__name__)
+def ensure_unicode(s):
+ """Convert s to a unicode object.
+ If it's alredy a unicode object, s is returned as is. Otherwise
+ it's converted to a byte-string which is assumed to be in utf-8 and
+ then converted to unicode."""
+ if isinstance(s, unicode):
+ return s
+ return unicode(str(s), 'utf-8')
+
+
def get_field_identifier(id, name, it=None, idx=0):
"""Will return the identifier of a field. If the field in in a rg the
identifier of the first occourance will be returned on default."""
@@ -393,9 +403,9 @@
db.recycleConnection(conn, c)
case.id = int(id)
- case.last_name = unicode(str(result.get('name', '')), 'utf-8')
- case.first_name = unicode(str(result.get('vorname', '')), 'utf-8')
- case.knr = unicode(str(result.get('fn', '')), 'utf-8')
+ case.last_name = ensure_unicode(result.get('name', ''))
+ case.first_name = ensure_unicode(result.get('vorname', ''))
+ case.knr = ensure_unicode(result.get('fn', ''))
case.first_meeting = result.get('erstgespraech')
case.cm_end = result.get('datum_cm_ende')
case.editor = result.get('bearbeiter_id', None)
@@ -408,9 +418,9 @@
just returns a case object initiated with the provided parameters"""
case = Case()
case.id = int(id)
- case.first_name = unicode(str(first_name), 'utf-8')
- case.last_name = unicode(str(last_name), 'utf-8')
- case.knr = unicode(str(knr), 'utf-8')
+ case.first_name = ensure_unicode(first_name)
+ case.last_name = ensure_unicode(last_name)
+ case.knr = ensure_unicode(knr)
case.editor = bearbeiter_id
case.state = State()
case.state.setData(s_id, id, s_state, s_access)
@@ -598,7 +608,7 @@
def from_db(cls, obj):
if obj is None:
return u""
- return unicode(str(obj), 'utf-8')
+ return ensure_unicode(obj)
class CaseAgeField(CaseField):
@@ -678,7 +688,7 @@
if item:
value = item.getValue()
if isinstance(value, str):
- value = unicode(str(value), 'utf-8')
+ value = ensure_unicode(value)
self.__dict__[name] = value
return value
else:
More information about the Mpuls-commits
mailing list