Skip to content

Commit

Permalink
Initial modifications for oxr alternative currencies panosl#62
Browse files Browse the repository at this point in the history
  • Loading branch information
racitup committed Nov 30, 2018
1 parent e4a03ca commit 6d14533
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion currencies/management/commands/_openexchangerates.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, *args):
if not APP_ID:
raise ImproperlyConfigured(
"You need to set the 'OPENEXCHANGERATES_APP_ID' setting to your openexchangerates.org api key")
self.client = OpenExchangeRatesClient(APP_ID)
self.client = OpenExchangeRatesClient(APP_ID, show_alternative=True)
self.endpoint = self.client.ENDPOINT_CURRENCIES
super(CurrencyHandler, self).__init__(*args)

Expand Down
7 changes: 5 additions & 2 deletions currencies/management/commands/_openexchangerates_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ class OpenExchangeRatesClient(object):
ENDPOINT_CURRENCIES = BASE_URL + '/currencies.json'
ENDPOINT_HISTORICAL = BASE_URL + '/historical/%s.json'

def __init__(self, api_key):
def __init__(self, api_key, show_alternative=False):
"""Convenient constructor"""
self.client = requests.Session()
self.client.params.update({'app_id': api_key})
params = {'app_id': api_key}
if show_alternative:
params.update({'show_alternative': '1'})
self.client.params.update(params)

def latest(self, base='USD'):
"""Fetches latest exchange rate data from service
Expand Down
25 changes: 25 additions & 0 deletions currencies/migrations/0005_code_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-11-30 01:19
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('currencies', '0004_code_primary'),
]

operations = [
migrations.AlterField(
model_name='currency',
name='code',
field=models.CharField(max_length=20, primary_key=True, serialize=False, verbose_name='code'),
),
migrations.AlterField(
model_name='currency',
name='name',
field=models.CharField(db_index=True, max_length=50, verbose_name='name'),
),
]
4 changes: 2 additions & 2 deletions currencies/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
@python_2_unicode_compatible
class Currency(models.Model):

code = models.CharField(_('code'), max_length=3,
code = models.CharField(_('code'), max_length=20,
primary_key=True)
name = models.CharField(_('name'), max_length=35,
name = models.CharField(_('name'), max_length=50,
db_index=True)
symbol = models.CharField(_('symbol'), max_length=4, blank=True,
db_index=True)
Expand Down

0 comments on commit 6d14533

Please sign in to comment.