Simple app to manage currencies conversion in Django using openexchangerates.org service.
Project description
# Django Easy Currencies
Simple app to manage currencies convertion in Django using [openexchangerates.org](https://openexchangerates.org) service.
The app will automatically invokes the service and in a **single HTTP call** it will creates all the necessary conversion rates permutations offline **by "bypassing" the free account limitation which limits the source currency to USD** using simple math alghoritms and the excellent Python's `itertools` utilities (so this is 100% legal!).
---
## Quick start
### Installation
1. Get an app key from [openexchangerates.org](https://openexchangerates.org) (you don't need to pay, the basic free account will be enough)
2. Add "django_easy_currencies" to your `INSTALLED_APPS` setting like this:
```
INSTALLED_APPS = (
...
'django_easy_currencies',
)
```
3. Configure the app by providing your app id and the currencies you want to use like this:
```
EASY_CURRENCIES = {
'currencies': (
('USD', 'US Dollar'),
('EUR', 'Euro'),
('GBP', 'British Pound'),
('AUD', 'Australian Dollar'),
('CAD', 'Canadian Dollar'),
('CHF', 'Swiss Franc'),
('JPY', 'Japanese Yen'),
),
'app_id': os.environ['EASY_CURRENCIES_APP_ID']
}
```
**Just a note**: *An environment variable holding your app id is a best practice but is not mandatory, you can define it inline in your settings.py*
4. Include the "**django_easy_currencies**" URLconf in your project urls.py like this:
```
url(r'^currency/', include('django_easy_currencies.urls')),
```
5. Add the "**django_easy_currencies**" context processor to your existent processors like this:
```
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as BASE_CONTEXT_PROCESSORS
TEMPLATE_CONTEXT_PROCESSORS = BASE_CONTEXT_PROCESSORS + (
'django_easy_currencies.context_processors.currency',
)
```
6. Run `python manage.py migrate` to create the app models.
7. Run the custom management command `python manage.py currencies --update` to save currency rates in your database.
*You should run this command at least once a day in order to have updated rates (automatization of this step is up to you)*
8. (Optional) Run `python manage.py currencies --list` to see the loaded currency rates
### Change active currency
The default currency automatically activated by the context porcessor is "**USD**".
To change it "**django_easy_currencies**" provides a custom tag which prints a combo with all the available currencies and calls `ChangeCurrencyView` as soon the user select a new option.
To use the tag you just need to:
1. Load the tag library:
`{% load currencies %}`
2. Use the tag:
`{% currencies_combo %}`
### Display localized currencies in templates
1. Load the tag library:
`{% load currencies %}`
2. Use the custom tag to display the converted price:
`{% local_currency original_price original_currency %}`
The tag will convert the `original_price` using `original_currency` into the currenct active currency (which is available in template context as "`active_currency`"). And formatting it with the right currency symbol.
So, supposing you are going to print a localized book price which originally is **39.50 USD **and the active currency is **EUR**, the result will be something like: **€ 31,26**.
And in the template it will looks like:
`{% local_currency book.price 'USD' %}`
or
`{% local_currency book.price book.original_currency %}`
It's also possible to skip number formatting by passing `False` as the third tag argument:
`{% local_currency book.price 'USD' False %}`
In this way the output will be simply: **31.26**
Simple app to manage currencies convertion in Django using [openexchangerates.org](https://openexchangerates.org) service.
The app will automatically invokes the service and in a **single HTTP call** it will creates all the necessary conversion rates permutations offline **by "bypassing" the free account limitation which limits the source currency to USD** using simple math alghoritms and the excellent Python's `itertools` utilities (so this is 100% legal!).
---
## Quick start
### Installation
1. Get an app key from [openexchangerates.org](https://openexchangerates.org) (you don't need to pay, the basic free account will be enough)
2. Add "django_easy_currencies" to your `INSTALLED_APPS` setting like this:
```
INSTALLED_APPS = (
...
'django_easy_currencies',
)
```
3. Configure the app by providing your app id and the currencies you want to use like this:
```
EASY_CURRENCIES = {
'currencies': (
('USD', 'US Dollar'),
('EUR', 'Euro'),
('GBP', 'British Pound'),
('AUD', 'Australian Dollar'),
('CAD', 'Canadian Dollar'),
('CHF', 'Swiss Franc'),
('JPY', 'Japanese Yen'),
),
'app_id': os.environ['EASY_CURRENCIES_APP_ID']
}
```
**Just a note**: *An environment variable holding your app id is a best practice but is not mandatory, you can define it inline in your settings.py*
4. Include the "**django_easy_currencies**" URLconf in your project urls.py like this:
```
url(r'^currency/', include('django_easy_currencies.urls')),
```
5. Add the "**django_easy_currencies**" context processor to your existent processors like this:
```
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as BASE_CONTEXT_PROCESSORS
TEMPLATE_CONTEXT_PROCESSORS = BASE_CONTEXT_PROCESSORS + (
'django_easy_currencies.context_processors.currency',
)
```
6. Run `python manage.py migrate` to create the app models.
7. Run the custom management command `python manage.py currencies --update` to save currency rates in your database.
*You should run this command at least once a day in order to have updated rates (automatization of this step is up to you)*
8. (Optional) Run `python manage.py currencies --list` to see the loaded currency rates
### Change active currency
The default currency automatically activated by the context porcessor is "**USD**".
To change it "**django_easy_currencies**" provides a custom tag which prints a combo with all the available currencies and calls `ChangeCurrencyView` as soon the user select a new option.
To use the tag you just need to:
1. Load the tag library:
`{% load currencies %}`
2. Use the tag:
`{% currencies_combo %}`
### Display localized currencies in templates
1. Load the tag library:
`{% load currencies %}`
2. Use the custom tag to display the converted price:
`{% local_currency original_price original_currency %}`
The tag will convert the `original_price` using `original_currency` into the currenct active currency (which is available in template context as "`active_currency`"). And formatting it with the right currency symbol.
So, supposing you are going to print a localized book price which originally is **39.50 USD **and the active currency is **EUR**, the result will be something like: **€ 31,26**.
And in the template it will looks like:
`{% local_currency book.price 'USD' %}`
or
`{% local_currency book.price book.original_currency %}`
It's also possible to skip number formatting by passing `False` as the third tag argument:
`{% local_currency book.price 'USD' False %}`
In this way the output will be simply: **31.26**
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Close
Hashes for django-easy-currencies-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38bfb7ede8fab1dbc9d14d1f0dea807b69d21e3ad16b1edc59842b330bc95b85 |
|
MD5 | 7d1c3bd15ea0f1d871abcf2545727626 |
|
BLAKE2b-256 | 19e075e4daff7f310c38604c1d46a87483dc65f84dfd425b5f030a6ce3e71b05 |
Close
Hashes for django_easy_currencies-0.1.1-py2.7.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | c11e4144024360a090fec10939f83dda4906461f2eec1c19d12242b0da726fd0 |
|
MD5 | f3f2d77638fe98ccb585c30b667af050 |
|
BLAKE2b-256 | c1b1f9011abb481f7f82bfaab8d55825c9e3f672e4d9a2603ada80b9f91de172 |
Close
Hashes for django-easy-currencies-0.1.1.macosx-10.8-x86_64.exe
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5377aa16aebfb54c5d972ec7e0dd755a479ea0e87282b10a6f796f4677fd12c7 |
|
MD5 | e50866175f30257ffd7fb6e7586a6c31 |
|
BLAKE2b-256 | a7e3353e24fc4a3569728de642b4bd41556b06ae27de3b32e4fa5cf9bbbe41a9 |