Application import: Added propper_unicode function to handle

unicode/ascii mix. Thanks to Rene Koecher!
This commit is contained in:
Emanuel Schuetze 2011-11-29 12:10:06 +01:00
parent e91df2b67b
commit 8ed81db9f2
2 changed files with 12 additions and 2 deletions

View File

@ -19,6 +19,7 @@ from django.utils.translation import ugettext as _
from openslides.participant.models import Profile
from openslides.system.api import config_get
from openslides.utils.utils import _propper_unicode
class Application(models.Model):
@ -385,9 +386,9 @@ class Application(models.Model):
def writelog(self, text, user=None):
if not self.log:
self.log = ""
self.log += u"%s | %s" % (datetime.now().strftime("%d.%m.%Y %H:%M:%S"), text)
self.log += u"%s | %s" % (datetime.now().strftime("%d.%m.%Y %H:%M:%S"), _propper_unicode(text))
if user is not None:
self.log += u" (by %s)" % (user.username)
self.log += u" (by %s)" % (_propper_unicode(user.username))
self.log += "\n"
self.save()

View File

@ -86,3 +86,12 @@ def ajax_request(data):
ajax response
"""
return HttpResponse(json.dumps(data))
def _propper_unicode(text):
res = ''
if not isinstance(text, unicode):
res = u"%s" % text.decode('UTF-8')
else:
res = text
return res