def get_template(): import webnotes.model from webnotes.utils import getCSVelement form = webnotes.form sql = webnotes.conn.sql # get form values dt = form.getvalue('dt') overwrite = cint(form.getvalue('overwrite')) or 0 pt, pf = '', '' tmp_lbl, tmp_ml = [],[] # is table? dtd = sql("select istable, autoname from tabDocType where name='%s'" % dt) if dtd and dtd[0][0]: res1 = sql("select parent, fieldname from tabDocField where options='%s' and fieldtype='Table' and docstatus!=2" % dt) if res1: pt, pf = res1[0][0], res1[0][1] # line 1 dset = [] if pt and pf: lbl, ml = [pt], ['[Mandatory]'] line1 = '%s,%s,%s' % (getCSVelement(dt), getCSVelement(pt), getCSVelement(pf)) line2 = ',,,,,,Please fill valid %(p)s No in %(p)s column.' % {'p':getCSVelement(pt)} else: if dtd[0][1]=='Prompt' or overwrite: lbl, ml= ['Name'], ['[Mandatory][Special Characters are not allowed]'] else: lbl, ml= [], [] line1 = '%s' % getCSVelement(dt) line2 = (overwrite and ',,,,,,Please fill valid %(d)s No in %(n)s' % {'d':dt,'n': 'Name'}) or ',,' # Help on Line line1 = line1 + ',,,Please fill columns which are Mandatory., Please do not modify the structure' # fieldnames res = sql("select fieldname, fieldtype, label, reqd, hidden from tabDocField where parent='%s' and docstatus!=2" % dt) for r in res: # restrict trash_reason field, hidden and required fields if not r[1] in webnotes.model.no_value_fields and r[0] != 'trash_reason' and not r[4] and not r[3]: tmp_lbl.append(getCSVelement(r[2])) tmp_ml.append('') # restrict trash_reason field and hidden fields and add Mandatory indicator for required fields elif not r[1] in webnotes.model.no_value_fields and r[0] != 'trash_reason' and not r[4] and r[3]: lbl.append(getCSVelement(r[2])) ml.append(getCSVelement('[Mandatory]')) dset.append(line1) dset.append(line2) dset.append(','.join(ml + tmp_ml)) dset.append(','.join(lbl + tmp_lbl)) txt = '\n'.join(dset) webnotes.response['result'] = txt webnotes.response['type'] = 'csv' webnotes.response['doctype'] = dt
def runquery_csv(): from webnotes.utils import getCSVelement # run query res = runquery(from_export = 1) q = form.getvalue('query') rep_name = form.getvalue('report_name') if not form.has_key('simple_query'): tl, fl= get_sql_tables(q), get_sql_fields(q) meta = get_sql_meta(tl) # Report Name if not rep_name: rep_name = get_sql_tables(q)[0] if not rep_name: rep_name = 'DataExport' # Headings heads = [] for h in out['colnames']: heads.append(getCSVelement(h)) if form.has_key('colnames'): for h in form.getvalue('colnames').split(','): heads.append(getCSVelement(h)) # Output dataset dset = [rep_name, ''] if heads: dset.append(','.join(heads)) # Data for r in out['values']: dset.append(','.join([getCSVelement(i) for i in r])) txt = '\n'.join(dset) out['result'] = txt out['type'] = 'csv' out['doctype'] = rep_name
def make_csv_output(res, dt): import webnotes from webnotes.utils import getCSVelement txt = [] if type(res)==list: for r in res: txt.append(','.join([getCSVelement(i) for i in r])) txt = '\n'.join(txt) else: txt = 'Output was not in list format\n' + r webnotes.response['result'] = txt webnotes.response['type'] = 'csv' webnotes.response['doctype'] = dt.replace(' ','')
def get_template(): import webnotes.model from webnotes.utils import getCSVelement form = webnotes.form sql = webnotes.conn.sql # get form values dt = form.getvalue('dt') overwrite = cint(form.getvalue('overwrite')) or 0 pt, pf = '', '' tmp_lbl, tmp_ml = [], [] # is table? dtd = sql("select istable, autoname from tabDocType where name='%s'" % dt) if dtd and dtd[0][0]: res1 = sql( "select parent, fieldname from tabDocField where options='%s' and fieldtype='Table' and docstatus!=2" % dt) if res1: pt, pf = res1[0][0], res1[0][1] # line 1 dset = [] if pt and pf: lbl, ml = [pt], ['[Mandatory]'] line1 = '%s,%s,%s' % (getCSVelement(dt), getCSVelement(pt), getCSVelement(pf)) line2 = ',,,,,,Please fill valid %(p)s No in %(p)s column.' % { 'p': getCSVelement(pt) } else: if dtd[0][1] == 'Prompt' or overwrite: lbl, ml = ['Name' ], ['[Mandatory][Special Characters are not allowed]'] else: lbl, ml = [], [] line1 = '%s' % getCSVelement(dt) line2 = (overwrite and ',,,,,,Please fill valid %(d)s No in %(n)s' % { 'd': dt, 'n': 'Name' }) or ',,' # Help on Line line1 = line1 + ',,,Please fill columns which are Mandatory., Please do not modify the structure' # fieldnames res = sql( "select fieldname, fieldtype, label, reqd, hidden from tabDocField where parent='%s' and docstatus!=2" % dt) for r in res: # restrict trash_reason field, hidden and required fields if not r[1] in webnotes.model.no_value_fields and r[ 0] != 'trash_reason' and not r[4] and not r[3]: tmp_lbl.append(getCSVelement(r[2])) tmp_ml.append('') # restrict trash_reason field and hidden fields and add Mandatory indicator for required fields elif not r[1] in webnotes.model.no_value_fields and r[ 0] != 'trash_reason' and not r[4] and r[3]: lbl.append(getCSVelement(r[2])) ml.append(getCSVelement('[Mandatory]')) dset.append(line1) dset.append(line2) dset.append(','.join(ml + tmp_ml)) dset.append(','.join(lbl + tmp_lbl)) txt = '\n'.join(dset) webnotes.response['result'] = txt webnotes.response['type'] = 'csv' webnotes.response['doctype'] = dt