# Path: pyoko/lib/utils.py
# class lazy_property(object):
#     """
#     Meant to be used for lazy evaluation of an object attribute.
#     property should represent non-mutable data, as it replaces itself.
# 
#     from: http://stackoverflow.com/a/6849299/454130
#     """
# 
#     def __init__(self, fget):
#         self.fget = fget
#         self.func_name = fget.__name__
# 
#     def __get__(self, obj, cls):
#         if obj is None:
#             return None
#         value = self.fget(obj)
#         obj.__dict__[self.func_name] = value
#         return value
# 
# def get_object_from_path(path):
#     """
#     Import's object from given Python path.
#     """
#     try:
#         return sys.IMPORT_CACHE[path]
#     except KeyError:
#         _path = path.split('.')
#         module_path = '.'.join(_path[:-1])
#         class_name = _path[-1]
#         module = importlib.import_module(module_path)
#         sys.IMPORT_CACHE[path] = getattr(module, class_name)
#         return sys.IMPORT_CACHE[path]
# 
# Path: pyoko/exceptions.py
# class ValidationError(PyokoError):
#     pass
# 
# Path: pyoko/conf.py
# class Settings(object):
#     def __init__(self):


import datetime
import time
import uuid
import six
from pyoko.lib.utils import lazy_property, get_object_from_path
from pyoko.exceptions import ValidationError
from pyoko.conf import settings
        # instance._field_values[self.name] = value

    def clean_value(self, val):
        if not val:
            return self.default() if callable(self.default) else self.default
        else:
            return val.strftime(DATE_FORMAT)

    def _load_data(self, instance, value):
        if value is None or value == EMPTY_DATETIME:
            value = ''
        else:
            try:
                value = datetime.datetime.strptime(value, DATE_FORMAT).date()
            except ValueError:
                value = datetime.datetime.strptime(value, self.format).date()
        instance._field_values[self.name] = value


class Integer(BaseField):
    # TODO: add checks for solr's int field's limits
    # TODO: add support for solr's long int field
    solr_type = 'int'
    # default_value = 0

    def clean_value(self, val):
        if val is not None:
            try:
                return int(val)
            except ValueError:

# Path: pyoko/lib/utils.py
# class lazy_property(object):
#     """
#     Meant to be used for lazy evaluation of an object attribute.
#     property should represent non-mutable data, as it replaces itself.
# 
#     from: http://stackoverflow.com/a/6849299/454130
#     """
# 
#     def __init__(self, fget):
#         self.fget = fget
#         self.func_name = fget.__name__
# 
#     def __get__(self, obj, cls):
#         if obj is None:
#             return None
#         value = self.fget(obj)
#         obj.__dict__[self.func_name] = value
#         return value
# 
# def get_object_from_path(path):
#     """
#     Import's object from given Python path.
#     """
#     try:
#         return sys.IMPORT_CACHE[path]
#     except KeyError:
#         _path = path.split('.')
#         module_path = '.'.join(_path[:-1])
#         class_name = _path[-1]
#         module = importlib.import_module(module_path)
#         sys.IMPORT_CACHE[path] = getattr(module, class_name)
#         return sys.IMPORT_CACHE[path]
# 
# Path: pyoko/exceptions.py
# class ValidationError(PyokoError):
#     pass
# 
# Path: pyoko/conf.py
# class Settings(object):
#     def __init__(self):


# Path: pyoko/fields.py
import datetime
import time
import uuid
import six
from pyoko.lib.utils import lazy_property, get_object_from_path
from pyoko.exceptions import ValidationError
from pyoko.conf import settings

        # instance._field_values[self.name] = value

    def clean_value(self, val):
        if not val:
            return self.default() if callable(self.default) else self.default
        else:
            return val.strftime(DATE_FORMAT)

    def _load_data(self, instance, value):
        if value is None or value == EMPTY_DATETIME:
            value = ''
        else:
            try:
                value = datetime.datetime.strptime(value, DATE_FORMAT).date()
            except ValueError:
                value = datetime.datetime.strptime(value, self.format).date()
        instance._field_values[self.name] = value


class Integer(BaseField):
    # TODO: add checks for solr's int field's limits
    # TODO: add support for solr's long int field
    solr_type = 'int'
    # default_value = 0

    def clean_value(self, val):
        if val is not None:
            try:
                return int(val)
            except ValueError:

                raise ValidationError("%r could not be cast to integer" % val)