More getpaid.discount localization issues

2 views
Skip to first unread message

Rob LaRubbio

unread,
Jul 6, 2010, 7:39:30 PM7/6/10
to getpa...@googlegroups.com
I got past my previous issue by removing some extra files in the locales directory (I'm still checking with the committer to see if that is ok).  Now I've run into another localization issue around date formating and forms.

When I submit the form adding my discount to a payable item I get an attribute error looking up self.request.locale. For some reason the HTTPRequest does not have a local associated with it.  The code that fails is:

parts/zope2/lib/python/zope/formlib/form.py(809)handle_edit_action()

805      @action(_("Apply"), condition=haveInputWidgets)
806      def handle_edit_action(self, action, data):
807          if applyChanges(self.context, self.form_fields, data, self.adapters):
808              zope.event.notify(ObjectModifiedEvent(self.context))
809  ->            formatter = self.request.locale.dates.getFormatter(
810                  'dateTime', 'medium')
811  
812              try:
813                  time_zone = idatetime.ITZInfo(self.request)
814              except TypeError:

I can get my own locale object like this while in the pdb session:

from Acquisition import aq_inner
from zope.component import getMultiAdapter

context = aq_inner(self.context)
portal_state = getMultiAdapter((context, self.request), name=u'plone_portal_state')

current_locale = portal_state.locale()

but I'm guessing I shouldn't modify formlib.  I'm also curious why my request doesn't have a local associated with it.  I've run this both in chrome and firefox on os x, firefox sends HTTP_ACCEPT_LANGUAGE in the headers, chrome does not, but it does send en-US in the user agent.  Any thoughts or suggestions on where else I should look?  Thanks.

-Rob

Mikko Ohtamaa

unread,
Jul 6, 2010, 9:59:38 PM7/6/10
to getpaid-dev
Hi,
 
When I submit the form adding my discount to a payable item I get an attribute error looking up self.request.locale. For some reason the HTTPRequest does not have a local associated with it.  The code that fails is:

I might be wrong request.locales is some magical Zope 3 variable which gets set by z2.setup_locale() in plone.z3cform. It is not enabled on Zope 3 by default-

http://svn.zope.org/plone.z3cform/trunk/plone/z3cform/z2.py?rev=109071&view=auto

-Mikko
 

parts/zope2/lib/python/zope/formlib/form.py(809)handle_edit_action()

805      @action(_("Apply"), condition=haveInputWidgets)
806      def handle_edit_action(self, action, data):
807          if applyChanges(self.context, self.form_fields, data, self.adapters):
808              zope.event.notify(ObjectModifiedEvent(self.context))
809  ->            formatter = self.request.locale.dates.getFormatter(
810                  'dateTime', 'medium')
811  
812              try:
813                  time_zone = idatetime.ITZInfo(self.request)
814              except TypeError:

I can get my own locale object like this while in the pdb session:

from Acquisition import aq_inner
from zope.component import getMultiAdapter

context = aq_inner(self.context)
portal_state = getMultiAdapter((context, self.request), name=u'plone_portal_state')

current_locale = portal_state.locale()

but I'm guessing I shouldn't modify formlib.  I'm also curious why my request doesn't have a local associated with it.  I've run this both in chrome and firefox on os x, firefox sends HTTP_ACCEPT_LANGUAGE in the headers, chrome does not, but it does send en-US in the user agent.  Any thoughts or suggestions on where else I should look?  Thanks.

-Rob

--
GetPaid for Plone: http://www.plonegetpaid.com (overview info) | http://code.google.com/p/getpaid (code and issue tracker)
You received this message because you are subscribed to the Google Groups "getpaid-dev" group.
To post to this group, send email to getpa...@googlegroups.com
To unsubscribe from this group, send email to getpaid-dev...@googlegroups.com
 
For more options, visit this group at
http://groups.google.com/group/getpaid-dev?hl=en?hl=en



--
Mikko Ohtamaa
mFabrik - Freedom Delivered.

Web site - http://mfabrik.com
Mobile site - http://mfabrik.mobi
Blog - http://blog.mfabrik.com

Mikko Ohtamaa

unread,
Jul 6, 2010, 10:00:22 PM7/6/10
to getpaid-dev
I might be wrong request.locales is some magical Zope 3 variable which gets set by z2.setup_locale() in plone.z3cform. It is not enabled on Zope 3 by default-
 
Typing error above: it is not enabled on *Zope 2* by default
 

Rob LaRubbio

unread,
Jul 8, 2010, 6:04:03 PM7/8/10
to getpa...@googlegroups.com
Thanks, it looks like adding that got me past my issue.  I do have some questions about the correct way to mark the new dependency on plone.z3cform.

I've currently done this:

in getpaid.discount's setup.py added plone.z3cform to install-requires
in getpaid.discount's configure.xml added:

<include package="plone.z3cform" />

in my buildout cfg (335.cfg from getpaid.buildout)
  added plone.z3cform to buildout:eggs
  pinned plone.z3cform to 0.6.0
  pinned z3c.form to 1.9.0

A lot of that sounds fragile but I'm not sure how to include the dependencies and the versions without breaking anything else.

Also a final question on what is the correct localizable way to print out currency values?  Currently I've just assumed the format is x.xx which I know is not correct.  Thanks.

-Rob

Alberto Berti

unread,
Jul 9, 2010, 4:01:03 AM7/9/10
to getpa...@googlegroups.com

Rob> Also a final question on what is the correct localizable way to
Rob> print out currency values? Currently I've just assumed the
Rob> format is x.xx which I know is not correct. Thanks.

I don't know if plone has a service for this, but python's locale module
can give you all the info you need, have a look at LC_MONETARY
localeconv() category of keys, they should be all you need
http://docs.python.org/library/locale.html .

Rob LaRubbio

unread,
Jul 13, 2010, 12:38:42 PM7/13/10
to getpa...@googlegroups.com
I just wanted to resend this to see if someone could double check to make sure I am including this dependency correct.  I was going to ask on irc today but it doesn't look like anyone is currently online.

My basic question is is there a way to add this dependency to getpaid.discount without forcing users of the package to have to add plone.z3cform to their buildout?  Also is there a better solution then forcing users to pin versions in their buildout?  Thanks.

-Rob

On Thu, Jul 8, 2010 at 3:04 PM, Rob LaRubbio <laru...@gmail.com> wrote:
Thanks, it looks like adding that got me past my issue.  I do have some questions about the correct way to mark the new dependency on plone.z3cform.

I've currently done this:

in getpaid.discount's setup.py added plone.z3cform to install-requires
in getpaid.discount's configure.xml added:

<include package="plone.z3cform" />

in my buildout cfg (335.cfg from getpaid.buildout)
  added plone.z3cform to buildout:eggs
  pinned plone.z3cform to 0.6.0
  pinned z3c.form to 1.9.0

A lot of that sounds fragile but I'm not sure how to include the dependencies and the versions without breaking anything else.

Reply all
Reply to author
Forward
0 new messages