def normalize_decimal(value, args=""):
    '''
    A template_tag wrapper to round_decimal.

    Usage:
    val|normalize_decimal
    val|normalize_decimal:'places=2'
    val|normalize_decimal:'places=2:roundfactor=.5'
    val|normalize_decimal:'places=2:roundfactor=.5:normalize=False'

    '''
    if value == '' or value is None:
        return value
    args, kwargs = get_filter_args(args,
            keywords=('places','roundfactor','normalize'),
            intargs=('places',),
            boolargs=('normalize',), stripquotes=True)

    if not 'places' in kwargs:
        kwargs['places'] = 2

    print 'val : %s' % round_decimal(val=value, **kwargs)
    try:
        return mark_safe(str(round_decimal(val=value, **kwargs)))
    
    except RoundedDecimalError, e:
        return value
Beispiel #2
0
def _get_payment_settings():
    payment_settings = settings.PAYMENT_PAGE_VARS
    payment_settings['x_fp_timestamp'] = round_decimal(time.time(), 0)
    payment_settings['x_amount'] = round_decimal(34.23, 2)
    payment_settings['x_fp_hash'] = _get_hash(payment_settings)
    payment_settings['x_fp_hash_str'] = _get_hash_string(payment_settings)
    return payment_settings
Beispiel #3
0
    def _sub_total(self):
        items = self.orderitem_set.all()
        sub_total = 0
        for item in items:
            sub_total += item.product.price * item.quantity

        return round_decimal(sub_total, 2)
Beispiel #4
0
 def _total(self):
     return round_decimal(float(self.sub_total) + float(self.tax_amount), 2)
Beispiel #5
0
 def _tax_amount(self):
     '''
     Assume 15% taxes to make things simple.
     '''
     return round_decimal(float(self.sub_total) * 0.15, 2)
Beispiel #6
0
 def _line_item_total(self):
     return round_decimal(float(self.product.price) * float(self.quantity), 2)
Beispiel #7
0
 def __unicode__(self):
     return u'%s : $%s' % (self.photo.title, round_decimal(self.price, 2))