from datetime import date

from rows import fields


class IntegerField(fields.IntegerField):

    @classmethod
    def deserialize(cls, value, *args, **kwargs):
        try:  # Rows cannot convert values such as '2011.0' to integer
            value = int(float(value))
        except:
            pass
        return super(IntegerField, cls).deserialize(value)


class DateAsStringField(fields.DateField):
    INPUT_FORMAT = '%Y-%m-%dT%H:%M:%S'
    OUTPUT_FORMAT = '%Y-%m-%d'

    @classmethod
    def deserialize(cls, value, *args, **kwargs):
        value = super(DateAsStringField, cls).deserialize(value)
        if value:  # useful when serializing it to Celery
            return value.strftime(cls.OUTPUT_FORMAT)

from rows import fields


class IntegerField(fields.IntegerField):

    @classmethod
    def deserialize(cls, value, *args, **kwargs):
        try:  # Rows cannot convert values such as '2011.0' to integer
            value = int(float(value))
        except:
            pass
        return super(IntegerField, cls).deserialize(value)


class DateAsStringField(fields.DateField):
    INPUT_FORMAT = '%Y-%m-%d %H:%M:%S'
    OUTPUT_FORMAT = '%Y-%m-%d'

    @classmethod
    def deserialize(cls, value, *args, **kwargs):
        value = value.replace('T', ' ')  # normalize date/time separator
        return super(DateAsStringField, cls).deserialize(value)

Make date imports more flexible
Make date imports more flexible

Now ut works with `YYYY-MM-DD HH:MM:SS` and with `YYYY-MM-DDTHH:MM:SS`.

- from datetime import date
- 
  from rows import fields
  
  
  class IntegerField(fields.IntegerField):
  
      @classmethod
      def deserialize(cls, value, *args, **kwargs):
          try:  # Rows cannot convert values such as '2011.0' to integer
              value = int(float(value))
          except:
              pass
          return super(IntegerField, cls).deserialize(value)
  
  
  class DateAsStringField(fields.DateField):
-     INPUT_FORMAT = '%Y-%m-%dT%H:%M:%S'
+     INPUT_FORMAT = '%Y-%m-%d %H:%M:%S'
      OUTPUT_FORMAT = '%Y-%m-%d'
  
      @classmethod
      def deserialize(cls, value, *args, **kwargs):
+         value = value.replace('T', ' ')  # normalize date/time separator
-         value = super(DateAsStringField, cls).deserialize(value)
+         return super(DateAsStringField, cls).deserialize(value)
-         if value:  # useful when serializing it to Celery
-             return value.strftime(cls.OUTPUT_FORMAT)
  
Make date imports more flexible
## Code Before:
from datetime import date

from rows import fields


class IntegerField(fields.IntegerField):

    @classmethod
    def deserialize(cls, value, *args, **kwargs):
        try:  # Rows cannot convert values such as '2011.0' to integer
            value = int(float(value))
        except:
            pass
        return super(IntegerField, cls).deserialize(value)


class DateAsStringField(fields.DateField):
    INPUT_FORMAT = '%Y-%m-%dT%H:%M:%S'
    OUTPUT_FORMAT = '%Y-%m-%d'

    @classmethod
    def deserialize(cls, value, *args, **kwargs):
        value = super(DateAsStringField, cls).deserialize(value)
        if value:  # useful when serializing it to Celery
            return value.strftime(cls.OUTPUT_FORMAT)

## Instruction:
Make date imports more flexible
## Code After:
from rows import fields


class IntegerField(fields.IntegerField):

    @classmethod
    def deserialize(cls, value, *args, **kwargs):
        try:  # Rows cannot convert values such as '2011.0' to integer
            value = int(float(value))
        except:
            pass
        return super(IntegerField, cls).deserialize(value)


class DateAsStringField(fields.DateField):
    INPUT_FORMAT = '%Y-%m-%d %H:%M:%S'
    OUTPUT_FORMAT = '%Y-%m-%d'

    @classmethod
    def deserialize(cls, value, *args, **kwargs):
        value = value.replace('T', ' ')  # normalize date/time separator
        return super(DateAsStringField, cls).deserialize(value)
