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.
 
 
 
 
 
 

73 lines
2.5 KiB

  1. # Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. #
  3. # MIT License (MIT)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. # and/or sell copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #
  22. from __future__ import unicode_literals
  23. import webnotes
  24. @webnotes.whitelist()
  25. def remove_attach():
  26. """remove attachment"""
  27. import webnotes.utils.file_manager
  28. fid = webnotes.form_dict.get('fid')
  29. webnotes.utils.file_manager.remove_file(fid)
  30. @webnotes.whitelist()
  31. def get_fields():
  32. """get fields"""
  33. r = {}
  34. args = {
  35. 'select':webnotes.form_dict.get('select')
  36. ,'from':webnotes.form_dict.get('from')
  37. ,'where':webnotes.form_dict.get('where')
  38. }
  39. ret = webnotes.conn.sql("select %(select)s from `%(from)s` where %(where)s limit 1" % args)
  40. if ret:
  41. fl, i = webnotes.form_dict.get('fields').split(','), 0
  42. for f in fl:
  43. r[f], i = ret[0][i], i+1
  44. webnotes.response['message']=r
  45. @webnotes.whitelist()
  46. def validate_link():
  47. """validate link when updated by user"""
  48. import webnotes
  49. import webnotes.utils
  50. value, options, fetch = webnotes.form_dict.get('value'), webnotes.form_dict.get('options'), webnotes.form_dict.get('fetch')
  51. # no options, don't validate
  52. if not options or options=='null' or options=='undefined':
  53. webnotes.response['message'] = 'Ok'
  54. return
  55. if webnotes.conn.sql("select name from `tab%s` where name=%s" % (options, '%s'), value):
  56. # get fetch values
  57. if fetch:
  58. webnotes.response['fetch_values'] = [webnotes.utils.parse_val(c) \
  59. for c in webnotes.conn.sql("select %s from `tab%s` where name=%s" \
  60. % (fetch, options, '%s'), value)[0]]
  61. webnotes.response['message'] = 'Ok'