@@ -40,7 +40,6 @@ class DocType(): | |||||
and attached_to_doctype=%s | and attached_to_doctype=%s | ||||
and attached_to_name=%s""", (self.doc.file_name, self.doc.attached_to_doctype, | and attached_to_name=%s""", (self.doc.file_name, self.doc.attached_to_doctype, | ||||
self.doc.attached_to_name))[0][0] | self.doc.attached_to_name))[0][0] | ||||
webnotes.msgprint(n_records) | |||||
if n_records > 1: | if n_records > 1: | ||||
webnotes.msgprint(webnotes._("Same file has already been attached to the record")) | webnotes.msgprint(webnotes._("Same file has already been attached to the record")) | ||||
raise webnotes.DuplicateEntryError | raise webnotes.DuplicateEntryError | ||||
@@ -187,7 +187,10 @@ Thank you,<br> | |||||
'product': startup.product_name, | 'product': startup.product_name, | ||||
'user_fullname': get_user_fullname(webnotes.session['user']) | 'user_fullname': get_user_fullname(webnotes.session['user']) | ||||
} | } | ||||
sendmail_md(self.doc.email, subject=subject, msg=txt % args) | |||||
sender = webnotes.session.user != "Administrator" and webnotes.session.user or None | |||||
sendmail_md(recipients=self.doc.email, sender=sender, subject=subject, msg=txt % args) | |||||
def on_trash(self): | def on_trash(self): | ||||
if self.doc.name in ["Administrator", "Guest"]: | if self.doc.name in ["Administrator", "Guest"]: | ||||
@@ -1,8 +1,8 @@ | |||||
[ | [ | ||||
{ | { | ||||
"creation": "2013-02-25 13:11:50", | |||||
"creation": "2013-03-09 15:45:57", | |||||
"docstatus": 0, | "docstatus": 0, | ||||
"modified": "2013-02-25 14:18:36", | |||||
"modified": "2013-04-30 17:50:00", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"owner": "Administrator" | "owner": "Administrator" | ||||
}, | }, | ||||
@@ -41,6 +41,7 @@ | |||||
"fieldname": "report_name", | "fieldname": "report_name", | ||||
"fieldtype": "Data", | "fieldtype": "Data", | ||||
"label": "Report Name", | "label": "Report Name", | ||||
"read_only": 0, | |||||
"reqd": 1 | "reqd": 1 | ||||
}, | }, | ||||
{ | { | ||||
@@ -50,6 +51,7 @@ | |||||
"in_list_view": 1, | "in_list_view": 1, | ||||
"label": "Ref DocType", | "label": "Ref DocType", | ||||
"options": "DocType", | "options": "DocType", | ||||
"read_only": 0, | |||||
"reqd": 1 | "reqd": 1 | ||||
}, | }, | ||||
{ | { | ||||
@@ -59,12 +61,20 @@ | |||||
"in_list_view": 1, | "in_list_view": 1, | ||||
"label": "Is Standard", | "label": "Is Standard", | ||||
"options": "No\nYes", | "options": "No\nYes", | ||||
"read_only": 0, | |||||
"reqd": 1 | "reqd": 1 | ||||
}, | }, | ||||
{ | |||||
"doctype": "DocField", | |||||
"fieldname": "add_total_row", | |||||
"fieldtype": "Check", | |||||
"label": "Add Total Row" | |||||
}, | |||||
{ | { | ||||
"doctype": "DocField", | "doctype": "DocField", | ||||
"fieldname": "column_break_4", | "fieldname": "column_break_4", | ||||
"fieldtype": "Column Break" | |||||
"fieldtype": "Column Break", | |||||
"read_only": 0 | |||||
}, | }, | ||||
{ | { | ||||
"doctype": "DocField", | "doctype": "DocField", | ||||
@@ -72,25 +82,29 @@ | |||||
"fieldtype": "Select", | "fieldtype": "Select", | ||||
"label": "Report Type", | "label": "Report Type", | ||||
"options": "Report Builder\nQuery Report\nScript Report", | "options": "Report Builder\nQuery Report\nScript Report", | ||||
"read_only": 0, | |||||
"reqd": 1 | "reqd": 1 | ||||
}, | }, | ||||
{ | { | ||||
"doctype": "DocField", | "doctype": "DocField", | ||||
"fieldname": "disabled", | "fieldname": "disabled", | ||||
"fieldtype": "Check", | "fieldtype": "Check", | ||||
"label": "Disabled" | |||||
"label": "Disabled", | |||||
"read_only": 0 | |||||
}, | }, | ||||
{ | { | ||||
"doctype": "DocField", | "doctype": "DocField", | ||||
"fieldname": "section_break_6", | "fieldname": "section_break_6", | ||||
"fieldtype": "Section Break" | |||||
"fieldtype": "Section Break", | |||||
"read_only": 0 | |||||
}, | }, | ||||
{ | { | ||||
"depends_on": "eval:doc.report_type==\"Query Report\"", | "depends_on": "eval:doc.report_type==\"Query Report\"", | ||||
"doctype": "DocField", | "doctype": "DocField", | ||||
"fieldname": "query", | "fieldname": "query", | ||||
"fieldtype": "Code", | "fieldtype": "Code", | ||||
"label": "Query" | |||||
"label": "Query", | |||||
"read_only": 0 | |||||
}, | }, | ||||
{ | { | ||||
"depends_on": "eval:doc.report_type==\"Report Builder\"", | "depends_on": "eval:doc.report_type==\"Report Builder\"", | ||||
@@ -26,7 +26,7 @@ cur_frm.cscript['server_python'] = function(doc, dt, dn) { | |||||
$c_obj(make_doclist(doc.doctype, doc.name), 'execute_server', '', function(r, rt) { | $c_obj(make_doclist(doc.doctype, doc.name), 'execute_server', '', function(r, rt) { | ||||
doc = locals[doc.doctype][doc.name]; | doc = locals[doc.doctype][doc.name]; | ||||
if(r.exc) { | if(r.exc) { | ||||
doc.response = r.exc; | |||||
doc.response = (r.exc || []).join("\n"); | |||||
} else { | } else { | ||||
doc.response = 'Worked!'.bold() | doc.response = 'Worked!'.bold() | ||||
} | } | ||||
@@ -176,8 +176,12 @@ def upload(): | |||||
return columns | return columns | ||||
# extra input params | |||||
import json | |||||
params = json.loads(webnotes.form_dict.get("params") or '{}') | |||||
# header | # header | ||||
rows = read_csv_content_from_uploaded_file() | |||||
rows = read_csv_content_from_uploaded_file(params.get("ignore_encoding_errors")) | |||||
start_row = get_start_row() | start_row = get_start_row() | ||||
header = rows[:start_row] | header = rows[:start_row] | ||||
data = rows[start_row:] | data = rows[start_row:] | ||||
@@ -195,7 +199,7 @@ def upload(): | |||||
webnotes.conn.begin() | webnotes.conn.begin() | ||||
overwrite = webnotes.form_dict.get('overwrite') | |||||
overwrite = params.get('overwrite') | |||||
doctype_dl = webnotes.model.doctype.get(doctype) | doctype_dl = webnotes.model.doctype.get(doctype) | ||||
# delete child rows (if parenttype) | # delete child rows (if parenttype) | ||||
@@ -226,8 +230,7 @@ def upload(): | |||||
ret.append('Inserted row for %s at #%s' % (getlink(parenttype, | ret.append('Inserted row for %s at #%s' % (getlink(parenttype, | ||||
doc.parent), unicode(doc.idx))) | doc.parent), unicode(doc.idx))) | ||||
else: | else: | ||||
ret.append(import_doc(d, doctype, overwrite, row_idx, | |||||
webnotes.form_dict.get("_submit")=="on")) | |||||
ret.append(import_doc(d, doctype, overwrite, row_idx, params.get("_submit"))) | |||||
except Exception, e: | except Exception, e: | ||||
error = True | error = True | ||||
ret.append('Error for row (#%d) %s : %s' % (row_idx, | ret.append('Error for row (#%d) %s : %s' % (row_idx, | ||||
@@ -307,13 +310,10 @@ def delete_child_rows(rows, doctype): | |||||
def import_doc(d, doctype, overwrite, row_idx, submit=False): | def import_doc(d, doctype, overwrite, row_idx, submit=False): | ||||
"""import main (non child) document""" | """import main (non child) document""" | ||||
from webnotes.model.bean import Bean | |||||
if webnotes.conn.exists(doctype, d['name']): | if webnotes.conn.exists(doctype, d['name']): | ||||
if overwrite: | if overwrite: | ||||
doclist = webnotes.model.doc.get(doctype, d['name']) | |||||
doclist[0].fields.update(d) | |||||
bean = Bean(doclist) | |||||
bean = webnotes.bean(doctype, d['name']) | |||||
bean.doc.fields.update(d) | |||||
if d.get("docstatus") == 1: | if d.get("docstatus") == 1: | ||||
bean.update_after_submit() | bean.update_after_submit() | ||||
else: | else: | ||||
@@ -323,12 +323,11 @@ def import_doc(d, doctype, overwrite, row_idx, submit=False): | |||||
return 'Ignored row (#%d) %s (exists)' % (row_idx, | return 'Ignored row (#%d) %s (exists)' % (row_idx, | ||||
getlink(doctype, d['name'])) | getlink(doctype, d['name'])) | ||||
else: | else: | ||||
d['__islocal'] = 1 | |||||
dl = Bean([webnotes.model.doc.Document(fielddata = d)]) | |||||
dl.save() | |||||
bean = webnotes.bean([d]) | |||||
bean.insert() | |||||
if submit: | if submit: | ||||
dl.submit() | |||||
bean.submit() | |||||
return 'Inserted row (#%d) %s' % (row_idx, getlink(doctype, | return 'Inserted row (#%d) %s' % (row_idx, getlink(doctype, | ||||
dl.doc.fields['name'])) | |||||
bean.doc.fields['name'])) |
@@ -136,7 +136,8 @@ wn.ui.form.AssignTo = Class.extend({ | |||||
msgprint("Email sent to " + assign_to); | msgprint("Email sent to " + assign_to); | ||||
me.render(r.message); | me.render(r.message); | ||||
} | } | ||||
} | |||||
}, | |||||
btn: this | |||||
}); | }); | ||||
} | } | ||||
} | } | ||||
@@ -85,7 +85,7 @@ wn.request.call = function(opts) { | |||||
opts.error && opts.error(xhr) | opts.error && opts.error(xhr) | ||||
} | } | ||||
}; | }; | ||||
if(opts.progress_bar) { | if(opts.progress_bar) { | ||||
var interval = null; | var interval = null; | ||||
$.extend(ajax_args, { | $.extend(ajax_args, { | ||||
@@ -109,7 +109,7 @@ wn.request.call = function(opts) { | |||||
} | } | ||||
}) | }) | ||||
} | } | ||||
$.ajax(ajax_args); | $.ajax(ajax_args); | ||||
} | } | ||||
@@ -151,9 +151,9 @@ wn.request.cleanup = function(opts, r) { | |||||
} | } | ||||
// show messages | // show messages | ||||
if(r.server_messages) { | |||||
r.server_messages = JSON.parse(r.server_messages) | |||||
msgprint(r.server_messages); | |||||
if(r._server_messages) { | |||||
r._server_messages = JSON.parse(r._server_messages) | |||||
msgprint(r._server_messages); | |||||
} | } | ||||
// show errors | // show errors | ||||
@@ -164,10 +164,30 @@ wn.request.cleanup = function(opts, r) { | |||||
if(v)console.log(v); | if(v)console.log(v); | ||||
}) | }) | ||||
} else { | } else { | ||||
console.log(r.exc); | |||||
console.log(r.exc); | |||||
} | } | ||||
}; | }; | ||||
// debug messages | |||||
if(r._debug_messages) { | |||||
console.log("-") | |||||
console.log("-") | |||||
console.log("-") | |||||
if(opts.args) { | |||||
console.log("<<<< arguments "); | |||||
console.log(opts.args); | |||||
console.log(">>>>") | |||||
} | |||||
$.each(JSON.parse(r._debug_messages), function(i, v) { console.log(v); }); | |||||
console.log("<<<< response"); | |||||
delete r._debug_messages; | |||||
console.log(r); | |||||
console.log(">>>>") | |||||
console.log("-") | |||||
console.log("-") | |||||
console.log("-") | |||||
} | |||||
if(r['403']) { | if(r['403']) { | ||||
wn.set_route('403'); | wn.set_route('403'); | ||||
} | } | ||||
@@ -25,10 +25,16 @@ wn.upload = { | |||||
} | } | ||||
// add other inputs in the div as arguments | // add other inputs in the div as arguments | ||||
opts.args.params = {}; | |||||
$upload.find("input[name]").each(function() { | $upload.find("input[name]").each(function() { | ||||
var key = $(this).attr("name"); | var key = $(this).attr("name"); | ||||
var type = $(this).attr("type"); | |||||
if(key!="filedata" && key!="file_url") { | if(key!="filedata" && key!="file_url") { | ||||
opts.args[key] = $(this).val(); | |||||
if(type === "checkbox") { | |||||
opts.args.params[key] = $(this).is(":checked"); | |||||
} else { | |||||
opts.args.params[key] = $(this).val(); | |||||
} | |||||
} | } | ||||
}) | }) | ||||
@@ -141,15 +141,14 @@ wn.views.QueryReport = Class.extend({ | |||||
$(f.wrapper).find("input, button").css({"margin-top":"-4px"}); | $(f.wrapper).find("input, button").css({"margin-top":"-4px"}); | ||||
else if(f.df.fieldtype == "Date") | else if(f.df.fieldtype == "Date") | ||||
$(f.wrapper).css({"margin-right":"-15px"}); | $(f.wrapper).css({"margin-right":"-15px"}); | ||||
if(df.get_query) f.get_query = df.get_query; | if(df.get_query) f.get_query = df.get_query; | ||||
}); | }); | ||||
this.set_filters_by_name(); | this.set_filters_by_name(); | ||||
}, | }, | ||||
clear_filters: function() { | clear_filters: function() { | ||||
this.filters = []; | this.filters = []; | ||||
this.appframe.toolbar.find(".filters").remove(); | |||||
this.appframe.$w.find('.appframe-toolbar').find(".filters").remove(); | |||||
}, | }, | ||||
set_filters_by_name: function() { | set_filters_by_name: function() { | ||||
this.filters_by_name = {}; | this.filters_by_name = {}; | ||||
@@ -68,6 +68,7 @@ incoming_cookies = {} | |||||
add_cookies = {} # append these to outgoing request | add_cookies = {} # append these to outgoing request | ||||
cookies = {} | cookies = {} | ||||
response = _dict({'message':'', 'exc':''}) | response = _dict({'message':'', 'exc':''}) | ||||
error_log = [] | |||||
debug_log = [] | debug_log = [] | ||||
message_log = [] | message_log = [] | ||||
mute_emails = False | mute_emails = False | ||||
@@ -107,7 +108,16 @@ def errprint(msg): | |||||
print repr(msg) | print repr(msg) | ||||
from utils import cstr | from utils import cstr | ||||
debug_log.append(cstr(msg or '')) | |||||
error_log.append(cstr(msg)) | |||||
def log(msg): | |||||
if not request_method: | |||||
import conf | |||||
if getattr(conf, "logging", False): | |||||
print repr(msg) | |||||
from utils import cstr | |||||
debug_log.append(cstr(msg)) | |||||
def msgprint(msg, small=0, raise_exception=0, as_table=False): | def msgprint(msg, small=0, raise_exception=0, as_table=False): | ||||
from utils import cstr | from utils import cstr | ||||
@@ -103,6 +103,12 @@ class Database: | |||||
webnotes.errprint(query % values) | webnotes.errprint(query % values) | ||||
except TypeError: | except TypeError: | ||||
webnotes.errprint([query, values]) | webnotes.errprint([query, values]) | ||||
if getattr(conf, "logging", False)==2: | |||||
webnotes.log("<<<< query") | |||||
webnotes.log(query) | |||||
webnotes.log("with values:") | |||||
webnotes.log(values) | |||||
webnotes.log(">>>>") | |||||
self._cursor.execute(query, values) | self._cursor.execute(query, values) | ||||
@@ -110,6 +116,10 @@ class Database: | |||||
if debug: | if debug: | ||||
self.explain_query(query) | self.explain_query(query) | ||||
webnotes.errprint(query) | webnotes.errprint(query) | ||||
if getattr(conf, "logging", False)==2: | |||||
webnotes.log("<<<< query") | |||||
webnotes.log(query) | |||||
webnotes.log(">>>>") | |||||
self._cursor.execute(query) | self._cursor.execute(query) | ||||
except Exception, e: | except Exception, e: | ||||
@@ -136,14 +146,17 @@ class Database: | |||||
return self._cursor.fetchall() | return self._cursor.fetchall() | ||||
def explain_query(self, query, values=None): | def explain_query(self, query, values=None): | ||||
webnotes.errprint("--- query explain ---") | |||||
if values is None: | |||||
self._cursor.execute("explain " + query) | |||||
else: | |||||
self._cursor.execute("explain " + query, values) | |||||
import json | |||||
webnotes.errprint(json.dumps(self.fetch_as_dict(), indent=1)) | |||||
webnotes.errprint("--- query explain end ---") | |||||
try: | |||||
webnotes.errprint("--- query explain ---") | |||||
if values is None: | |||||
self._cursor.execute("explain " + query) | |||||
else: | |||||
self._cursor.execute("explain " + query, values) | |||||
import json | |||||
webnotes.errprint(json.dumps(self.fetch_as_dict(), indent=1)) | |||||
webnotes.errprint("--- query explain end ---") | |||||
except: | |||||
webnotes.errprint("error in query explain") | |||||
def sql_list(self, query, values=(), debug=False): | def sql_list(self, query, values=(), debug=False): | ||||
return [r[0] for r in self.sql(query, values, debug=debug)] | return [r[0] for r in self.sql(query, values, debug=debug)] | ||||
@@ -326,10 +339,10 @@ class Database: | |||||
return [] | return [] | ||||
if as_dict: | if as_dict: | ||||
return values | |||||
return values and [values] or [] | |||||
if isinstance(fields, list): | if isinstance(fields, list): | ||||
return map(lambda d: values.get(d), fields) | |||||
return [map(lambda d: values.get(d), fields)] | |||||
else: | else: | ||||
r = self.sql("""select field, value | r = self.sql("""select field, value | ||||
@@ -340,10 +353,7 @@ class Database: | |||||
if as_dict: | if as_dict: | ||||
return r and [webnotes._dict(r)] or [] | return r and [webnotes._dict(r)] or [] | ||||
else: | else: | ||||
if r: | |||||
return [[i[1] for i in r]] | |||||
else: | |||||
return [] | |||||
return r and [[i[1] for i in r]] or [] | |||||
def get_values_from_table(self, fields, filters, doctype, as_dict, debug): | def get_values_from_table(self, fields, filters, doctype, as_dict, debug): | ||||
fl = fields | fl = fields | ||||
@@ -140,7 +140,7 @@ def get_defaults_for_match(userd): | |||||
def clear_cache(parent=None): | def clear_cache(parent=None): | ||||
def all_profiles(): | def all_profiles(): | ||||
return webnotes.conn.sql_list("select name from tabProfile") + ["Control Panel"] | |||||
return webnotes.conn.sql_list("select name from tabProfile") + ["Control Panel", "__global"] | |||||
if parent=="Control Panel" or not parent: | if parent=="Control Panel" or not parent: | ||||
parent = all_profiles() | parent = all_profiles() | ||||
@@ -211,6 +211,7 @@ def get_method(cmd): | |||||
method = webnotes.get_method(cmd) | method = webnotes.get_method(cmd) | ||||
else: | else: | ||||
method = globals()[cmd] | method = globals()[cmd] | ||||
webnotes.log("method:" + cmd) | |||||
return method | return method | ||||
def print_response(): | def print_response(): | ||||
@@ -255,7 +256,7 @@ def print_iframe(): | |||||
eprint("") | eprint("") | ||||
eprint(webnotes.response.get('result') or '') | eprint(webnotes.response.get('result') or '') | ||||
if webnotes.debug_log: | |||||
if webnotes.error_log: | |||||
import json | import json | ||||
eprint("""\ | eprint("""\ | ||||
<script> | <script> | ||||
@@ -273,7 +274,7 @@ def print_iframe(): | |||||
} | } | ||||
</script>""" % { | </script>""" % { | ||||
'messages': json.dumps(webnotes.message_log).replace("'", "\\'"), | 'messages': json.dumps(webnotes.message_log).replace("'", "\\'"), | ||||
'errors': json.dumps(webnotes.debug_log).replace("'", "\\'"), | |||||
'errors': json.dumps(webnotes.error_log).replace("'", "\\'"), | |||||
}) | }) | ||||
def print_raw(): | def print_raw(): | ||||
@@ -287,13 +288,17 @@ def print_raw(): | |||||
def make_logs(): | def make_logs(): | ||||
"""make strings for msgprint and errprint""" | """make strings for msgprint and errprint""" | ||||
import json | |||||
import json, conf | |||||
from webnotes.utils import cstr | from webnotes.utils import cstr | ||||
if webnotes.debug_log: | |||||
webnotes.response['exc'] = json.dumps("\n".join([cstr(d) for d in webnotes.debug_log])) | |||||
if webnotes.error_log: | |||||
# webnotes.response['exc'] = json.dumps("\n".join([cstr(d) for d in webnotes.error_log])) | |||||
webnotes.response['exc'] = json.dumps([cstr(d) for d in webnotes.error_log]) | |||||
if webnotes.message_log: | if webnotes.message_log: | ||||
webnotes.response['server_messages'] = json.dumps([cstr(d) for d in webnotes.message_log]) | |||||
webnotes.response['_server_messages'] = json.dumps([cstr(d) for d in webnotes.message_log]) | |||||
if webnotes.debug_log and getattr(conf, "logging", False): | |||||
webnotes.response['_debug_messages'] = json.dumps(webnotes.debug_log) | |||||
def print_cookie_header(): | def print_cookie_header(): | ||||
"""if there ar additional cookies defined during the request, add them""" | """if there ar additional cookies defined during the request, add them""" | ||||
@@ -380,7 +380,7 @@ class Document: | |||||
res = webnotes.model.meta.get_dt_values(self.doctype, | res = webnotes.model.meta.get_dt_values(self.doctype, | ||||
'autoname, issingle, istable, name_case', as_dict=1) | 'autoname, issingle, istable, name_case', as_dict=1) | ||||
res = res and res[0] or {} | res = res and res[0] or {} | ||||
if new: | if new: | ||||
self.fields["__islocal"] = 1 | self.fields["__islocal"] = 1 | ||||
@@ -214,9 +214,7 @@ def check_if_doc_is_linked(dt, dn, method="Delete"): | |||||
link_fields = get_link_fields(dt) | link_fields = get_link_fields(dt) | ||||
link_fields = [[lf['parent'], lf['fieldname']] for lf in link_fields] | link_fields = [[lf['parent'], lf['fieldname']] for lf in link_fields] | ||||
for l in link_fields: | |||||
link_dt, link_field = l | |||||
for link_dt, link_field in link_fields: | |||||
item = webnotes.conn.get_value(link_dt, {link_field:dn}, ["name", "parent", "parenttype", | item = webnotes.conn.get_value(link_dt, {link_field:dn}, ["name", "parent", "parenttype", | ||||
"docstatus"], as_dict=True) | "docstatus"], as_dict=True) | ||||
@@ -193,9 +193,12 @@ def now_datetime(): | |||||
def get_user_time_zone(): | def get_user_time_zone(): | ||||
global user_time_zone | global user_time_zone | ||||
if not user_time_zone: | |||||
user_time_zone = webnotes.cache().get_value("time_zone") | |||||
if not user_time_zone: | if not user_time_zone: | ||||
user_time_zone = webnotes.conn.get_value('Control Panel', None, 'time_zone') \ | user_time_zone = webnotes.conn.get_value('Control Panel', None, 'time_zone') \ | ||||
or 'Asia/Calcutta' | or 'Asia/Calcutta' | ||||
webnotes.cache().set_value("time_zone", user_time_zone) | |||||
return user_time_zone | return user_time_zone | ||||
def convert_utc_to_user_timezone(utc_timestamp): | def convert_utc_to_user_timezone(utc_timestamp): | ||||
@@ -26,10 +26,10 @@ import json | |||||
import csv, cStringIO | import csv, cStringIO | ||||
from webnotes.utils import encode, cstr | from webnotes.utils import encode, cstr | ||||
def read_csv_content_from_uploaded_file(): | |||||
def read_csv_content_from_uploaded_file(ignore_encoding=False): | |||||
from webnotes.utils.file_manager import get_uploaded_content | from webnotes.utils.file_manager import get_uploaded_content | ||||
fname, fcontent = get_uploaded_content() | fname, fcontent = get_uploaded_content() | ||||
return read_csv_content(fcontent) | |||||
return read_csv_content(fcontent, ignore_encoding) | |||||
def read_csv_content_from_attached_file(doc): | def read_csv_content_from_attached_file(doc): | ||||
fileid = webnotes.conn.get_value("File Data", {"attached_to_doctype": doc.doctype, | fileid = webnotes.conn.get_value("File Data", {"attached_to_doctype": doc.doctype, | ||||
@@ -28,7 +28,7 @@ def get_html(page_name): | |||||
# load from cache, if auto cache clear is falsy | # load from cache, if auto cache clear is falsy | ||||
if not (hasattr(conf, 'auto_cache_clear') and conf.auto_cache_clear or 0): | if not (hasattr(conf, 'auto_cache_clear') and conf.auto_cache_clear or 0): | ||||
if not get_page_settings().get("page_name", {}).get("no_cache", None): | |||||
if not get_page_settings().get(page_name, {}).get("no_cache"): | |||||
html = webnotes.cache().get_value("page:" + page_name) | html = webnotes.cache().get_value("page:" + page_name) | ||||
from_cache = True | from_cache = True | ||||
@@ -66,7 +66,7 @@ def add(args=None): | |||||
# notify | # notify | ||||
if not args.get("no_notification"): | if not args.get("no_notification"): | ||||
notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', notify=args.get('notify')) | |||||
notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', description=args.get("description"), notify=args.get('notify')) | |||||
# update feeed | # update feeed | ||||
try: | try: | ||||
@@ -100,9 +100,14 @@ def remove(doctype, name, assign_to): | |||||
if res and res[0]: notify_assignment(res[0][0], res[0][1], res[0][2], res[0][3]) | if res and res[0]: notify_assignment(res[0][0], res[0][1], res[0][2], res[0][3]) | ||||
return get({"doctype": doctype, "name": name}) | return get({"doctype": doctype, "name": name}) | ||||
def clear(doctype, name): | |||||
for assign_to in webnotes.conn.sql_list("""select owner from `tabToDo` | |||||
where reference_type=%(doctype)s and reference_name=%(name)s""", locals()): | |||||
remove(doctype, name, assign_to) | |||||
def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE', notify=0): | |||||
def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE', | |||||
description=None, notify=0): | |||||
""" | """ | ||||
Notify assignee that there is a change in assignment | Notify assignee that there is a change in assignment | ||||
""" | """ | ||||
@@ -139,9 +144,10 @@ def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE', no | |||||
else: | else: | ||||
arg = { | arg = { | ||||
'contact': owner, | 'contact': owner, | ||||
'txt': "A new task, %s, has been assigned to you by %s." \ | |||||
'txt': "A new task, %s, has been assigned to you by %s. %s" \ | |||||
% (assignment, | % (assignment, | ||||
user_info.get(webnotes.session.get('user'), {}).get('fullname')), | |||||
user_info.get(webnotes.session.get('user'), {}).get('fullname'), | |||||
description and ("<p>Description: " + description + "</p>") or ""), | |||||
'notify': notify | 'notify': notify | ||||
} | } | ||||
@@ -27,6 +27,7 @@ import os, json | |||||
from webnotes import _ | from webnotes import _ | ||||
from webnotes.modules import scrub, get_module_path | from webnotes.modules import scrub, get_module_path | ||||
from webnotes.utils import flt, cint | |||||
@webnotes.whitelist() | @webnotes.whitelist() | ||||
def get_script(report_name): | def get_script(report_name): | ||||
@@ -67,7 +68,23 @@ def run(report_name, filters=None): | |||||
+ ".report." + scrub(report.name) + "." + scrub(report.name) + ".execute" | + ".report." + scrub(report.name) + "." + scrub(report.name) + ".execute" | ||||
columns, result = webnotes.get_method(method_name)(filters or {}) | columns, result = webnotes.get_method(method_name)(filters or {}) | ||||
if cint(report.add_total_row): | |||||
result = add_total_row(result, columns) | |||||
return { | return { | ||||
"result": result, | "result": result, | ||||
"columns": columns | "columns": columns | ||||
} | |||||
} | |||||
def add_total_row(result, columns): | |||||
total_row = [""]*len(columns) | |||||
for row in result: | |||||
for i, col in enumerate(columns): | |||||
if col.split(":")[1] in ["Currency", "Int", "Float"] and flt(row[i]): | |||||
total_row[i] = flt(total_row[i]) + flt(row[i]) | |||||
if columns[0].split(":")[1] not in ["Currency", "Int", "Float"]: | |||||
total_row[0] = "Total" | |||||
result.append(total_row) | |||||
return result |
@@ -164,6 +164,8 @@ def setup_options(): | |||||
help="clear web cache") | help="clear web cache") | ||||
parser.add_option("--clear_cache", default=False, action="store_true", | parser.add_option("--clear_cache", default=False, action="store_true", | ||||
help="clear cache") | help="clear cache") | ||||
parser.add_option("--clear_defaults", default=False, action="store_true", | |||||
help="clear cache of defaults") | |||||
parser.add_option("--domain", metavar="DOMAIN", | parser.add_option("--domain", metavar="DOMAIN", | ||||
help="store domain in Website Settings", nargs=1) | help="store domain in Website Settings", nargs=1) | ||||
@@ -433,6 +435,11 @@ def run(): | |||||
elif options.clear_cache: | elif options.clear_cache: | ||||
clear_cache() | clear_cache() | ||||
elif options.clear_defaults: | |||||
import webnotes.defaults | |||||
webnotes.defaults.clear_cache() | |||||
webnotes.clear_cache() | |||||
elif options.append_future_import: | elif options.append_future_import: | ||||
append_future_import() | append_future_import() | ||||