You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

143 lines
2.7 KiB

  1. :mod:`utils` --- Utilities Module
  2. =================================
  3. .. module:: utils
  4. :synopsis: Utility functions
  5. Date and Time Functions
  6. -----------------------
  7. .. data:: user_format
  8. User format specified in :term:`Control Panel`
  9. Examples:
  10. * dd-mm-yyyy
  11. * mm-dd-yyyy
  12. * dd/mm/yyyy
  13. .. function:: getdate(string_date)
  14. Coverts string date (yyyy-mm-dd) to datetime.date object
  15. .. function:: add_days(string_date, days)
  16. Adds `days` to the given `string_date`
  17. .. function:: now()
  18. Returns `time.strftime('%Y-%m-%d %H:%M:%S')`
  19. .. function:: nowdate()
  20. Returns time.strftime('%Y-%m-%d')
  21. .. function:: get_first_day(date, d_years=0, d_months=0)
  22. Returns the first day of the month for the date specified by date object
  23. Also adds `d_years` and `d_months` if specified
  24. .. function:: get_last_day(dt)
  25. Returns last day of the month using:
  26. `get_first_day(dt, 0, 1) + datetime.timedelta(-1)`
  27. .. function:: formatdate(dt)
  28. Convers the given string date to :data:`user_format`
  29. Datatype Conversions
  30. --------------------
  31. .. function:: dict_to_str(args, sep='&')
  32. Converts a dictionary to URL
  33. .. function:: isNull(v)
  34. Returns true if v='' or v is `None`
  35. .. function:: has_common(l1, l2)
  36. Returns true if there are common elements in lists l1 and l2
  37. .. function:: flt(s)
  38. Convert to float (ignore commas)
  39. .. function:: cint(s)
  40. Convert to integer
  41. .. function:: cstr(s)
  42. Convert to string
  43. .. function:: str_esc_quote(s)
  44. Escape quotes
  45. .. function:: replace_newlines(s)
  46. Replace newlines by '<br>'
  47. .. function:: parse_val(v)
  48. Converts to simple datatypes from SQL query results
  49. .. function:: fmt_money(amount, fmt = '%.2f')
  50. Convert to string with commas for thousands, millions etc
  51. Defaults
  52. --------
  53. .. function:: get_defaults()
  54. Get dictionary of default values from the :term:`Control Panel`
  55. .. function:: set_default(key, val)
  56. Set / add a default value to :term:`Control Panel`
  57. File (BLOB) Functions
  58. ---------------------
  59. .. function:: get_file(fname)
  60. Returns result set of ((fieldname, blobcontent, lastmodified),) for a file of name or id `fname`
  61. Email Functions
  62. ---------------
  63. .. function:: validate_email_add(email_str)
  64. Validates the email string
  65. .. function:: sendmail(recipients, sender='', msg='', subject='[No Subject]', parts=[], cc=[], attach=[])
  66. Send an email. For more details see :func:`email_lib.sendmail`
  67. Other Functions
  68. ---------------
  69. .. function:: getCSVelement(v)
  70. Returns the CSV value of `v`, For example:
  71. * apple becomes "apple"
  72. * hi"there becomes "hi""there"
  73. .. function:: generate_hash()
  74. Generates reandom hash for session id
  75. .. function:: getTraceback()
  76. Returns the traceback of the Exception