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.
 
 
 
 
 
 

86 lines
2.3 KiB

  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. import webnotes, json
  5. from webnotes import _
  6. @webnotes.whitelist()
  7. def remove_attach():
  8. """remove attachment"""
  9. import webnotes.utils.file_manager
  10. fid = webnotes.form_dict.get('fid')
  11. webnotes.utils.file_manager.remove_file(fid)
  12. @webnotes.whitelist()
  13. def get_fields():
  14. """get fields"""
  15. r = {}
  16. args = {
  17. 'select':webnotes.form_dict.get('select')
  18. ,'from':webnotes.form_dict.get('from')
  19. ,'where':webnotes.form_dict.get('where')
  20. }
  21. ret = webnotes.conn.sql("select %(select)s from `%(from)s` where %(where)s limit 1" % args)
  22. if ret:
  23. fl, i = webnotes.form_dict.get('fields').split(','), 0
  24. for f in fl:
  25. r[f], i = ret[0][i], i+1
  26. webnotes.response['message']=r
  27. @webnotes.whitelist()
  28. def validate_link():
  29. """validate link when updated by user"""
  30. import webnotes
  31. import webnotes.utils
  32. value, options, fetch = webnotes.form_dict.get('value'), webnotes.form_dict.get('options'), webnotes.form_dict.get('fetch')
  33. # no options, don't validate
  34. if not options or options=='null' or options=='undefined':
  35. webnotes.response['message'] = 'Ok'
  36. return
  37. if webnotes.conn.sql("select name from `tab%s` where name=%s" % (options, '%s'), value):
  38. # get fetch values
  39. if fetch:
  40. webnotes.response['fetch_values'] = [webnotes.utils.parse_val(c) \
  41. for c in webnotes.conn.sql("select %s from `tab%s` where name=%s" \
  42. % (fetch, options, '%s'), value)[0]]
  43. webnotes.response['message'] = 'Ok'
  44. @webnotes.whitelist()
  45. def add_comment(doclist):
  46. """allow any logged user to post a comment"""
  47. doclist = json.loads(doclist)
  48. doclist[0]["__islocal"] = 1
  49. doclistobj = webnotes.bean(doclist)
  50. doclistobj.ignore_permissions = True
  51. doclistobj.save()
  52. return [d.fields for d in doclist]
  53. return save(doclist)
  54. @webnotes.whitelist()
  55. def get_next(doctype, name, prev):
  56. import webnotes.widgets.reportview
  57. prev = int(prev)
  58. field = "`tab%s`.name" % doctype
  59. res = webnotes.widgets.reportview.execute(doctype,
  60. fields = [field],
  61. filters = [[doctype, "name", "<" if prev else ">", name]],
  62. order_by = field + " " + ("desc" if prev else "asc"),
  63. limit_start=0, limit_page_length=1, as_list=True)
  64. if not res:
  65. webnotes.msgprint(_("No further records"))
  66. return None
  67. else:
  68. return res[0][0]