From bd95fda321cce6f6073db296aebd5de11b978adc Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 11 Aug 2011 17:42:19 +0530 Subject: [PATCH 1/2] profile, utf fix --- cgi-bin/webnotes/profile.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cgi-bin/webnotes/profile.py b/cgi-bin/webnotes/profile.py index dd135ee1ba..3fe1eec59d 100644 --- a/cgi-bin/webnotes/profile.py +++ b/cgi-bin/webnotes/profile.py @@ -150,10 +150,16 @@ class Profile: # get profile profile = webnotes.conn.sql("SELECT name, email, first_name, last_name FROM tabProfile WHERE name=%s OR email=%s",(self.name, self.name)) - + + profile_cols = [desc[0] for desc in webnotes.conn.sql("DESCRIBE tabProfile")] + if not profile: raise Exception, "Profile %s not found" % self.name - + elif 'registered' in profile_cols: + if not webnotes.conn.sql("SELECT registered FROM tabProfile WHERE name=%s", self.name)[0][0]: + # if an unregistered user tries to reset password + raise Exception, "You cannot reset your password as you have not completed registration. You need to complete registration using the link provided in the email." + # update tab Profile webnotes.conn.sql("UPDATE tabProfile SET password=password(%s) WHERE name=%s", (pwd, profile[0][0])) @@ -170,12 +176,14 @@ class Profile: Update the user's `Recent` list with the given `dt` and `dn` """ conn = webnotes.conn + from webnotes.utils import cstr # get list of child tables, so we know what not to add in the recent list child_tables = [t[0] for t in conn.sql('select name from tabDocType where istable = 1')] + if not (dt in ['Print Format', 'Start Page', 'Event', 'ToDo Item', 'Search Criteria']) and not webnotes.is_testing and not (dt in child_tables): - r = webnotes.conn.sql("select recent_documents from tabProfile where name=%s", self.name)[0][0] or '' - new_str = dt+'~~~'+dn + '\n' + r = cstr(webnotes.conn.sql("select recent_documents from tabProfile where name=%s", self.name)[0][0] or '') + new_str = cstr(dt)+'~~~'+cstr(dn) + '\n' if new_str in r: r = r.replace(new_str, '') From 9c3a02677f437b27303305eefe62effda2a5e87a Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 16 Aug 2011 09:56:00 +0530 Subject: [PATCH 2/2] encoding friendly csv output --- .../utils/{ => jslib}/jsdependency.py | 0 cgi-bin/webnotes/utils/{ => jslib}/jsmin.py | 0 .../webnotes/utils/{ => jslib}/jsnamespace.py | 0 .../webnotes/utils/{ => jslib}/jstimestamp.py | 0 cgi-bin/webnotes/widgets/form.py | 23 +++++++------- cgi-bin/webnotes/widgets/query_builder.py | 31 +++++++++---------- 6 files changed, 25 insertions(+), 29 deletions(-) rename cgi-bin/webnotes/utils/{ => jslib}/jsdependency.py (100%) rename cgi-bin/webnotes/utils/{ => jslib}/jsmin.py (100%) rename cgi-bin/webnotes/utils/{ => jslib}/jsnamespace.py (100%) rename cgi-bin/webnotes/utils/{ => jslib}/jstimestamp.py (100%) diff --git a/cgi-bin/webnotes/utils/jsdependency.py b/cgi-bin/webnotes/utils/jslib/jsdependency.py similarity index 100% rename from cgi-bin/webnotes/utils/jsdependency.py rename to cgi-bin/webnotes/utils/jslib/jsdependency.py diff --git a/cgi-bin/webnotes/utils/jsmin.py b/cgi-bin/webnotes/utils/jslib/jsmin.py similarity index 100% rename from cgi-bin/webnotes/utils/jsmin.py rename to cgi-bin/webnotes/utils/jslib/jsmin.py diff --git a/cgi-bin/webnotes/utils/jsnamespace.py b/cgi-bin/webnotes/utils/jslib/jsnamespace.py similarity index 100% rename from cgi-bin/webnotes/utils/jsnamespace.py rename to cgi-bin/webnotes/utils/jslib/jsnamespace.py diff --git a/cgi-bin/webnotes/utils/jstimestamp.py b/cgi-bin/webnotes/utils/jslib/jstimestamp.py similarity index 100% rename from cgi-bin/webnotes/utils/jstimestamp.py rename to cgi-bin/webnotes/utils/jslib/jstimestamp.py diff --git a/cgi-bin/webnotes/widgets/form.py b/cgi-bin/webnotes/widgets/form.py index 7f5a325770..6eddede16f 100644 --- a/cgi-bin/webnotes/widgets/form.py +++ b/cgi-bin/webnotes/widgets/form.py @@ -214,19 +214,18 @@ def runserverobj(): 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 + from cStringIO import StringIO + import csv + + f = StringIO() + writer = csv.writer(f) + for r in res: + writer.writerow(r) + + f.seek(0) + + webnotes.response['result'] = f.read() webnotes.response['type'] = 'csv' webnotes.response['doctype'] = dt.replace(' ','') diff --git a/cgi-bin/webnotes/widgets/query_builder.py b/cgi-bin/webnotes/widgets/query_builder.py index cf272434e3..72e320cd70 100644 --- a/cgi-bin/webnotes/widgets/query_builder.py +++ b/cgi-bin/webnotes/widgets/query_builder.py @@ -294,7 +294,7 @@ def runquery(q='', ret=0, from_export=0): # ==================================================================== def runquery_csv(): - from webnotes.utils import getCSVelement + global out # run query res = runquery(from_export = 1) @@ -312,22 +312,19 @@ def runquery_csv(): # 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 + rows = [[rep_name], out['colnames']] + out['values'] + + from cStringIO import StringIO + import csv + + f = StringIO() + writer = csv.writer(f) + for r in rows: + writer.writerow(r) + + f.seek(0) + out['result'] = f.read() out['type'] = 'csv' out['doctype'] = rep_name +