Merge branch 'shf_rename' of github.com:webnotes/wnframework into shf_rename

This commit is contained in:
Rushabh Mehta 2012-04-15 16:05:08 +05:30
commit 5450f696de
2 changed files with 11 additions and 5 deletions

View file

@ -295,7 +295,7 @@ class DbManager:
"""
Just returns the output of Desc tables.
"""
return list(self.conn.sql("DESC %s"%table))
return list(self.conn.sql("DESC `%s`"%table))
def get_tables_list(self,target=None):

View file

@ -38,6 +38,11 @@ def get(arg=None):
fields = json.loads(data['fields'])
tables = ['`tab' + data['doctype'] + '`']
# select fields if they exist in table
columns = [".".join([tables[0], col]) for col in get_table_columns(data['doctype'])]
fields = [f for f in fields if f in columns]
docstatus = json.loads(data['docstatus'])
if docstatus:
conditions = [tables[0] + '.docstatus in (' + ','.join(docstatus) + ')']
@ -98,10 +103,11 @@ def get_stats():
import json
tags = json.loads(webnotes.form_dict.get('stats'))
doctype = webnotes.form_dict['doctype']
stats = {}
columns = get_table_columns(doctype)
for tag in tags:
if not tag in columns: continue
tagcount = webnotes.conn.sql("""select %(tag)s, count(*)
from `tab%(doctype)s`
where ifnull(%(tag)s, '')!=''
@ -132,7 +138,7 @@ def scrub_user_tags(tagcount):
rlist.append([tag, rdict[tag]])
return rlist
def get_table_columns(table):
res = webnotes.conn.sql("DESC `tab%s`" % table, as_dict=1)
if res: return [r['Field'] for r in res]