Currency management in Plone

Hanno Schlichting plone at hannosch.info
Thu Aug 23 22:50:31 UTC 2007


Wichert Akkerman wrote:
> I just released version 1.0b1 of a new product: simplon.plone.currency.
> This is a simple product for Plone 3 that allows you to manage different
> currencies in your site: you can add and remove currencies and manage
> their conversion rates. It includes a database with description and symbols
> for all currencies as well.
> 
> By itself this product is not very useful. It is intended to be used
> as a component in products that need to use currencies in some way. If
> anyone is working on such a product I would love to hear some feedback.
> 
> You can find more information and a downloadable package in the
> python package index:
> http://cheeseshop.python.org/pypi/simplon.plone.currency/1.0b1

I have looked at it briefly and wonder why you didn't reuse the currency
information available in zope.i18n.locales?

While in Zope2 the current locale is not directly available from
REQUEST.locale as in Zope3, with Plone3 it is available from the portal
globals view (plone.app.layout.globals.portal):

  >>> portal_state = queryMultiAdapter((context, request),
  ...     name=u'plone_portal_state')
  >>> locale = portal_state.locale()

If you don't want to have the locale in the currently negotiated
language you can also get a specific one:

  >>> from zope.i18n.locales import locales
  >>> en = locales.getLocale('en', 'us', None)

  >>> pp len(en.numbers.currencies)
  382

  >>> pp en.numbers.currencies[u'USD'].__dict__
  {'displayName': u'US Dollar',
   'symbol': u'US$',
   'symbolChoice': False,
   'type': u'USD'}

If you use this information for the currency information you can also
get currency names translated into every language for free :)

For an example of the latter you can look at the otherwise a bit hairy
LanguageTableWidget in plone.app.controlpanel.widgets. It defines
self.languages in the __init__ and latter on uses it in the textForValue
method. Basically it uses the key of the language to look it up in the
current locale and gets the displayName for it.

HTH,
Hanno





More information about the Product-Developers mailing list