Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #530 (closed defect: fixed)

Opened 13 years ago

Last modified 12 years ago

I18N problems with new style widgets

Reported by: Jorge Godoy <jgodoy@…> Owned by: anonymous
Priority: high Milestone:
Component: TG Widgets Version:
Severity: major Keywords:
Cc:

Description

As per messages on the thread  http://groups.google.com.br/group/turbogears/browse_thread/thread/1498e82c0a4793d5/eb490f0cacef5405?lnk=st&q=turbogears+widget+code+switching&rnum=1#eb490f0cacef5405

Here's the initialization code:

    widgets.CalendarDatePicker(attrs = {'size':11, 'maxlength':10},
                               name = "contrato_assinatura",
                               format = "%d/%m/%Y",
                               button_text = lazy_gettext(u"Calendário"),
                               calendar_lang = lazy_gettext('pt-utf8'),
                               label = lazy_gettext('Data de assinatura do contrato')),

And here's the traceback:

Traceback (most recent call last):
  File "./start-site_amostras.py", line 24, in ?
    from site_amostras.controllers import Root
  File "/home/godoy/.eclipse/LATAM/site_amostras/site_amostras/controllers.py", line 14, in ?
    from toxicologia import Toxicologia
  File "/home/godoy/.eclipse/LATAM/site_amostras/site_amostras/toxicologia.py", line 25, in ?
    import analises
  File "/home/godoy/.eclipse/LATAM/site_amostras/site_amostras/analises.py", line 15, in ?
    from site_amostras import segmentos
  File "/home/godoy/.eclipse/LATAM/site_amostras/site_amostras/segmentos.py", line 27, in ?
    from site_amostras.formularios import grid_segmentos, formulario_segmentos
  File "/home/godoy/.eclipse/LATAM/site_amostras/site_amostras/formularios.py", line 145, in ?
    label = lazy_gettext(
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/base.py", line 44, in widgetinit
    func(self, *args, **kw)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/widgets/forms.py", line 554, in __init__
    self.javascript=[JSLink(static, "calendar.js"),
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/i18n/tg_gettext.py", line 100, in __str__
    return str(self.eval())
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/i18n/tg_gettext.py", line 94, in eval
    return self.func(*self.args, **self.kw)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/i18n/tg_gettext.py", line 46, in gettext
    return gettext_f(key, locale, domain)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/i18n/tg_gettext.py", line 55, in _gettext
    if locale is None:locale = get_locale()
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/i18n/utils.py", line 64, in get_locale
    locale = get_locale_f()
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/i18n/utils.py", line 77, in _get_locale
    locale = cherrypy.session.get(locale_key)
  File "/usr/lib/python2.4/site-packages/CherryPy-2.2.0beta-py2.4.egg/cherrypy/filters/sessionfilter.py", line 413, in __getattr__
    sess = cherrypy.request._session
  File "/usr/lib/python2.4/site-packages/CherryPy-2.2.0beta-py2.4.egg/cherrypy/__init__.py", line 42, in __getattr__
    childobject = getattr(serving, self.__attrname__)
AttributeError: 'thread._local' object has no attribute 'request'

Attachments

controllers.py Download (893 bytes) - added by anonymous 13 years ago.
welcome.kid Download (557 bytes) - added by anonymous 13 years ago.

Change History

comment:1 Changed 13 years ago by michele

Did you open a ticket the first time (for the old widgets)?

comment:2 Changed 13 years ago by Jorge Godoy <jgodoy@…>

I had no problem with old widgets. They worked just fine. Only new style widgets are problematic.

comment:3 Changed 13 years ago by michele

You had a problem with old widgets, ticket is #485, but the strange thing is that the problem was solved on i18n not on widgets. :-(

comment:4 Changed 13 years ago by Jorge Godoy <jgodoy@…>

#485 was because I was using "_" instead of lazy_gettext. Now I'm using lazy_gettext but the error started happening again. This mistake that happened in #485 was the reason I proposed mapping "_" to lazy_gettext automatically for everything or at least for widgets, to make it an 'universal' solution for I18N.

Without changing anything on my working code the problem started happening again, but this time I am using lazy_gettext...

comment:5 Changed 13 years ago by alberto@…

Jorge,

This is strange... I'm trying to reproduce your problem but I can't... It works flawlessly in my system (python 2.4.1 + pristine clean r694 + all thirdparty up to date). I'm attaching a welcome.kid and a controllers.py for you to try on freshly quickstarted project. Please report back.

Thanks, Alberto

Changed 13 years ago by anonymous

Changed 13 years ago by anonymous

comment:6 Changed 13 years ago by anonymous

Well, I've lied, the second button doesn't pop a calendar, but that's because both textfields hace the same id :)

comment:7 Changed 13 years ago by Jorge Godoy <jgodoy@…>

I've just started the project, copied the attached files over the created ones and ran start-project.py.

The following traceback appears:

Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/CherryPy-2.2.0beta-py2.4.egg/cherrypy/_cphttptools.py", line 99, in _run
    self.main()
  File "/usr/lib/python2.4/site-packages/CherryPy-2.2.0beta-py2.4.egg/cherrypy/_cphttptools.py", line 247, in main
    body = page_handler(*virtual_path, **self.params)
  File "<string>", line 3, in index
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/controllers.py", line 188, in expose
    func, tg_format, html, fragment, *args, **kw)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/database.py", line 193, in run_with_transaction
    retval = func(*args, **kw)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/controllers.py", line 205, in _execute_func
    return _process_output(tg_format, output, html, fragment)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/controllers.py", line 68, in _process_output
    fragment=fragment)
  File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/view.py", line 60, in render
    return engine.render(info, format, fragment, template)
  File "/usr/lib/python2.4/site-packages/TurboKid-0.9.0-py2.4.egg/turbokid/kidsupport.py", line 122, in render
    tclass = self.load_template(template)
  File "/usr/lib/python2.4/site-packages/TurboKid-0.9.0-py2.4.egg/turbokid/kidsupport.py", line 94, in load_template
    "%s.kid" % basename)
  File "/usr/lib/python2.4/site-packages/setuptools-0.6a10dev_r41995-py2.4.egg/pkg_resources.py", line 676, in resource_filename
    return get_provider(package_or_requirement).get_resource_filename(
  File "/usr/lib/python2.4/site-packages/setuptools-0.6a10dev_r41995-py2.4.egg/pkg_resources.py", line 119, in get_provider
    __import__(moduleOrReq)
ImportError: No module named tgtest.templates

comment:8 Changed 13 years ago by alberto@…

ooops, sorry, replace tgtest for the name of you test project (I think you need a cup of that Brazillian strong coffee... :D )

Well, gotta go now... they're pulling me from my hair away from the computer...be back tomorrow.

good luck, Alberto

comment:9 Changed 13 years ago by Jorge Godoy <jgodoy@…>

  • Status changed from new to closed
  • Resolution set to invalid

Indeed, I am needing some strong coffee... Again. :-)

