Esempio n. 1
0
 def __init__(self, attrs=None, format=None):
     super(DateTimeInput, self).__init__(attrs)
     if format:
         self.format = format
         self.manual_format = True
     else:
         self.format = formats.get_format('DATETIME_INPUT_FORMATS')[0]
         self.manual_format = False
Esempio n. 2
0
 def _has_changed(self, initial, data):
     # If our field has show_hidden_initial=True, initial will be a string
     # formatted by HiddenInput using formats.localize_input, which is not
     # necessarily the format used for this  widget. Attempt to convert it.
     try:
         input_format = formats.get_format('TIME_INPUT_FORMATS')[0]
         initial = datetime.datetime.strptime(initial, input_format).time()
     except (TypeError, ValueError):
         pass
     return super(TimeInput, self)._has_changed(self._format_value(initial), data)
Esempio n. 3
0
 def __init__(self, attrs=None, format=None):
     attrs = attrs or {}
     attrs.setdefault('maxlength',8)
     super(TimeInput, self).__init__(attrs)
     if format:
         self.format = format
         self.manual_format = True
     else:
         self.format = formats.get_format('TIME_INPUT_FORMATS')[0]
         self.manual_format = False
Esempio n. 4
0
    def __init__(self, amount=Decimal("0.0"), currency=None):
        if isinstance(amount, OriginalMoney):
            try:
                amount = amount.amount
            except AttributeError: # just in case python-money is not installed (Decimal assumes as OriginalMoney)
                pass
        currency = currency or settings.DEFAULT_CURRENCY

        if OriginalMoney == Decimal:
            OriginalMoney.__init__(self, amount)
            self.amount = amount
            self.currency = currency
        else:
            OriginalMoney.__init__(self, str(amount).replace(get_format('THOUSAND_SEPARATOR'),''), currency)
Esempio n. 5
0
 def __eq__(self, other):
     if other is None:
         return False
     if isinstance(other, Money):
         return (self.amount == other.amount) and (self.currency == other.currency)
     return self.amount == Decimal(str(other).replace(get_format('THOUSAND_SEPARATOR'),''))
Esempio n. 6
0
 def __str__(self):
     return number_format(self.amount, decimal_pos=get_format('DECIMAL_PLACES'))