From bcbf417a02b976c7f27c13afd23344005aa981a8 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 18 Jan 2012 17:51:13 +0530 Subject: [PATCH] Fix webnotes.conn.sql issue in custom_field.py --- py/core/doctype/custom_field/custom_field.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/py/core/doctype/custom_field/custom_field.py b/py/core/doctype/custom_field/custom_field.py index 124c22228c..d5023b58f6 100644 --- a/py/core/doctype/custom_field/custom_field.py +++ b/py/core/doctype/custom_field/custom_field.py @@ -5,6 +5,7 @@ from webnotes.utils import cint, cstr, flt, formatdate, now from webnotes.model.doc import Document from webnotes import msgprint, errprint + # ----------------------------------------------------------------------------------------- class DocType: def __init__(self, d, dl): @@ -13,9 +14,8 @@ class DocType: # Get Fields # ----------- def get_fields_label(self): - sql = webnotes.conn.sql label_name = [] - for i in sql("SELECT idx, label FROM tabDocField WHERE parent = '%s' and ifnull(hidden,0) = 0 and fieldname != '%s' order by idx" % (self.doc.dt, cstr(self.doc.fieldname))): i[1] and i[0] and label_name.append(i[1]+' - '+cstr(i[0])) + for i in webnotes.conn.sql("SELECT idx, label FROM tabDocField WHERE parent = '%s' and ifnull(hidden,0) = 0 and fieldname != '%s' order by idx" % (self.doc.dt, cstr(self.doc.fieldname))): i[1] and i[0] and label_name.append(i[1]+' - '+cstr(i[0])) return "\n".join(label_name) @@ -31,13 +31,12 @@ class DocType: # Validate Field # --------------- def validate_field(self): - sql = webnotes.conn.sql - if self.doc.__islocal == 1 and sql("select name from tabDocField where parent = %s and (label = %s or fieldname = %s)" , (self.doc.dt, self.doc.label, self.doc.fieldname)): + if self.doc.__islocal == 1 and webnotes.conn.sql("select name from tabDocField where parent = %s and (label = %s or fieldname = %s)" , (self.doc.dt, self.doc.label, self.doc.fieldname)): msgprint("%s field already exists in Document : %s" % (self.doc.label, self.doc.dt)) raise Exception if self.doc.fieldtype=='Link' and self.doc.options: - if not sql("select name from tabDocType where name=%s", self.doc.options): + if not webnotes.conn.sql("select name from tabDocType where name=%s", self.doc.options): msgprint("%s is not a valid Document" % self.doc.options) raise Exception @@ -45,9 +44,8 @@ class DocType: # Update Field # ------------- def update_field(self, df, new): - sql = webnotes.conn.sql import webnotes.model - sql("update tabDocField set idx = idx + 1, modified = %s where parent = %s and idx > %s", (now(),self.doc.dt, self.idx)) + webnotes.conn.sql("update tabDocField set idx = idx + 1, modified = %s where parent = %s and idx > %s", (now(),self.doc.dt, self.idx)) for k in self.doc.fields: if k not in webnotes.model.default_fields and k not in self.ignore_fields and not k.startswith('_'): df.fields[k] = self.doc.fields[k] @@ -61,8 +59,7 @@ class DocType: # Add Field # ---------- def add_field(self): - sql = webnotes.conn.sql - field_exists = sql("select name from tabDocField where parent = %s and (label = %s or fieldname = %s)" , (self.doc.dt, self.doc.label, self.doc.fieldname)) + field_exists = webnotes.conn.sql("select name from tabDocField where parent = %s and (label = %s or fieldname = %s)" , (self.doc.dt, self.doc.label, self.doc.fieldname)) field_exists = field_exists and field_exists[0][0] or '' self.ignore_fields = ['dt','trash_reason','insert_after','index','customfield1','length'] if field_exists: @@ -88,9 +85,8 @@ class DocType: # Trash # ------ def on_trash(self): - sql = webnotes.conn.sql - sql("update tabDocField set idx = idx - 1 where parent = %s and idx > %s" , (self.doc.dt, cint((self.doc.insert_after).split(' - ')[1]))) - sql("delete from tabDocField where parent = %s and fieldname = %s", (self.doc.dt, self.doc.fieldname)) + webnotes.conn.sql("update tabDocField set idx = idx - 1 where parent = %s and idx > %s" , (self.doc.dt, cint((self.doc.insert_after).split(' - ')[1]))) + webnotes.conn.sql("delete from tabDocField where parent = %s and fieldname = %s", (self.doc.dt, self.doc.fieldname)) # Restore