Merge remote-tracking branch 'frappe/develop' into v5.0

Conflicts:
	frappe/__version__.py
	frappe/hooks.py
	frappe/translations/ar.csv
	frappe/translations/bs.csv
	frappe/translations/ca.csv
	frappe/translations/de.csv
	frappe/translations/el.csv
	frappe/translations/es.csv
	frappe/translations/fr.csv
	frappe/translations/hi.csv
	frappe/translations/hr.csv
	frappe/translations/it.csv
	frappe/translations/ja.csv
	frappe/translations/kn.csv
	frappe/translations/nl.csv
	frappe/translations/pt-BR.csv
	frappe/translations/pt.csv
	frappe/translations/ru.csv
	frappe/translations/sr.csv
	frappe/translations/ta.csv
	frappe/translations/th.csv
	frappe/translations/vi.csv
	frappe/translations/zh-cn.csv
	frappe/translations/zh-tw.csv
	requirements.txt
	setup.py
This commit is contained in:
Anand Doshi 2015-03-06 17:41:22 +05:30
commit f70f409a64
6 changed files with 21 additions and 4 deletions

View file

@ -5,6 +5,7 @@ from __future__ import unicode_literals
import sys, os
import json
import logging
import MySQLdb
from werkzeug.wrappers import Request, Response
from werkzeug.local import LocalManager
@ -70,6 +71,14 @@ def application(request):
except Exception, e:
http_status_code = getattr(e, "http_status_code", 500)
if (http_status_code==500
and isinstance(e, MySQLdb.OperationalError)
and e.args[0] in (1205, 1213)):
# 1205 = lock wait timeout
# 1213 = deadlock
# code 409 represents conflict
http_status_code = 409
if frappe.local.is_ajax:
response = frappe.utils.response.report_error(http_status_code)
else:

View file

@ -68,6 +68,7 @@ class FormMeta(Meta):
self.set("__listview_template", get_html_format(listview_template))
self.add_code_via_hook("doctype_js", "__js")
self.add_code_via_hook("doctype_list_js", "__list_js")
self.add_custom_script()
def _add_code(self, path, fieldname):

View file

@ -84,7 +84,9 @@ def rename_parent_and_child(doctype, old, new, meta):
update_child_docs(old, new, meta)
def validate_rename(doctype, new, meta, merge, force, ignore_permissions):
exists = frappe.db.get_value(doctype, new)
# using for update so that it gets locked and someone else cannot edit it while this rename is going on!
exists = frappe.db.sql("select name from `tab{doctype}` where name=%s for update".format(doctype=doctype), new)
exists = exists[0][0] if exists else None
if merge and not exists:
frappe.msgprint(_("{0} {1} does not exist, select a new target to merge").format(doctype, new), raise_exception=1)

View file

@ -178,7 +178,7 @@ function _round(num, precision) {
var m = Math.pow(10, d);
var n = +(d ? num * m : num).toFixed(8); // Avoid rounding errors
var i = Math.floor(n), f = n - i;
var r = (f == 0.5) ? ((i % 2 == 0) ? i : i + 1) : Math.round(n);
var r = (!precision && f == 0.5) ? ((i % 2 == 0) ? i : i + 1) : Math.round(n);
return d ? r / m : r;
}

View file

@ -68,6 +68,9 @@ frappe.request.call = function(opts) {
msgprint(__("Not permitted"));
},
409: function(xhr) {
msgprint(__("Another transaction is blocking this one. Please try again in a few seconds."));
},
417: function(data, xhr) {
if(typeof data === "string") data = JSON.parse(data);
opts.error_callback && opts.error_callback(data, xhr.responseText);

View file

@ -210,12 +210,14 @@ def flt(s, precision=None):
"""Convert to float (ignore commas)"""
if isinstance(s, basestring):
s = s.replace(',','')
try:
num = float(s)
if precision is not None:
num = rounded(num, precision)
except Exception:
num = 0
return num
def cint(s):
@ -235,7 +237,7 @@ def cstr(s):
return unicode(s)
def rounded(num, precision=0):
"""round method for round halfs to nearest even algorithm"""
"""round method for round halfs to nearest even algorithm aka banker's rounding - compatible with python3"""
precision = cint(precision)
multiplier = 10 ** precision
@ -245,7 +247,7 @@ def rounded(num, precision=0):
floor = math.floor(num)
decimal_part = num - floor
if decimal_part == 0.5:
if not precision and decimal_part == 0.5:
num = floor if (floor % 2 == 0) else floor + 1
else:
num = round(num)