base.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #coding=utf-8
  2. class Formater():
  3. @staticmethod
  4. def formatStr(value):
  5. res = u''
  6. if value != None:
  7. try:
  8. res = str(value)
  9. except:
  10. pass
  11. return res
  12. @staticmethod
  13. def formatCount(value):
  14. return int(round(float(value or 0) * 100,0))
  15. @staticmethod
  16. def formatPrice(value):
  17. return int(round(float(value or 0) * 100,0))
  18. @staticmethod
  19. def formatCountShow(value):
  20. return '%.2f' % (float(value or 0)/100.0)
  21. @staticmethod
  22. def formatPriceShow(value):
  23. return '%.2f' % (float(value or 0)/100.0)
  24. @staticmethod
  25. def formatAmount(value):
  26. return int(round(float(value or 0) * 10000,0))
  27. @staticmethod
  28. def formatAmountShow(value):
  29. return '%.2f' % (float(value or 0) / 10000.0 + 0.0000001)
  30. def clean_datetime_range(data, fieldname):
  31. if data is not None and fieldname in data and data[fieldname] != '':
  32. if data is not None:
  33. t = data[fieldname].split(' - ')
  34. # t = data[fieldname]
  35. data = data.copy()
  36. data[fieldname + '_0'] = t[0]+ ' 00:00:00'
  37. data[fieldname + '_1'] = t[1] + ' 23:59:59'
  38. else:
  39. t = data[fieldname].split(' - ')
  40. data = data.copy()
  41. data[fieldname+'_0'] = t[0]
  42. data[fieldname+'_1'] = t[1] + ' 23:59:59'
  43. data.pop(fieldname)
  44. return data