Commit 0cd0c19e authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Merge branch '30-lazyT' into 'master'

Resolve "fix crash when the lazy translation is activated"

Closes #30

See merge request !35
parents 69e44829 15ee8e31
......@@ -15,6 +15,7 @@
"""
import json
import os
import plugin_dbui as dbui
from gluon.tools import PluginManager
......@@ -152,7 +153,7 @@ def dbui_conf():
# fill the javascript template
app = request.application
script = API % (app,
json.dumps(config),
json.dumps(config, cls=dbui.JSONEncoder),
debug,
app,
app,
......
......@@ -15,7 +15,7 @@ from gluon.tools import PluginManager
T.set_current_languages("en", "en-gb", "en-us") # mother tongue
T.force("fr-fr") # user language
T.lazy = False # immediate translation
T.lazy = True # no immediate translation
#.............................................................................
#
......
......@@ -26,7 +26,7 @@ from converter import (to_field,
to_viewport)
from dbui import Dbui
from dbsvc import CALLBACK_ERRORS, DbSvc
from directsvc import DBUI, DirectSvc
from directsvc import DBUI, DirectSvc, JSONEncoder
from extjs import (ArrayStore,
CheckBox,
ComboBox,
......
......@@ -17,7 +17,7 @@ DBUI = "Dbui"
PROC_KEY = "%s.%s"
class MyJsonEncoder(json.JSONEncoder):
class JSONEncoder(json.JSONEncoder):
"""Add to the standard JSON encoder:
- date
......@@ -26,6 +26,38 @@ class MyJsonEncoder(json.JSONEncoder):
- time
"""
def __init__(self,
skipkeys=False,
ensure_ascii=True,
check_circular=True,
allow_nan=True,
sort_keys=False,
indent=None,
separators=None,
encoding='utf-8',
default=None,
use_decimal=False):
"""
Note:
* Copy from the base class gluon.contrib.simplejson
* the controller plugin_dbui.dbui_conf is crashing if the
constructor is not defined (not understood)
"""
self.skipkeys = skipkeys
self.ensure_ascii = ensure_ascii
self.check_circular = check_circular
self.allow_nan = allow_nan
self.sort_keys = sort_keys
self.use_decimal = use_decimal
if isinstance(indent, (int, long)):
indent = ' ' * indent
self.indent = indent
if separators is not None:
self.item_separator, self.key_separator = separators
if default is not None:
self.default = default
self.encoding = encoding
def default(self, obj):
if isinstance(obj, (datetime.date,
......@@ -208,4 +240,4 @@ class DirectSvc(BaseSvc):
li.append(di)
self.dbg("End directSvc.call", li)
return json.dumps(li, cls=MyJsonEncoder)
return json.dumps(li, cls=JSONEncoder)
......@@ -3,6 +3,9 @@
"""
import json
import locale
from directsvc import JSONEncoder
from gluon import current
......@@ -39,7 +42,10 @@ class Node(object):
the widget associated to the leaf
"""
di = {'cfg': json.dumps(cfg), 'leaf': True, 'text': text}
di = {'cfg': json.dumps(cfg, cls=JSONEncoder),
'leaf': True,
'text': text}
self.children.append(di)
def add_children(self, leaves, func=None, hidden=[]):
......@@ -67,7 +73,8 @@ class Node(object):
# according to local setting
cvt = {}
for el in leaves:
cvt[T(el)] = el
# NOTE: str is required to force the translation when lazyT is on
cvt[str(T(el))] = el
translate_leaves = cvt.keys()
translate_leaves.sort(cmp=locale.strcoll)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment