Beispiel #1
0
 def _convert_field_value(self, field, value, filter_type, db_module):
     data_type = field.data_type
     if filter_type and filter_type in [
             common.FILTER_CONTAINS, common.FILTER_STARTWITH,
             common.FILTER_ENDWITH
     ]:
         if data_type == common.FLOAT:
             value = common.str_to_float(value)
         elif data_type == common.CURRENCY:
             value = common.str_to_currency(value)
         if type(value) == float:
             if int(value) == value:
                 value = str(int(value)) + '.'
             else:
                 value = str(value)
         return value
     else:
         if data_type == common.DATE:
             if type(value) in string_types:
                 result = value
             else:
                 result = value.strftime('%Y-%m-%d')
             return db_module.cast_date(result)
         elif data_type == common.DATETIME:
             if type(value) in string_types:
                 result = value
             else:
                 result = value.strftime('%Y-%m-%d %H:%M')
             result = db_module.cast_datetime(result)
             return result
         elif data_type == common.INTEGER:
             if type(value) == int or type(
                     value) in string_types and value.isdigit():
                 return str(value)
             else:
                 return "'" + value + "'"
         elif data_type == common.BOOLEAN:
             if value:
                 return '1'
             else:
                 return '0'
         elif data_type == common.TEXT:
             #~ return "'" + str(value) + "'"
             return "'" + to_unicode(value) + "'"
         elif data_type in (common.FLOAT, common.CURRENCY):
             return str(float(value))
         else:
             return value
Beispiel #2
0
 def _convert_field_value(self, field, value, filter_type, db_module):
     data_type = field.data_type
     if filter_type and filter_type in [common.FILTER_CONTAINS, common.FILTER_STARTWITH, common.FILTER_ENDWITH]:
         if data_type == common.FLOAT:
             value = common.str_to_float(value)
         elif data_type == common.CURRENCY:
             value = common.str_to_currency(value)
         if type(value) == float:
             if int(value) == value:
                 value = str(int(value)) + '.'
             else:
                 value = str(value)
         return value
     else:
         if data_type == common.DATE:
             if type(value) in string_types:
                 result = value
             else:
                 result = value.strftime('%Y-%m-%d')
             return db_module.cast_date(result)
         elif data_type == common.DATETIME:
             if type(value) in string_types:
                 result = value
             else:
                 result = value.strftime('%Y-%m-%d %H:%M')
             result = db_module.cast_datetime(result)
             return result
         elif data_type == common.INTEGER:
             if type(value) in integer_types or type(value) in string_types and value.isdigit():
                 return str(value)
             else:
                 return "'" + value + "'"
         elif data_type == common.BOOLEAN:
             if value:
                 return '1'
             else:
                 return '0'
         elif data_type == common.TEXT:
             #~ return "'" + str(value) + "'"
             return "'" + to_unicode(value) + "'"
         elif data_type in (common.FLOAT, common.CURRENCY):
             return str(float(value))
         else:
             return value