Skip to content

Commit

Permalink
added queriable get_doc to webclient API
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehta committed Jan 30, 2013
1 parent 20e7429 commit 067411d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion public/js/legacy/widgets/form/fields.js
Expand Up @@ -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);
Expand Down
8 changes: 1 addition & 7 deletions public/js/legacy/widgets/form/form_fields.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion webnotes/client.py
Expand Up @@ -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()
Expand Down
26 changes: 18 additions & 8 deletions webnotes/utils/webclient.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

0 comments on commit 067411d

Please sign in to comment.