MCPcopy Index your code
hub / github.com/encode/django-rest-framework / __init__

Method __init__

rest_framework/fields.py:997–1036  ·  view source on GitHub ↗
(self, max_digits, decimal_places, coerce_to_string=None, max_value=None, min_value=None,
                 localize=False, rounding=None, normalize_output=False, **kwargs)

Source from the content-addressed store, hash-verified

995 MAX_STRING_LENGTH = 1000 # Guard against malicious string inputs.
996
997 def __init__(self, max_digits, decimal_places, coerce_to_string=None, max_value=None, min_value=None,
998 localize=False, rounding=None, normalize_output=False, **kwargs):
999 self.max_digits = max_digits
1000 self.decimal_places = decimal_places
1001 self.localize = localize
1002 self.normalize_output = normalize_output
1003 if coerce_to_string is not None:
1004 self.coerce_to_string = coerce_to_string
1005 if self.localize:
1006 self.coerce_to_string = True
1007
1008 self.max_value = max_value
1009 self.min_value = min_value
1010
1011 if self.max_value is not None and not isinstance(self.max_value, (int, decimal.Decimal)):
1012 warnings.warn("max_value should be an integer or Decimal instance.")
1013 if self.min_value is not None and not isinstance(self.min_value, (int, decimal.Decimal)):
1014 warnings.warn("min_value should be an integer or Decimal instance.")
1015
1016 if self.max_digits is not None and self.decimal_places is not None:
1017 self.max_whole_digits = self.max_digits - self.decimal_places
1018 else:
1019 self.max_whole_digits = None
1020
1021 super().__init__(**kwargs)
1022
1023 if self.max_value is not None:
1024 message = lazy_format(self.error_messages['max_value'], max_value=self.max_value)
1025 self.validators.append(
1026 MaxValueValidator(self.max_value, message=message))
1027 if self.min_value is not None:
1028 message = lazy_format(self.error_messages['min_value'], min_value=self.min_value)
1029 self.validators.append(
1030 MinValueValidator(self.min_value, message=message))
1031
1032 if rounding is not None:
1033 valid_roundings = [v for k, v in vars(decimal).items() if k.startswith('ROUND_')]
1034 assert rounding in valid_roundings, (
1035 'Invalid rounding option %s. Valid values for rounding are: %s' % (rounding, valid_roundings))
1036 self.rounding = rounding
1037
1038 def validate_empty_values(self, data):
1039 if smart_str(data).strip() == '' and self.allow_null:

Callers

nothing calls this directly

Calls 2

lazy_formatClass · 0.90
__init__Method · 0.45

Tested by

no test coverage detected