Example #1
0
def price(val, args=None):
	if isinstance(args, types.StringTypes) and ',' in args:
		currency, decimal_pos = args.split(',', 1)
		decimal_pos = int(decimal_pos)
	else:
		currency = args
		decimal_pos = None
	if isinstance(currency, types.StringTypes):
		currency = Currency.objects.get(code=currency)
	try:
		float(val)
	except:
		return ''
	
	if currency is None:
		currency = Currency.objects.get_default()
	elif isinstance(currency, types.StringTypes):
		currency = Currency.objects.get(code=currency)
	
	if decimal_pos == "" or decimal_pos is None:
		decimal_pos = currency.decimal_places
	
	if not decimal_pos and val is not None and not float(val).is_integer():
		# if decimal places would hide some part of the price
		# and decimal pos is 0, set it to 2
		decimal_pos = 2
	
	if not isinstance(currency, Currency):
		return ''
	return mark_safe(fprc(val, currency, decimal_pos))
Example #2
0
def price(val, args=None):
    if isinstance(args, types.StringTypes) and ',' in args:
        currency, decimal_pos = args.split(',', 1)
        decimal_pos = int(decimal_pos)
    else:
        currency = args
        decimal_pos = None
    if isinstance(currency, types.StringTypes):
        currency = Currency.objects.get(code=currency)
    try:
        float(val)
    except:
        return ''

    if currency is None:
        currency = Currency.objects.get_default()
    elif isinstance(currency, types.StringTypes):
        currency = Currency.objects.get(code=currency)

    if decimal_pos == "" or decimal_pos is None:
        decimal_pos = currency.decimal_places

    if not decimal_pos and val is not None and not float(val).is_integer():
        # if decimal places would hide some part of the price
        # and decimal pos is 0, set it to 2
        decimal_pos = 2

    if not isinstance(currency, Currency):
        return ''
    return mark_safe(fprc(val, currency, decimal_pos))
Example #3
0
def to_default_curr_using_factor(price, factor):
	c = Currency.objects.get_default()
	return mark_safe(fprc(price * factor, c, int(c.decimal_places)))
Example #4
0
def format_price(val, currency, decimal_pos):
	return fprc(val, currency, decimal_pos)
Example #5
0
def to_default_curr_using_factor(price, factor):
    c = Currency.objects.get_default()
    return mark_safe(fprc(price * factor, c, int(c.decimal_places)))
Example #6
0
def format_price(val, currency, decimal_pos):
    return fprc(val, currency, decimal_pos)