暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

data_field.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: utf-8 -*-
  2. from .field_data_handler import FieldDataHandler
  3. class DataField(FieldDataHandler):
  4. ## @brief Instanciates a new fieldtype
  5. # @param nullable bool : is None allowed as value ?
  6. # @param uniq bool : Indicates if a field should handle a uniq value
  7. # @param primary bool : If true the field is a primary key
  8. # @param internal str|False: if False, that field is not internal. Other values cans be "autosql" or "internal"
  9. # @param **kwargs : Other arguments
  10. # @throw NotImplementedError if called from bad class
  11. def __init__(self, internal=False, nullable=True, uniq=False, primary=False, **kwargs):
  12. if self.__class__ == DataField:
  13. raise NotImplementedError("Abstract class")
  14. super().__init__(internal, **kwargs)
  15. self.nullable = nullable
  16. self.uniq = uniq
  17. self.primary = primary
  18. if 'defaults' in kwargs:
  19. self.default, error = self.check_data_value(kwargs['default'])
  20. if error:
  21. raise error
  22. del(args['default'])
  23. def check_data_value(self, value):
  24. if value is None:
  25. if not self.nullable:
  26. return None, TypeError("'None' value but field is not nullable")
  27. return None, None
  28. return super().check_data_value(value)