From 067411da16c6764ade1a7c5bdb6abd35f39f9409 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 30 Jan 2013 11:06:04 +0530 Subject: [PATCH] added queriable get_doc to webclient API --- public/js/legacy/widgets/form/fields.js | 2 +- public/js/legacy/widgets/form/form_fields.js | 8 +----- webnotes/client.py | 6 ++++- webnotes/utils/webclient.py | 26 ++++++++++++++------ 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/public/js/legacy/widgets/form/fields.js b/public/js/legacy/widgets/form/fields.js index bbf623b4a3c..fd4f824eb4b 100644 --- a/public/js/legacy/widgets/form/fields.js +++ b/public/js/legacy/widgets/form/fields.js @@ -942,7 +942,7 @@ TextField.prototype.make_input = function() { $(this.input).css({height: "160px"}); } this.input.set_input = function(v) { - me.input.value = v; + me.input.value = (v==null ? "" : v); } this.input.onchange = function() { me.set(me.input.value); diff --git a/public/js/legacy/widgets/form/form_fields.js b/public/js/legacy/widgets/form/form_fields.js index decaefe8e27..a68627fe01b 100644 --- a/public/js/legacy/widgets/form/form_fields.js +++ b/public/js/legacy/widgets/form/form_fields.js @@ -237,8 +237,6 @@ _f.TableField.prototype.refresh = function() { _f.TableField.prototype.set = function(v) { }; // nothing _f.TableField.prototype.set_input = function(v) { }; // nothing -// ============================================================== - _f.CodeField = function() { }; _f.CodeField.prototype = new Field(); @@ -291,15 +289,11 @@ _f.CodeField.prototype.make_input = function() { this.input.set_input = function(v) { if(me.editor) { - me.editor.setContent(v || ""); + me.editor.setContent(v==null ? "" : v); } else { $(me.input).val(v); } } - // this.input.onchange = function() { - // me.set(me.editor.getContent()); - // me.run_trigger(); - // } this.get_value = function() { return me.editor && me.editor.getContent(); // tinyMCE } diff --git a/webnotes/client.py b/webnotes/client.py index 5d4f739cbc1..47654a37835 100644 --- a/webnotes/client.py +++ b/webnotes/client.py @@ -25,7 +25,11 @@ import json @webnotes.whitelist() -def get(doctype, name): +def get(doctype, name=None, filters=None): + if filters and not name: + name = webnotes.conn.get_value(doctype, json.loads(filters)) + if not name: + raise Exception, "No document found for given filters" return [d.fields for d in webnotes.model_wrapper(doctype, name).doclist] @webnotes.whitelist() diff --git a/webnotes/utils/webclient.py b/webnotes/utils/webclient.py index 85c02f32de6..235cbb7f143 100644 --- a/webnotes/utils/webclient.py +++ b/webnotes/utils/webclient.py @@ -58,12 +58,16 @@ def delete(doctype, name): "name": name }) -def get_doc(doctype, name): - ret = get_request({ +def get_doc(doctype, name=None, filters=None): + params = { "cmd": "webnotes.client.get", "doctype": doctype, - "name": name - }) + } + if name: + params["name"] = name + if filters: + params["filters"] = json.dumps(filters) + ret = get_request(params) return ret def get_request(params): @@ -100,20 +104,26 @@ def test_all(self): "customer_type": "Company", "customer_group": "Standard Group", "territory": "Default", + "customer_details": "some unique info", "company": "Alpha" }]) self.assertTrue(response.json["message"][0]["name"]=="Import Test Customer") # get response = get_doc("Customer", "Import Test Customer") + self.check_get(response) + + response = get_doc("Customer", filters={"customer_details":"some unique info"}) + self.check_get(response) + # delete + self.assertTrue(delete("Customer", "Import Test Customer").json["message"]=="okay") + + def check_get(self, response): doclist = response.json["message"] self.assertTrue(len(doclist)==1) self.assertTrue(doclist[0]["doctype"]=="Customer") self.assertTrue(doclist[0]["customer_group"]=="Standard Group") - - # delete - self.assertTrue(delete("Customer", "Import Test Customer").json["message"]=="okay") - + if __name__=="__main__": unittest.main() \ No newline at end of file