Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

199 rader
3.1 KiB

  1. # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
  2. # License: MIT. See LICENSE
  3. # model __init__.py
  4. import frappe
  5. data_fieldtypes = (
  6. 'Currency',
  7. 'Int',
  8. 'Long Int',
  9. 'Float',
  10. 'Percent',
  11. 'Check',
  12. 'Small Text',
  13. 'Long Text',
  14. 'Code',
  15. 'Text Editor',
  16. 'Markdown Editor',
  17. 'HTML Editor',
  18. 'Date',
  19. 'Datetime',
  20. 'Time',
  21. 'Text',
  22. 'Data',
  23. 'Link',
  24. 'Dynamic Link',
  25. 'Password',
  26. 'Select',
  27. 'Rating',
  28. 'Read Only',
  29. 'Attach',
  30. 'Attach Image',
  31. 'Signature',
  32. 'Color',
  33. 'Barcode',
  34. 'Geolocation',
  35. 'Duration',
  36. 'Icon'
  37. )
  38. attachment_fieldtypes = (
  39. 'Attach',
  40. 'Attach Image',
  41. )
  42. no_value_fields = (
  43. 'Section Break',
  44. 'Column Break',
  45. 'Tab Break',
  46. 'HTML',
  47. 'Table',
  48. 'Table MultiSelect',
  49. 'Button',
  50. 'Image',
  51. 'Fold',
  52. 'Heading'
  53. )
  54. display_fieldtypes = (
  55. 'Section Break',
  56. 'Column Break',
  57. 'Tab Break',
  58. 'HTML',
  59. 'Button',
  60. 'Image',
  61. 'Fold',
  62. 'Heading')
  63. numeric_fieldtypes = (
  64. 'Currency',
  65. 'Int',
  66. 'Long Int',
  67. 'Float',
  68. 'Percent',
  69. 'Check'
  70. )
  71. data_field_options = (
  72. 'Email',
  73. 'Name',
  74. 'Phone',
  75. 'URL',
  76. 'Barcode'
  77. )
  78. default_fields = (
  79. 'doctype',
  80. 'name',
  81. 'owner',
  82. 'creation',
  83. 'modified',
  84. 'modified_by',
  85. 'docstatus',
  86. 'idx'
  87. )
  88. child_table_fields = (
  89. 'parent',
  90. 'parentfield',
  91. 'parenttype'
  92. )
  93. optional_fields = (
  94. "_user_tags",
  95. "_comments",
  96. "_assign",
  97. "_liked_by",
  98. "_seen"
  99. )
  100. table_fields = (
  101. 'Table',
  102. 'Table MultiSelect'
  103. )
  104. core_doctypes_list = (
  105. 'DocType',
  106. 'DocField',
  107. 'DocPerm',
  108. 'DocType Action',
  109. 'DocType Link',
  110. 'User',
  111. 'Role',
  112. 'Has Role',
  113. 'Page',
  114. 'Module Def',
  115. 'Print Format',
  116. 'Report',
  117. 'Customize Form',
  118. 'Customize Form Field',
  119. 'Property Setter',
  120. 'Custom Field',
  121. 'Client Script'
  122. )
  123. log_types = (
  124. 'Version',
  125. 'Error Log',
  126. 'Scheduled Job Log',
  127. 'Event Sync Log',
  128. 'Event Update Log',
  129. 'Access Log',
  130. 'View Log',
  131. 'Activity Log',
  132. 'Energy Point Log',
  133. 'Notification Log',
  134. 'Email Queue',
  135. 'DocShare',
  136. 'Document Follow',
  137. 'Console Log'
  138. )
  139. def delete_fields(args_dict, delete=0):
  140. """
  141. Delete a field.
  142. * Deletes record from `tabDocField`
  143. * If not single doctype: Drops column from table
  144. * If single, deletes record from `tabSingles`
  145. args_dict = { dt: [field names] }
  146. """
  147. import frappe.utils
  148. for dt in args_dict:
  149. fields = args_dict[dt]
  150. if not fields:
  151. continue
  152. frappe.db.delete("DocField", {
  153. "parent": dt,
  154. "fieldname": ("in", fields),
  155. })
  156. # Delete the data/column only if delete is specified
  157. if not delete:
  158. continue
  159. if frappe.db.get_value("DocType", dt, "issingle"):
  160. frappe.db.delete("Singles", {
  161. "doctype": dt,
  162. "field": ("in", fields),
  163. })
  164. else:
  165. existing_fields = frappe.db.describe(dt)
  166. existing_fields = existing_fields and [e[0] for e in existing_fields] or []
  167. fields_need_to_delete = set(fields) & set(existing_fields)
  168. if not fields_need_to_delete:
  169. continue
  170. if frappe.db.db_type == 'mariadb':
  171. # mariadb implicitly commits before DDL, make it explicit
  172. frappe.db.commit()
  173. query = "ALTER TABLE `tab%s` " % dt + \
  174. ", ".join("DROP COLUMN `%s`" % f for f in fields_need_to_delete)
  175. frappe.db.sql(query)
  176. if frappe.db.db_type == 'postgres':
  177. # commit the results to db
  178. frappe.db.commit()