@@ -18,7 +18,7 @@ def get_notifications(): | |||||
open_count_module = {} | open_count_module = {} | ||||
notification_count = dict(webnotes.conn.sql("""select for_doctype, open_count | notification_count = dict(webnotes.conn.sql("""select for_doctype, open_count | ||||
from `tabNotification Count` where owner=%s""", webnotes.session.user)) | |||||
from `tabNotification Count` where owner=%s""", (webnotes.session.user,))) | |||||
for d in config.for_doctype: | for d in config.for_doctype: | ||||
if d in can_read: | if d in can_read: | ||||
@@ -51,7 +51,7 @@ def get_notifications(): | |||||
def delete_notification_count_for(doctype): | def delete_notification_count_for(doctype): | ||||
if webnotes.flags.in_import: return | if webnotes.flags.in_import: return | ||||
webnotes.conn.sql("""delete from `tabNotification Count` where for_doctype = %s""", doctype) | |||||
webnotes.conn.sql("""delete from `tabNotification Count` where for_doctype = %s""", (doctype,)) | |||||
def delete_event_notification_count(): | def delete_event_notification_count(): | ||||
delete_notification_count_for("Event") | delete_notification_count_for("Event") | ||||
@@ -220,17 +220,17 @@ Thank you,<br> | |||||
webnotes.local.login_manager.logout(user=self.doc.name) | webnotes.local.login_manager.logout(user=self.doc.name) | ||||
# delete their password | # delete their password | ||||
webnotes.conn.sql("""delete from __Auth where user=%s""", self.doc.name) | |||||
webnotes.conn.sql("""delete from __Auth where user=%s""", (self.doc.name,)) | |||||
# delete todos | # delete todos | ||||
webnotes.conn.sql("""delete from `tabToDo` where owner=%s""", self.doc.name) | |||||
webnotes.conn.sql("""delete from `tabToDo` where owner=%s""", (self.doc.name,)) | |||||
webnotes.conn.sql("""update tabToDo set assigned_by=null where assigned_by=%s""", | webnotes.conn.sql("""update tabToDo set assigned_by=null where assigned_by=%s""", | ||||
self.doc.name) | |||||
(self.doc.name,)) | |||||
# delete events | # delete events | ||||
webnotes.conn.sql("""delete from `tabEvent` where owner=%s | webnotes.conn.sql("""delete from `tabEvent` where owner=%s | ||||
and event_type='Private'""", self.doc.name) | |||||
webnotes.conn.sql("""delete from `tabEvent User` where person=%s""", self.doc.name) | |||||
and event_type='Private'""", (self.doc.name,)) | |||||
webnotes.conn.sql("""delete from `tabEvent User` where person=%s""", (self.doc.name,)) | |||||
# delete messages | # delete messages | ||||
webnotes.conn.sql("""delete from `tabComment` where comment_doctype='Message' | webnotes.conn.sql("""delete from `tabComment` where comment_doctype='Message' | ||||
@@ -315,7 +315,7 @@ def get_perm_info(arg=None): | |||||
return webnotes.conn.sql("""select parent, permlevel, `read`, `write`, submit, | return webnotes.conn.sql("""select parent, permlevel, `read`, `write`, submit, | ||||
cancel, amend from tabDocPerm where role=%s | cancel, amend from tabDocPerm where role=%s | ||||
and docstatus<2 order by parent, permlevel""", | and docstatus<2 order by parent, permlevel""", | ||||
webnotes.form_dict['role'], as_dict=1) | |||||
(webnotes.form_dict['role'],), as_dict=1) | |||||
@webnotes.whitelist(allow_guest=True) | @webnotes.whitelist(allow_guest=True) | ||||
def update_password(new_password, key=None, old_password=None): | def update_password(new_password, key=None, old_password=None): | ||||
@@ -368,7 +368,7 @@ def reset_password(user): | |||||
if user in ["demo@erpnext.com", "Administrator"]: | if user in ["demo@erpnext.com", "Administrator"]: | ||||
return "Not allowed" | return "Not allowed" | ||||
if webnotes.conn.sql("""select name from tabProfile where name=%s""", user): | |||||
if webnotes.conn.sql("""select name from tabProfile where name=%s""", (user,)): | |||||
# Hack! | # Hack! | ||||
webnotes.session["user"] = "Administrator" | webnotes.session["user"] = "Administrator" | ||||
profile = webnotes.bean("Profile", user) | profile = webnotes.bean("Profile", user) | ||||
@@ -20,7 +20,7 @@ class TestProfile(unittest.TestCase): | |||||
delete_doc("Profile", "_test@example.com") | delete_doc("Profile", "_test@example.com") | ||||
self.assertTrue(not webnotes.conn.sql("""select * from `tabToDo` where owner=%s""", | self.assertTrue(not webnotes.conn.sql("""select * from `tabToDo` where owner=%s""", | ||||
"_test@example.com")) | |||||
("_test@example.com",))) | |||||
from webnotes.core.doctype.role.test_role import test_records as role_records | from webnotes.core.doctype.role.test_role import test_records as role_records | ||||
webnotes.bean(copy=role_records[1]).insert() | webnotes.bean(copy=role_records[1]).insert() | ||||
@@ -41,4 +41,4 @@ def get_unread_messages(): | |||||
WHERE comment_doctype IN ('My Company', 'Message') | WHERE comment_doctype IN ('My Company', 'Message') | ||||
AND comment_docname = %s | AND comment_docname = %s | ||||
AND ifnull(docstatus,0)=0 | AND ifnull(docstatus,0)=0 | ||||
""", webnotes.user.name)[0][0] | |||||
""", (webnotes.user.name,))[0][0] |
@@ -469,7 +469,7 @@ class Database: | |||||
if dt==dn: | if dt==dn: | ||||
return True # single always exists (!) | return True # single always exists (!) | ||||
try: | try: | ||||
return self.sql('select name from `tab%s` where name=%s' % (dt, '%s'), dn) | |||||
return self.sql('select name from `tab%s` where name=%s' % (dt, '%s'), (dn,)) | |||||
except: | except: | ||||
return None | return None | ||||
elif isinstance(dt, dict) and dt.get('doctype'): | elif isinstance(dt, dict) and dt.get('doctype'): | ||||
@@ -34,7 +34,7 @@ def get_restrictions(user=None): | |||||
def build_restrictions(user): | def build_restrictions(user): | ||||
out = {} | out = {} | ||||
for key, value in webnotes.conn.sql("""select defkey, defvalue | for key, value in webnotes.conn.sql("""select defkey, defvalue | ||||
from tabDefaultValue where parent=%s and parenttype='Restriction'""", user): | |||||
from tabDefaultValue where parent=%s and parenttype='Restriction'""", (user,)): | |||||
out.setdefault(key, []) | out.setdefault(key, []) | ||||
out[key].append(value) | out[key].append(value) | ||||
return out | return out | ||||
@@ -133,7 +133,7 @@ def get_defaults_for(parent="Control Panel"): | |||||
defaults = webnotes.cache().get_value("__defaults:" + parent) | defaults = webnotes.cache().get_value("__defaults:" + parent) | ||||
if not defaults: | if not defaults: | ||||
res = webnotes.conn.sql("""select defkey, defvalue from `tabDefaultValue` | res = webnotes.conn.sql("""select defkey, defvalue from `tabDefaultValue` | ||||
where parent = %s order by creation""", parent, as_dict=1) | |||||
where parent = %s order by creation""", (parent,), as_dict=1) | |||||
defaults = webnotes._dict({}) | defaults = webnotes._dict({}) | ||||
for d in res: | for d in res: | ||||
@@ -100,7 +100,7 @@ class DbTable: | |||||
try: | try: | ||||
custom_fl = webnotes.conn.sql("""\ | custom_fl = webnotes.conn.sql("""\ | ||||
SELECT * FROM `tabCustom Field` | SELECT * FROM `tabCustom Field` | ||||
WHERE dt = %s AND docstatus < 2""", self.doctype, as_dict=1) | |||||
WHERE dt = %s AND docstatus < 2""", (self.doctype,), as_dict=1) | |||||
if custom_fl: fl += custom_fl | if custom_fl: fl += custom_fl | ||||
except Exception, e: | except Exception, e: | ||||
if e.args[0]!=1146: # ignore no custom field | if e.args[0]!=1146: # ignore no custom field | ||||
@@ -393,7 +393,7 @@ def updatedb(dt): | |||||
* updates columns | * updates columns | ||||
* updates indices | * updates indices | ||||
""" | """ | ||||
res = webnotes.conn.sql("select ifnull(issingle, 0) from tabDocType where name=%s", dt) | |||||
res = webnotes.conn.sql("select ifnull(issingle, 0) from tabDocType where name=%s", (dt,)) | |||||
if not res: | if not res: | ||||
raise Exception, 'Wrong doctype "%s" in updatedb' % dt | raise Exception, 'Wrong doctype "%s" in updatedb' % dt | ||||
@@ -36,10 +36,10 @@ def delete_doc(doctype=None, name=None, doclist = None, force=0, ignore_doctypes | |||||
try: | try: | ||||
tablefields = webnotes.model.meta.get_table_fields(doctype) | tablefields = webnotes.model.meta.get_table_fields(doctype) | ||||
webnotes.conn.sql("delete from `tab%s` where name=%s" % (doctype, "%s"), name) | |||||
webnotes.conn.sql("delete from `tab%s` where name=%s" % (doctype, "%s"), (name,)) | |||||
for t in tablefields: | for t in tablefields: | ||||
if t[0] not in ignore_doctypes: | if t[0] not in ignore_doctypes: | ||||
webnotes.conn.sql("delete from `tab%s` where parent = %s" % (t[0], '%s'), name) | |||||
webnotes.conn.sql("delete from `tab%s` where parent = %s" % (t[0], '%s'), (name,)) | |||||
except Exception, e: | except Exception, e: | ||||
if e.args[0]==1451: | if e.args[0]==1451: | ||||
webnotes.msgprint("Cannot delete %s '%s' as it is referenced in another record. You must delete the referred record first" % (doctype, name)) | webnotes.msgprint("Cannot delete %s '%s' as it is referenced in another record. You must delete the referred record first" % (doctype, name)) | ||||
@@ -375,7 +375,7 @@ class Document: | |||||
if '\n' in dt: | if '\n' in dt: | ||||
dt = dt.split('\n')[0] | dt = dt.split('\n')[0] | ||||
tmp = webnotes.conn.sql("""SELECT name FROM `tab%s` | tmp = webnotes.conn.sql("""SELECT name FROM `tab%s` | ||||
WHERE name = %s""" % (dt, '%s'), dn) | |||||
WHERE name = %s""" % (dt, '%s'), (dn,)) | |||||
return tmp and tmp[0][0] or ''# match case | return tmp and tmp[0][0] or ''# match case | ||||
def _update_values(self, issingle, link_list, ignore_fields=0, keep_timestamps=False): | def _update_values(self, issingle, link_list, ignore_fields=0, keep_timestamps=False): | ||||
@@ -441,7 +441,7 @@ class Document: | |||||
"""update parent type and parent field, if not explicitly specified""" | """update parent type and parent field, if not explicitly specified""" | ||||
tmp = webnotes.conn.sql("""select parent, fieldname from tabDocField | tmp = webnotes.conn.sql("""select parent, fieldname from tabDocField | ||||
where fieldtype='Table' and options=%s""", self.doctype) | |||||
where fieldtype='Table' and options=%s""", (self.doctype,)) | |||||
if len(tmp)==0: | if len(tmp)==0: | ||||
raise Exception, 'Incomplete parent info in child table (%s, %s)' \ | raise Exception, 'Incomplete parent info in child table (%s, %s)' \ | ||||
@@ -587,15 +587,15 @@ def make_autoname(key, doctype=''): | |||||
def getseries(key, digits, doctype=''): | def getseries(key, digits, doctype=''): | ||||
# series created ? | # series created ? | ||||
current = webnotes.conn.sql("select `current` from `tabSeries` where name=%s for update", key) | |||||
current = webnotes.conn.sql("select `current` from `tabSeries` where name=%s for update", (key,)) | |||||
if current and current[0][0] is not None: | if current and current[0][0] is not None: | ||||
current = current[0][0] | current = current[0][0] | ||||
# yes, update it | # yes, update it | ||||
webnotes.conn.sql("update tabSeries set current = current+1 where name=%s", key) | |||||
webnotes.conn.sql("update tabSeries set current = current+1 where name=%s", (key,)) | |||||
current = cint(current) + 1 | current = cint(current) + 1 | ||||
else: | else: | ||||
# no, create it | # no, create it | ||||
webnotes.conn.sql("insert into tabSeries (name, current) values (%s, 1)", key) | |||||
webnotes.conn.sql("insert into tabSeries (name, current) values (%s, 1)", (key,)) | |||||
current = 1 | current = 1 | ||||
return ('%0'+str(digits)+'d') % current | return ('%0'+str(digits)+'d') % current | ||||
@@ -633,7 +633,7 @@ def check_page_perm(doc): | |||||
if doc.publish: | if doc.publish: | ||||
return | return | ||||
if not webnotes.conn.sql("select name from `tabPage Role` where parent=%s and role='Guest'", doc.name): | |||||
if not webnotes.conn.sql("select name from `tabPage Role` where parent=%s and role='Guest'", (doc.name,)): | |||||
webnotes.response['403'] = 1 | webnotes.response['403'] = 1 | ||||
raise webnotes.PermissionError, '[WNF] No read permission for %s %s' % ('Page', doc.name) | raise webnotes.PermissionError, '[WNF] No read permission for %s %s' % ('Page', doc.name) | ||||
@@ -669,7 +669,7 @@ def get(dt, dn='', with_children = 1, from_controller = 0): | |||||
def getsingle(doctype): | def getsingle(doctype): | ||||
"""get single doc as dict""" | """get single doc as dict""" | ||||
dataset = webnotes.conn.sql("select field, value from tabSingles where doctype=%s", doctype) | |||||
dataset = webnotes.conn.sql("select field, value from tabSingles where doctype=%s", (doctype,)) | |||||
return dict(dataset) | return dict(dataset) | ||||
def copy_common_fields(from_doc, to_doc): | def copy_common_fields(from_doc, to_doc): | ||||
@@ -685,7 +685,7 @@ def copy_common_fields(from_doc, to_doc): | |||||
def validate_name(doctype, name, case=None, merge=False): | def validate_name(doctype, name, case=None, merge=False): | ||||
if not merge: | if not merge: | ||||
if webnotes.conn.sql('select name from `tab%s` where name=%s' % (doctype,'%s'), name): | |||||
if webnotes.conn.sql('select name from `tab%s` where name=%s' % (doctype,'%s'), (name,)): | |||||
raise NameError, 'Name %s already exists' % name | raise NameError, 'Name %s already exists' % name | ||||
# no name | # no name | ||||
@@ -132,7 +132,7 @@ def sort_fields(doclist): | |||||
def apply_property_setters(doctype, doclist): | def apply_property_setters(doctype, doclist): | ||||
for ps in webnotes.conn.sql("""select * from `tabProperty Setter` where | for ps in webnotes.conn.sql("""select * from `tabProperty Setter` where | ||||
doc_type=%s""", doctype, as_dict=1): | |||||
doc_type=%s""", (doctype,), as_dict=1): | |||||
if ps['doctype_or_field']=='DocType': | if ps['doctype_or_field']=='DocType': | ||||
if ps.get('property_type', None) in ('Int', 'Check'): | if ps.get('property_type', None) in ('Int', 'Check'): | ||||
ps['value'] = cint(ps['value']) | ps['value'] = cint(ps['value']) | ||||
@@ -149,7 +149,7 @@ def apply_property_setters(doctype, doclist): | |||||
def add_custom_fields(doctype, doclist): | def add_custom_fields(doctype, doclist): | ||||
try: | try: | ||||
res = webnotes.conn.sql("""SELECT * FROM `tabCustom Field` | res = webnotes.conn.sql("""SELECT * FROM `tabCustom Field` | ||||
WHERE dt = %s AND docstatus < 2""", doctype, as_dict=1) | |||||
WHERE dt = %s AND docstatus < 2""", (doctype,), as_dict=1) | |||||
except Exception, e: | except Exception, e: | ||||
if e.args[0]==1146: | if e.args[0]==1146: | ||||
return doclist | return doclist | ||||
@@ -251,7 +251,7 @@ def clear_cache(doctype=None): | |||||
# clear all parent doctypes | # clear all parent doctypes | ||||
for dt in webnotes.conn.sql("""select parent from tabDocField | for dt in webnotes.conn.sql("""select parent from tabDocField | ||||
where fieldtype="Table" and options=%s""", doctype): | |||||
where fieldtype="Table" and options=%s""", (doctype,)): | |||||
clear_single(dt[0]) | clear_single(dt[0]) | ||||
# clear all notifications | # clear all notifications | ||||
@@ -312,7 +312,7 @@ def expand_selects(doclist): | |||||
def add_print_formats(doclist): | def add_print_formats(doclist): | ||||
print_formats = webnotes.conn.sql("""select * FROM `tabPrint Format` | print_formats = webnotes.conn.sql("""select * FROM `tabPrint Format` | ||||
WHERE doc_type=%s AND docstatus<2""", doclist[0].name, as_dict=1) | |||||
WHERE doc_type=%s AND docstatus<2""", (doclist[0].name,), as_dict=1) | |||||
for pf in print_formats: | for pf in print_formats: | ||||
doclist.append(webnotes.model.doc.Document('Print Format', fielddata=pf)) | doclist.append(webnotes.model.doc.Document('Print Format', fielddata=pf)) | ||||
@@ -334,7 +334,7 @@ def get_link_fields(doctype): | |||||
def add_validators(doctype, doclist): | def add_validators(doctype, doclist): | ||||
for validator in webnotes.conn.sql("""select name from `tabDocType Validator` where | for validator in webnotes.conn.sql("""select name from `tabDocType Validator` where | ||||
for_doctype=%s""", doctype, as_dict=1): | |||||
for_doctype=%s""", (doctype,), as_dict=1): | |||||
doclist.extend(webnotes.get_doclist('DocType Validator', validator.name)) | doclist.extend(webnotes.get_doclist('DocType Validator', validator.name)) | ||||
def add_search_fields(doclist): | def add_search_fields(doclist): | ||||
@@ -149,7 +149,7 @@ def get_link_fields(doctype): | |||||
df.parent not like "old%%%%" and df.parent != '0' and | df.parent not like "old%%%%" and df.parent != '0' and | ||||
((df.options=%s and df.fieldtype='Link') or | ((df.options=%s and df.fieldtype='Link') or | ||||
(df.options='link:%s' and df.fieldtype='Select'))""" \ | (df.options='link:%s' and df.fieldtype='Select'))""" \ | ||||
% ('%s', doctype), doctype, as_dict=1) | |||||
% ('%s', doctype), (doctype,), as_dict=1) | |||||
# get link fields from tabCustom Field | # get link fields from tabCustom Field | ||||
custom_link_fields = webnotes.conn.sql("""\ | custom_link_fields = webnotes.conn.sql("""\ | ||||
@@ -161,7 +161,7 @@ def get_link_fields(doctype): | |||||
df.dt not like "old%%%%" and df.dt != '0' and | df.dt not like "old%%%%" and df.dt != '0' and | ||||
((df.options=%s and df.fieldtype='Link') or | ((df.options=%s and df.fieldtype='Link') or | ||||
(df.options='link:%s' and df.fieldtype='Select'))""" \ | (df.options='link:%s' and df.fieldtype='Select'))""" \ | ||||
% ('%s', doctype), doctype, as_dict=1) | |||||
% ('%s', doctype), (doctype,), as_dict=1) | |||||
# add custom link fields list to link fields list | # add custom link fields list to link fields list | ||||
link_fields += custom_link_fields | link_fields += custom_link_fields | ||||
@@ -176,7 +176,7 @@ def get_link_fields(doctype): | |||||
ps.property_type='options' and | ps.property_type='options' and | ||||
ps.field_name is not null and | ps.field_name is not null and | ||||
(ps.value=%s or ps.value='link:%s')""" \ | (ps.value=%s or ps.value='link:%s')""" \ | ||||
% ('%s', doctype), doctype, as_dict=1) | |||||
% ('%s', doctype), (doctype,), as_dict=1) | |||||
link_fields += property_setter_link_fields | link_fields += property_setter_link_fields | ||||
@@ -211,7 +211,7 @@ def get_select_fields(old, new): | |||||
df.parent != %s and df.fieldtype = 'Select' and | df.parent != %s and df.fieldtype = 'Select' and | ||||
df.options not like "link:%%%%" and | df.options not like "link:%%%%" and | ||||
(df.options like "%%%%%s%%%%")""" \ | (df.options like "%%%%%s%%%%")""" \ | ||||
% ('%s', old), new, as_dict=1) | |||||
% ('%s', old), (new,), as_dict=1) | |||||
# get link fields from tabCustom Field | # get link fields from tabCustom Field | ||||
custom_select_fields = webnotes.conn.sql("""\ | custom_select_fields = webnotes.conn.sql("""\ | ||||
@@ -224,7 +224,7 @@ def get_select_fields(old, new): | |||||
df.dt != %s and df.fieldtype = 'Select' and | df.dt != %s and df.fieldtype = 'Select' and | ||||
df.options not like "link:%%%%" and | df.options not like "link:%%%%" and | ||||
(df.options like "%%%%%s%%%%")""" \ | (df.options like "%%%%%s%%%%")""" \ | ||||
% ('%s', old), new, as_dict=1) | |||||
% ('%s', old), (new,), as_dict=1) | |||||
# add custom link fields list to link fields list | # add custom link fields list to link fields list | ||||
select_fields += custom_select_fields | select_fields += custom_select_fields | ||||
@@ -241,7 +241,7 @@ def get_select_fields(old, new): | |||||
ps.field_name is not null and | ps.field_name is not null and | ||||
ps.value not like "link:%%%%" and | ps.value not like "link:%%%%" and | ||||
(ps.value like "%%%%%s%%%%")""" \ | (ps.value like "%%%%%s%%%%")""" \ | ||||
% ('%s', old), new, as_dict=1) | |||||
% ('%s', old), (new,), as_dict=1) | |||||
select_fields += property_setter_select_fields | select_fields += property_setter_select_fields | ||||
@@ -275,11 +275,11 @@ def update_select_field_values(old, new): | |||||
def update_parenttype_values(old, new): | def update_parenttype_values(old, new): | ||||
child_doctypes = webnotes.conn.sql("""\ | child_doctypes = webnotes.conn.sql("""\ | ||||
select options, fieldname from `tabDocField` | select options, fieldname from `tabDocField` | ||||
where parent=%s and fieldtype='Table'""", new, as_dict=1) | |||||
where parent=%s and fieldtype='Table'""", (new,), as_dict=1) | |||||
custom_child_doctypes = webnotes.conn.sql("""\ | custom_child_doctypes = webnotes.conn.sql("""\ | ||||
select options, fieldname from `tabCustom Field` | select options, fieldname from `tabCustom Field` | ||||
where dt=%s and fieldtype='Table'""", new, as_dict=1) | |||||
where dt=%s and fieldtype='Table'""", (new,), as_dict=1) | |||||
child_doctypes += custom_child_doctypes | child_doctypes += custom_child_doctypes | ||||
fields = [d['fieldname'] for d in child_doctypes] | fields = [d['fieldname'] for d in child_doctypes] | ||||
@@ -288,7 +288,7 @@ def update_parenttype_values(old, new): | |||||
select value as options from `tabProperty Setter` | select value as options from `tabProperty Setter` | ||||
where doc_type=%s and property='options' and | where doc_type=%s and property='options' and | ||||
field_name in ("%s")""" % ('%s', '", "'.join(fields)), | field_name in ("%s")""" % ('%s', '", "'.join(fields)), | ||||
new) | |||||
(new,)) | |||||
child_doctypes += property_setter_child_doctypes | child_doctypes += property_setter_child_doctypes | ||||
child_doctypes = (d['options'] for d in child_doctypes) | child_doctypes = (d['options'] for d in child_doctypes) | ||||
@@ -148,7 +148,7 @@ class Profile: | |||||
def load_profile(self): | def load_profile(self): | ||||
d = webnotes.conn.sql("""select email, first_name, last_name, | d = webnotes.conn.sql("""select email, first_name, last_name, | ||||
email_signature, background_image, user_type, language | email_signature, background_image, user_type, language | ||||
from tabProfile where name = %s""", self.name, as_dict=1)[0] | |||||
from tabProfile where name = %s""", (self.name,), as_dict=1)[0] | |||||
if not self.can_read: | if not self.can_read: | ||||
self.build_permissions() | self.build_permissions() | ||||
@@ -169,7 +169,7 @@ class Profile: | |||||
return d | return d | ||||
def get_user_fullname(user): | def get_user_fullname(user): | ||||
fullname = webnotes.conn.sql("SELECT CONCAT_WS(' ', first_name, last_name) FROM `tabProfile` WHERE name=%s", user) | |||||
fullname = webnotes.conn.sql("SELECT CONCAT_WS(' ', first_name, last_name) FROM `tabProfile` WHERE name=%s", (user,)) | |||||
return fullname and fullname[0][0] or '' | return fullname and fullname[0][0] or '' | ||||
def get_system_managers(only_name=False): | def get_system_managers(only_name=False): | ||||
@@ -218,7 +218,7 @@ def get_roles(username=None, with_standard=True): | |||||
return ['Guest'] | return ['Guest'] | ||||
roles = [r[0] for r in webnotes.conn.sql("""select role from tabUserRole | roles = [r[0] for r in webnotes.conn.sql("""select role from tabUserRole | ||||
where parent=%s and role!='All'""", username)] + ['All'] | |||||
where parent=%s and role!='All'""", (username,))] + ['All'] | |||||
# filter standard if required | # filter standard if required | ||||
if not with_standard: | if not with_standard: | ||||
@@ -35,14 +35,14 @@ def clear_cache(user=None): | |||||
# clear notifications | # clear notifications | ||||
if webnotes.flags.in_install_app!="webnotes": | if webnotes.flags.in_install_app!="webnotes": | ||||
webnotes.conn.sql("""delete from `tabNotification Count` where owner=%s""", user) | |||||
webnotes.conn.sql("""delete from `tabNotification Count` where owner=%s""", (user,)) | |||||
if webnotes.session: | if webnotes.session: | ||||
if user==webnotes.session.user and webnotes.session.sid: | if user==webnotes.session.user and webnotes.session.sid: | ||||
cache.delete_value("session:" + webnotes.session.sid) | cache.delete_value("session:" + webnotes.session.sid) | ||||
else: | else: | ||||
for sid in webnotes.conn.sql_list("""select sid from tabSessions | for sid in webnotes.conn.sql_list("""select sid from tabSessions | ||||
where user=%s""", user): | |||||
where user=%s""", (user,)): | |||||
cache.delete_value("session:" + sid) | cache.delete_value("session:" + sid) | ||||
webnotes.defaults.clear_cache(user) | webnotes.defaults.clear_cache(user) | ||||
@@ -56,12 +56,12 @@ def clear_cache(user=None): | |||||
def clear_sessions(user=None, keep_current=False): | def clear_sessions(user=None, keep_current=False): | ||||
if not user: | if not user: | ||||
user = webnotes.session.user | user = webnotes.session.user | ||||
for sid in webnotes.conn.sql("""select sid from tabSessions where user=%s""", user): | |||||
for sid in webnotes.conn.sql("""select sid from tabSessions where user=%s""", (user,)): | |||||
if keep_current and webnotes.session.sid==sid[0]: | if keep_current and webnotes.session.sid==sid[0]: | ||||
pass | pass | ||||
else: | else: | ||||
webnotes.cache().delete_value("session:" + sid[0]) | webnotes.cache().delete_value("session:" + sid[0]) | ||||
webnotes.conn.sql("""delete from tabSessions where sid=%s""", sid[0]) | |||||
webnotes.conn.sql("""delete from tabSessions where sid=%s""", (sid[0],)) | |||||
def get(): | def get(): | ||||
"""get session boot info""" | """get session boot info""" | ||||
@@ -211,7 +211,7 @@ class Session: | |||||
def delete_session(self): | def delete_session(self): | ||||
webnotes.cache().delete_value("session:" + self.sid) | webnotes.cache().delete_value("session:" + self.sid) | ||||
r = webnotes.conn.sql("""delete from tabSessions where sid=%s""", self.sid) | |||||
r = webnotes.conn.sql("""delete from tabSessions where sid=%s""", (self.sid,)) | |||||
def start_as_guest(self): | def start_as_guest(self): | ||||
"""all guests share the same 'Guest' session""" | """all guests share the same 'Guest' session""" | ||||
@@ -0,0 +1 @@ | |||||
<a href="https://github.com/webnotes/wnframework" style="color: #aaa">Built on Web Notes</a> |
@@ -61,7 +61,7 @@ def send(recipients=None, sender=None, doctype='Profile', email_field='email', | |||||
for r in filter(None, list(set(recipients))): | for r in filter(None, list(set(recipients))): | ||||
rdata = webnotes.conn.sql("""select * from `tab%s` where %s=%s""" % (doctype, | rdata = webnotes.conn.sql("""select * from `tab%s` where %s=%s""" % (doctype, | ||||
email_field, '%s'), r, as_dict=1) | |||||
email_field, '%s'), (r,), as_dict=1) | |||||
doc = rdata and rdata[0] or {} | doc = rdata and rdata[0] or {} | ||||
@@ -95,7 +95,7 @@ def unsubscribe(): | |||||
email = webnotes.form_dict.get('email') | email = webnotes.form_dict.get('email') | ||||
webnotes.conn.sql("""update `tab%s` set unsubscribed=1 | webnotes.conn.sql("""update `tab%s` set unsubscribed=1 | ||||
where `%s`=%s""" % (doctype, field, '%s'), email) | |||||
where `%s`=%s""" % (doctype, field, '%s'), (email,)) | |||||
if not webnotes.form_dict.get("from_test"): | if not webnotes.form_dict.get("from_test"): | ||||
webnotes.conn.commit() | webnotes.conn.commit() | ||||
@@ -129,13 +129,13 @@ def flush(from_test=False): | |||||
break | break | ||||
webnotes.conn.sql("""update `tabBulk Email` set status='Sending' where name=%s""", | webnotes.conn.sql("""update `tabBulk Email` set status='Sending' where name=%s""", | ||||
email["name"], auto_commit=auto_commit) | |||||
(email["name"],), auto_commit=auto_commit) | |||||
try: | try: | ||||
if not from_test: | if not from_test: | ||||
smptserver.sess.sendmail(email["sender"], email["recipient"], email["message"]) | smptserver.sess.sendmail(email["sender"], email["recipient"], email["message"]) | ||||
webnotes.conn.sql("""update `tabBulk Email` set status='Sent' where name=%s""", | webnotes.conn.sql("""update `tabBulk Email` set status='Sent' where name=%s""", | ||||
email["name"], auto_commit=auto_commit) | |||||
(email["name"],), auto_commit=auto_commit) | |||||
except Exception, e: | except Exception, e: | ||||
webnotes.conn.sql("""update `tabBulk Email` set status='Error', error=%s | webnotes.conn.sql("""update `tabBulk Email` set status='Error', error=%s | ||||
@@ -26,7 +26,7 @@ class DocType(WebsiteGenerator): | |||||
# update posts | # update posts | ||||
webnotes.conn.sql("""update tabBlogger set posts=(select count(*) from `tabBlog Post` | webnotes.conn.sql("""update tabBlogger set posts=(select count(*) from `tabBlog Post` | ||||
where ifnull(blogger,'')=tabBlogger.name) | where ifnull(blogger,'')=tabBlogger.name) | ||||
where name=%s""", self.doc.blogger) | |||||
where name=%s""", (self.doc.blogger,)) | |||||
def on_update(self): | def on_update(self): | ||||
WebsiteGenerator.on_update(self) | WebsiteGenerator.on_update(self) | ||||
@@ -56,7 +56,7 @@ class DocType(WebsiteGenerator): | |||||
self.doc.comment_list = webnotes.conn.sql("""\ | self.doc.comment_list = webnotes.conn.sql("""\ | ||||
select comment, comment_by_fullname, creation | select comment, comment_by_fullname, creation | ||||
from `tabComment` where comment_doctype="Blog Post" | from `tabComment` where comment_doctype="Blog Post" | ||||
and comment_docname=%s order by creation""", self.doc.name, as_dict=1) or [] | |||||
and comment_docname=%s order by creation""", (self.doc.name,), as_dict=1) or [] | |||||
def clear_blog_cache(): | def clear_blog_cache(): | ||||
@@ -66,8 +66,10 @@ class TestBlogPost(unittest.TestCase): | |||||
def test_restriction_in_report(self): | def test_restriction_in_report(self): | ||||
webnotes.defaults.add_default("Blog Category", "_Test Blog Category 1", "test1@example.com", | webnotes.defaults.add_default("Blog Category", "_Test Blog Category 1", "test1@example.com", | ||||
"Restriction") | "Restriction") | ||||
webnotes.local.reportview_doctypes = {} | |||||
names = [d.name for d in webnotes.get_list("Blog Post", fields=["name", "blog_category"])] | names = [d.name for d in webnotes.get_list("Blog Post", fields=["name", "blog_category"])] | ||||
self.assertTrue("_test-blog-post-1" in names) | self.assertTrue("_test-blog-post-1" in names) | ||||
self.assertFalse("_test-blog-post" in names) | self.assertFalse("_test-blog-post" in names) | ||||
@@ -111,6 +111,9 @@ def load_doctypes(): | |||||
for t in webnotes.local.reportview_tables: | for t in webnotes.local.reportview_tables: | ||||
if t.startswith('`'): | if t.startswith('`'): | ||||
doctype = t[4:-1] | doctype = t[4:-1] | ||||
if webnotes.local.reportview_doctypes.get(doctype): | |||||
continue | |||||
if not webnotes.has_permission(doctype): | if not webnotes.has_permission(doctype): | ||||
raise webnotes.PermissionError, doctype | raise webnotes.PermissionError, doctype | ||||
webnotes.local.reportview_doctypes[doctype] = webnotes.model.doctype.get(doctype) | webnotes.local.reportview_doctypes[doctype] = webnotes.model.doctype.get(doctype) | ||||
@@ -172,8 +175,7 @@ def build_filter_conditions(filters, conditions): | |||||
if not tname in webnotes.local.reportview_tables: | if not tname in webnotes.local.reportview_tables: | ||||
webnotes.local.reportview_tables.append(tname) | webnotes.local.reportview_tables.append(tname) | ||||
if not hasattr(webnotes.local, "reportview_doctypes"): | |||||
load_doctypes() | |||||
load_doctypes() | |||||
# prepare in condition | # prepare in condition | ||||
if f[2] in ['in', 'not in']: | if f[2] in ['in', 'not in']: | ||||
@@ -202,10 +204,10 @@ def build_match_conditions(doctype, fields=None, as_condition=True): | |||||
match_filters = {} | match_filters = {} | ||||
match_conditions = [] | match_conditions = [] | ||||
if not getattr(webnotes.local, "reportview_tables", None) \ | |||||
or not getattr(webnotes.local, "reportview_doctypes", None): | |||||
if not getattr(webnotes.local, "reportview_tables", None): | |||||
webnotes.local.reportview_tables = get_tables(doctype, fields) | webnotes.local.reportview_tables = get_tables(doctype, fields) | ||||
load_doctypes() | |||||
load_doctypes() | |||||
# get restrictions | # get restrictions | ||||
restrictions = webnotes.defaults.get_restrictions() | restrictions = webnotes.defaults.get_restrictions() | ||||