From abc4996a20f01d91d2fa85b0b6e02f84bc00b412 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Sat, 19 Nov 2016 13:02:49 +0530 Subject: [PATCH] Added docstring for get_single_value, get_singles_dict methods (#2292) --- frappe/database.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/frappe/database.py b/frappe/database.py index 9afc204a22..8861a6b6f8 100644 --- a/frappe/database.py +++ b/frappe/database.py @@ -509,7 +509,16 @@ class Database: return r and [[i[1] for i in r]] or [] def get_singles_dict(self, doctype): - """Get Single DocType as dict.""" + """Get Single DocType as dict. + + :param doctype: DocType of the single object whose value is requested + + Example: + + # Get coulmn and value of the single doctype Accounts Settings + account_settings = frappe.db.get_singles_dict("Accounts Settings") + """ + return frappe._dict(self.sql("""select field, value from tabSingles where doctype=%s""", doctype)) @@ -520,7 +529,17 @@ class Database: return frappe.get_list(*args, **kwargs) def get_single_value(self, doctype, fieldname, cache=False): - """Get property of Single DocType. Cache locally by default""" + """Get property of Single DocType. Cache locally by default + + :param doctype: DocType of the single object whose value is requested + :param fieldname: `fieldname` of the property whose value is requested + + Example: + + # Get the default value of the company from the Global Defaults doctype. + company = frappe.db.get_single_value('Global Defaults', 'default_company') + """ + value = self.value_cache.setdefault(doctype, {}).get(fieldname) if value: return value