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.

пре 11 година
пре 13 година
пре 12 година
пре 13 година
пре 14 година
пре 12 година
пре 13 година
пре 12 година
пре 13 година
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. # model __init__.py
  4. from __future__ import unicode_literals
  5. import webnotes
  6. no_value_fields = ['Section Break', 'Column Break', 'HTML', 'Table', 'Button', 'Image']
  7. default_fields = ['doctype','name','owner','creation','modified','modified_by','parent','parentfield','parenttype','idx','docstatus']
  8. def insert(doclist):
  9. if not isinstance(doclist, list):
  10. doclist = [doclist]
  11. for d in doclist:
  12. if isinstance(d, dict):
  13. d["__islocal"] = 1
  14. else:
  15. d.fields["__islocal"] = 1
  16. wrapper = webnotes.bean(doclist)
  17. wrapper.save()
  18. return wrapper
  19. @webnotes.whitelist()
  20. def delete_doc(doctype=None, name=None, doclist = None, force=0):
  21. import webnotes.model.utils
  22. return webnotes.model.utils.delete_doc(doctype, name, doclist, force)
  23. def rename(doctype, old, new, debug=False):
  24. import webnotes.model.rename_doc
  25. webnotes.model.rename_doc.rename_doc(doctype, old, new, debug)
  26. def copytables(srctype, src, srcfield, tartype, tar, tarfield, srcfields, tarfields=[]):
  27. import webnotes.model.doc
  28. if not tarfields:
  29. tarfields = srcfields
  30. l = []
  31. data = webnotes.model.doc.getchildren(src.name, srctype, srcfield)
  32. for d in data:
  33. newrow = webnotes.model.doc.addchild(tar, tarfield, tartype)
  34. newrow.idx = d.idx
  35. for i in range(len(srcfields)):
  36. newrow.fields[tarfields[i]] = d.fields[srcfields[i]]
  37. l.append(newrow)
  38. return l
  39. def db_exists(dt, dn):
  40. import webnotes
  41. return webnotes.conn.exists(dt, dn)
  42. def delete_fields(args_dict, delete=0):
  43. """
  44. Delete a field.
  45. * Deletes record from `tabDocField`
  46. * If not single doctype: Drops column from table
  47. * If single, deletes record from `tabSingles`
  48. args_dict = { dt: [field names] }
  49. """
  50. import webnotes.utils
  51. for dt in args_dict.keys():
  52. fields = args_dict[dt]
  53. if not fields: continue
  54. webnotes.conn.sql("""\
  55. DELETE FROM `tabDocField`
  56. WHERE parent=%s AND fieldname IN (%s)
  57. """ % ('%s', ", ".join(['"' + f + '"' for f in fields])), dt)
  58. # Delete the data / column only if delete is specified
  59. if not delete: continue
  60. is_single = webnotes.conn.sql("select issingle from tabDocType where name = '%s'" % dt)
  61. is_single = is_single and webnotes.utils.cint(is_single[0][0]) or 0
  62. if is_single:
  63. webnotes.conn.sql("""\
  64. DELETE FROM `tabSingles`
  65. WHERE doctype=%s AND field IN (%s)
  66. """ % ('%s', ", ".join(['"' + f + '"' for f in fields])), dt)
  67. else:
  68. existing_fields = webnotes.conn.sql("desc `tab%s`" % dt)
  69. existing_fields = existing_fields and [e[0] for e in existing_fields] or []
  70. query = "ALTER TABLE `tab%s` " % dt + \
  71. ", ".join(["DROP COLUMN `%s`" % f for f in fields if f in existing_fields])
  72. webnotes.conn.commit()
  73. webnotes.conn.sql(query)