It worked here... :-( (Un?)Fortunately. I'll check my code again. The weirdest thing is that if I go back to r665 everything works without a glitch. Updating to r694 breaks it.

Time for some coffee + ice cream. It is too hot...

I'm closing this as invalid since it worked with a new project.

comment:10 Changed 13 years ago by bjourne@…

  • Status changed from closed to reopened
  • Resolution invalid deleted

Hi. I'm having the same problem as this ticket describes using svn checkout 713. I can consistently reproduce the traceback by both adding "sessionFilter.on = True" to devcfg.py and by wrapping a string with the _() function. If I do either or, it works fine. This testcase (created from a clean run of "tg-admin quickstart") demonstrates it:  http://tg.pastebin.com/546644 The traceback I get is:

Traceback (most recent call last):
  File "start-testproj.py", line 24, in ?
    from testproj.controllers import Root
  File "/home/bjourne/python/turbogears/testproj/testproj/controllers.py", line 4, in ?
    foo = _("HEJ")
  File "/usr/lib/python2.4/site-packages/TurboGears-0.9a0dev_r713-py2.4.egg/turbogears/i18n/tg_gettext.py", line 46, in gettext
    return gettext_f(key, locale, domain)
  File "/usr/lib/python2.4/site-packages/TurboGears-0.9a0dev_r713-py2.4.egg/turbogears/i18n/tg_gettext.py", line 55, in _gettext
    if locale is None:locale = get_locale()
  File "/usr/lib/python2.4/site-packages/TurboGears-0.9a0dev_r713-py2.4.egg/turbogears/i18n/utils.py", line 64, in get_locale
    locale = get_locale_f()
  File "/usr/lib/python2.4/site-packages/TurboGears-0.9a0dev_r713-py2.4.egg/turbogears/i18n/utils.py", line 77, in _get_locale
    locale = cherrypy.session.get(locale_key)
  File "/usr/lib/python2.4/site-packages/CherryPy-2.2.0beta-py2.4.egg/cherrypy/filters/sessionfilter.py", line 413, in __getattr__
    sess = cherrypy.request._session
  File "/usr/lib/python2.4/site-packages/CherryPy-2.2.0beta-py2.4.egg/cherrypy/__init__.py", line 42, in __getattr__
    childobject = getattr(serving, self.__attrname__)
AttributeError: 'thread._local' object has no attribute 'request'

comment:11 Changed 13 years ago by alberto

  • Status changed from reopened to closed
  • Resolution set to fixed

take a look atr #485, to summarize: you need to use lazy_gettext when outside a request. There was a discussion at  http://groups.google.co.uk/group/turbogears/browse_thread/thread/7c6d4ec1dc4147db/105b726920635bff?q=lazy_gettext&rnum=1#105b726920635bff in which a decision was made to map _ to lazy_getetxt where applicable... I'm gonna open up a ticket on this one.

Note: See TracTickets for help on using tickets.