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.
 
 
 
 
 
 

50 line
1.7 KiB

  1. # metadata
  2. import webnotes
  3. #=================================================================================
  4. def get_dt_values(doctype, fields, as_dict = 0):
  5. return webnotes.conn.sql('SELECT %s FROM tabDocType WHERE name="%s"' % (fields, doctype), as_dict = as_dict)
  6. def set_dt_value(doctype, field, value):
  7. return webnotes.conn.set_value('DocType', doctype, field, value)
  8. def is_single(doctype):
  9. try:
  10. return get_dt_values(doctype, 'issingle')[0][0]
  11. except IndexError, e:
  12. raise Exception, 'Cannot determine whether %s is single' % doctype
  13. #=================================================================================
  14. def get_parent_dt(dt):
  15. parent_dt = webnotes.conn.sql("""select parent from tabDocField
  16. where fieldtype="Table" and options="%s" and (parent not like "old_parent:%%")
  17. limit 1""" % dt)
  18. return parent_dt and parent_dt[0][0] or ''
  19. #=================================================================================
  20. def set_fieldname(field_id, fieldname):
  21. webnotes.conn.set_value('DocField', field_id, 'fieldname', fieldname)
  22. #=================================================================================
  23. def get_link_fields(doctype):
  24. """
  25. Returns list of link fields for a doctype in tuple (fieldname, options, label)
  26. """
  27. return webnotes.conn.sql("""
  28. SELECT fieldname, options, label
  29. FROM tabDocField
  30. WHERE parent='%s'
  31. and (fieldtype='Link' or (fieldtype='Select' and `options` like 'link:%%'))
  32. and fieldname!='owner'""" % (doctype))
  33. #=================================================================================
  34. def get_table_fields(doctype):
  35. return webnotes.conn.sql("select options, fieldname from tabDocField where parent='%s' and fieldtype='Table'" % doctype)