Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install django-cuddlybuddly-ecb

How to install django-cuddlybuddly-ecb

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install django-cuddlybuddly-ecb
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.0 Available View build log
Windows (64-bit)
1.0 Available View build log
Mac OS X (10.5+)
1.0 Available View build log
Linux (32-bit)
1.0 Available View build log
Linux (64-bit)
1.0 Available View build log
 
License
BSD
Dependencies
Lastest release
version 1.0 on May 23rd, 2012

A Django app to convert currencies using the feed from the European Central Bank. Includes manager methods and template tags.

Installation

  1. Add cuddlybuddly.ecb to your INSTALLED_APPS.
  2. Run manage.py syncdb
  3. Create a cron job to run the equivalent of manage.py cb_ecb_update once per day.
  4. Add {% load ecb_tags %} to the templates where you wish to use the template tags.

Settings

CUDDLYBUDDLY_ECB_BASE

Takes the three letter currency code (ISO 4217) of your base currency, i.e. the currency your are storing things in. It defaults to usd.

The value of this setting is used as the default currency to convert from when using the convert manager method or the ecb template tag. In these circumstances using this setting will save you some typing.

CUDDLYBUDDLY_ECB_NON2DP

Some currencies do not use two decimal places. The most obvious being the Japanese Yen with zero, but Wikipedia lists some that even use one or three decimal places.

When converting 1.00 USD to JPY you do not want it to come out as 98.00, but as 98. This setting solves that.

By default this setting comes setup for the Japanese Yen (JPY) and Chinese Renminbi (CNY). I was too lazy to find out exactly what needs to be done for every currency so if you need more just add them yourself.

The default:

{
    0: ('jpy', 'cny')
}

This means to convert JPY and CNY to 0 decimal places.

While useless, you might set the following to also convert USD to two decimal places:

{
    0: ('jpy', 'cny'),
    2: ('usd',)
}

Manager Methods

The ExchangeRates model has the following manager methods available:

convert(value, to_currency, from_currency=CUDDLYBUDDLY_ECB_BASE)

Converts value to to_currency from from_currency.

If value cannot be successfully converted to a decimal.Decimal object or either to_currency or from_currency are invalid codes (i.e. they don't exist or the ECB feed doesn't support them) then 0.00 will be returned. Remember to take this into account if your are using this app for anything other than representational purposes. A user on a shopping site will be able to tell that 0.00 is most likely a mistake, but can your code?

get_updated_on()

Returns a datetime object of when the ECB feed was last accessed.

Template Tags

ecb

This is basically a wrapper to access the convert() method on the ExchangeRates manager.

Usage:

{% ecb value to_currency %}
{% ecb value to_currency as var %}
{% ecb value to_currency from_currency %}
{% ecb value to_currency from_currency as var %}

If value cannot be successfully converted to a decimal.Decimal object or either to_currency or from_currency are invalid codes (i.e. they don't exist or the ECB feed doesn't support them) then 0.00 will be returned.

If CUDDLYBUDDLY_ECB_BASE is set to usd, then the following would output 0.61 (at the time of writing):

{% ecb 1.00 "gbp" %}

However, we can override the base currency and the following would output 0.62:

{% ecb 100 "gbp" "jpy" %}
ecb_last_update

This is basically a wrapper to accesss the get_updated_on method on the ExchangeRates manager.

Usage:

{% ecb_last_update %}
{% ecb_last_update as var %}

You can supply it to the default Django date filter if you wish to format it differently.

Subscribe to package updates

Last updated May 23rd, 2012

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.