[fix] list_settings

This commit is contained in:
Rushabh Mehta 2016-06-01 06:41:34 +05:30
parent fe6de7981d
commit fd07b73a67

View file

@ -5,19 +5,28 @@ def get_list_settings(doctype, for_update=False):
'{0}::{1}'.format(doctype, frappe.session.user))
if list_settings is None:
list_settings = frappe.db.sql('''select * from __ListSettings
where user=%s and doctype=%s''', (frappe.session.user, doctype), as_dict=True)
list_settings = list_settings and list_settings[0] or '{}'
list_settings = frappe.db.sql('''select data from __ListSettings
where user=%s and doctype=%s''', (frappe.session.user, doctype))
list_settings = list_settings and list_settings[0][0] or '{}'
if not for_update:
update_list_settings(doctype, list_settings)
update_list_settings(doctype, list_settings, True)
return list_settings
def update_list_settings(doctype, list_settings):
def update_list_settings(doctype, list_settings, for_update=False):
'''update list settings in cache'''
current = json.loads(get_list_settings(doctype, for_update = True))
current.update(list_settings)
if for_update:
current = json.loads(list_settings)
else:
current = json.loads(get_list_settings(doctype, for_update = True))
if isinstance(current, basestring):
# corrupt due to old code, remove this in a future release
current = {}
current.update(list_settings)
frappe.cache().hset('_list_settings', '{0}::{1}'.format(doctype, frappe.session.user),
json.dumps(current))