|
|
|
|
@ -5,12 +5,14 @@ from .models import Currency as CurrencyModel |
|
|
|
|
|
|
|
|
|
MAIN_CURRENCY_ID = 1 |
|
|
|
|
DEFAULT_SYMBOL = '₸' # Тенге |
|
|
|
|
DEFAULT_SHORT = 'тг' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Currency(object): |
|
|
|
|
id = '' |
|
|
|
|
exchange = '' |
|
|
|
|
symbol = '' |
|
|
|
|
short = '' |
|
|
|
|
|
|
|
|
|
def __init__(self, request): |
|
|
|
|
self.id = request.session.get('currency_id', None) |
|
|
|
|
@ -20,9 +22,12 @@ class Currency(object): |
|
|
|
|
_currency = CurrencyModel.objects.get(pk=self.id) |
|
|
|
|
self.exchange = _currency.exchange |
|
|
|
|
self.symbol = _currency.HTML_letter_code |
|
|
|
|
self.short = _currency.abridgement |
|
|
|
|
except CurrencyModel.DoesNotExist: |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
_currency = CurrencyModel.objects.get(pk=MAIN_CURRENCY_ID) |
|
|
|
|
self.exchange = _currency.exchange |
|
|
|
|
self.symbol = _currency.HTML_letter_code |
|
|
|
|
self.short = DEFAULT_SHORT |
|
|
|
|
else: |
|
|
|
|
self.id = MAIN_CURRENCY_ID |
|
|
|
|
self.symbol = DEFAULT_SYMBOL |
|
|
|
|
@ -34,7 +39,9 @@ class Currency(object): |
|
|
|
|
try: |
|
|
|
|
_currency = CurrencyModel.objects.get(pk=self.id) |
|
|
|
|
self.symbol = _currency.HTML_letter_code |
|
|
|
|
self.short = _currency.abridgement |
|
|
|
|
self.exchange = _currency.exchange |
|
|
|
|
print(self.short) |
|
|
|
|
except CurrencyModel.DoesNotExist: |
|
|
|
|
self.symbol = DEFAULT_SYMBOL |
|
|
|
|
request.session['currency_id'] = c_id |
|
|
|
|
@ -42,10 +49,14 @@ class Currency(object): |
|
|
|
|
def get_symbol(self): |
|
|
|
|
return Markup(self.symbol) |
|
|
|
|
|
|
|
|
|
def get_short_currency_name(self): |
|
|
|
|
return self.short |
|
|
|
|
|
|
|
|
|
def get_price(self, price): |
|
|
|
|
_price = int(price * self.exchange) |
|
|
|
|
return _price |
|
|
|
|
|
|
|
|
|
def get_string_price(self, price): |
|
|
|
|
return Markup('{price} {code}'.format(price=self.get_price(price), code=self.symbol)) |
|
|
|
|
return Markup('{price} <span class="price__currency">{code}</span>'. |
|
|
|
|
format(price=self.get_price(price), code=self.symbol)) |
|
|
|
|
|
|
|
|
|
|