Here are the examples of the python api django.db.utils.DataError taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
4 Examples
3
View Complete Implementation : duration.py
Copyright MIT License
Author : openfun
Copyright MIT License
Author : openfun
@staticmethod
def from_db_value(value, *_args):
"""Convert a database value to a list value."""
if not value:
return None
try:
duration, unit = value.split("|")
except ValueError:
raise DataError(
"Value in database should be of the form '{duration:d}|{unit:s}'"
)
if not duration:
return None
return int(duration), unit
3
View Complete Implementation : duration.py
Copyright MIT License
Author : openfun
Copyright MIT License
Author : openfun
def to_python(self, value):
"""Convert a string value to a list value. Used for deserialization and in clean forms."""
if isinstance(value, (list, tuple)):
return value
if not value:
return None
if isinstance(value, str):
try:
duration, unit = value.split("|")
except ValueError:
raise DataError(
"Value in database should be of the form '{duration:d}|{unit:s}'"
)
return int(duration.strip()), unit.strip()
return value
3
View Complete Implementation : effort.py
Copyright MIT License
Author : openfun
Copyright MIT License
Author : openfun
@staticmethod
def from_db_value(value, *_args):
"""Convert a database value to a list value."""
if not value:
return None
try:
duration, unit, reference = value.split("|")
except ValueError:
raise DataError(
"Value in database should be of the form '{duration:d}|{unit:s}|{reference:s}'"
)
if not duration:
return None
return int(duration), unit, reference
3
View Complete Implementation : effort.py
Copyright MIT License
Author : openfun
Copyright MIT License
Author : openfun
def to_python(self, value):
"""Convert a string value to a list value. Used for deserialization and in clean forms."""
if isinstance(value, (list, tuple)):
return value
if not value:
return None
if isinstance(value, str):
try:
duration, unit, reference = value.split("|")
except ValueError:
raise DataError(
"Value in database should be of the form '{duration:d}|{unit:s}|{reference:s}'"
)
return int(duration.strip()), unit.strip(), reference.strip()
return value