|
|
@@ -17,6 +17,8 @@
|
|
|
|
|
|
import json
|
|
|
import logging
|
|
|
+import math
|
|
|
+import re
|
|
|
|
|
|
from django.forms import ValidationError
|
|
|
from django.http import Http404
|
|
|
@@ -114,6 +116,15 @@ def api_error_handler(func):
|
|
|
LOG.exception('Error running %s' % func)
|
|
|
response['status'] = 1
|
|
|
response['message'] = smart_unicode(e)
|
|
|
+ if response['message'].index("max_row_size"):
|
|
|
+ size = re.search(r"(\d+.?\d*) (.B)", response['message'])
|
|
|
+ if size and size.group(1):
|
|
|
+ response['help'] = {
|
|
|
+ 'setting': {
|
|
|
+ 'name': 'max_row_size',
|
|
|
+ 'value':str(int(_closest_power_of_2(_to_size_in_bytes(size.group(1), size.group(2)))))
|
|
|
+ }
|
|
|
+ }
|
|
|
if e.handle:
|
|
|
response['handle'] = e.handle
|
|
|
if e.extra:
|
|
|
@@ -135,6 +146,22 @@ def api_error_handler(func):
|
|
|
|
|
|
return decorator
|
|
|
|
|
|
+def _closest_power_of_2(number):
|
|
|
+ return math.pow(2, math.ceil(math.log(number, 2)))
|
|
|
+
|
|
|
+def _to_size_in_bytes(size, unit):
|
|
|
+ unit_size = 1
|
|
|
+ unit = unit.upper()
|
|
|
+ if unit[0] == 'K':
|
|
|
+ unit_size = unit_size * 1024
|
|
|
+ elif unit[0] == 'M':
|
|
|
+ unit_size = unit_size * 1024 * 1024
|
|
|
+ elif unit[0] == 'G':
|
|
|
+ unit_size = unit_size * 1024 * 1024 * 1024
|
|
|
+ elif unit[0] == 'T':
|
|
|
+ unit_size = unit_size * 1024 * 1024 * 1024 * 1024
|
|
|
+
|
|
|
+ return float(size) * unit_size
|
|
|
|
|
|
def json_error_handler(view_fn):
|
|
|
def decorator(*args, **kwargs):
|