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.

user_properties.py 1.5 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from __future__ import unicode_literals
  2. import webnotes
  3. @webnotes.whitelist(allow_roles=["System Manager", "Administrator"])
  4. def get_users_and_links():
  5. links, all_fields = [], []
  6. for l in webnotes.conn.sql("""select fieldname, options
  7. from tabDocField where fieldtype='Link'
  8. and parent not in ('[Select]', 'DocType', 'Module Def')
  9. """) + webnotes.conn.sql("""select fieldname, options
  10. from `tabCustom Field` where fieldtype='Link'"""):
  11. if not l[0] in all_fields:
  12. links.append([l[0], l[1]])
  13. all_fields.append(l[0])
  14. links.sort()
  15. return {
  16. "users": [d[0] for d in webnotes.conn.sql("""select name from tabProfile where
  17. ifnull(enabled,0)=1 and
  18. name not in ("Administrator", "Guest")""")],
  19. "link_fields": links
  20. }
  21. @webnotes.whitelist(allow_roles=["System Manager", "Administrator"])
  22. def get_properties(user=None, key=None):
  23. return webnotes.conn.sql("""select name, parent, defkey, defvalue
  24. from tabDefaultValue
  25. where parent!='Control Panel'
  26. and substr(defkey,0,1)!='_'
  27. %s%s order by parent, defkey""" % (\
  28. user and (" and parent='%s'" % user) or "",
  29. key and (" and defkey='%s'" % key) or ""), as_dict=True)
  30. @webnotes.whitelist(allow_roles=["System Manager", "Administrator"])
  31. def remove(user, name):
  32. webnotes.conn.sql("""delete from tabDefaultValue where name=%s""", name)
  33. webnotes.clear_cache(user=user)
  34. @webnotes.whitelist(allow_roles=["System Manager", "Administrator"])
  35. def add(parent, defkey, defvalue):
  36. webnotes.conn.add_default(defkey, defvalue, parent)