Use simple_error() from rattail, for showing some error messages

just trying to standardize a little
This commit is contained in:
Lance Edgar 2019-09-19 20:19:26 -05:00
parent a972fb7359
commit 0d2f6e060f
4 changed files with 19 additions and 15 deletions

View file

@ -44,7 +44,7 @@ from sqlalchemy import orm
from rattail.db import model, Session as RattailSession
from rattail.db.util import short_session
from rattail.threads import Thread
from rattail.util import load_object, prettify
from rattail.util import load_object, prettify, simple_error
from rattail.progress import SocketProgress
import colander
@ -1057,7 +1057,8 @@ class BatchMasterView(MasterView):
if progress:
progress.session.load()
progress.session['error'] = True
progress.session['error_msg'] = "Batch population failed: {} - {}".format(error.__class__.__name__, error)
progress.session['error_msg'] = "Batch population failed: {}".format(
simple_error(error))
progress.session.save()
return
@ -1113,7 +1114,8 @@ class BatchMasterView(MasterView):
if progress:
progress.session.load()
progress.session['error'] = True
progress.session['error_msg'] = "Data refresh failed: {} {}".format(error.__class__.__name__, error)
progress.session['error_msg'] = "Data refresh failed: {}".format(
simple_error(error))
progress.session.save()
return
@ -1262,7 +1264,7 @@ class BatchMasterView(MasterView):
}, mobile=True)
def execute_error_message(self, error):
return "Batch execution failed: {}: {}".format(type(error).__name__, error)
return "Batch execution failed: {}".format(simple_error(error))
def execute_thread(self, batch_uuid, user_uuid, progress, **kwargs):
"""

View file

@ -41,14 +41,13 @@ from sqlalchemy_utils.functions import get_primary_keys
from rattail.db import model, Session as RattailSession
from rattail.db.continuum import model_transaction_query
from rattail.core import Object
from rattail.util import prettify
from rattail.util import prettify, OrderedDict, simple_error
from rattail.time import localtime
from rattail.threads import Thread
from rattail.csvutil import UnicodeDictWriter
from rattail.files import temp_path
from rattail.excel import ExcelWriter
from rattail.gpc import GPC
from rattail.util import OrderedDict
import colander
import deform
@ -978,7 +977,8 @@ class MasterView(View):
if progress:
progress.session.load()
progress.session['error'] = True
progress.session['error_msg'] = "{}: {} {}".format(msg, error.__class__.__name__, error)
progress.session['error_msg'] = "{}: {}".format(
msg, simple_error(error))
progress.session.save()
return
@ -1835,7 +1835,8 @@ class MasterView(View):
if progress:
progress.session.load()
progress.session['error'] = True
progress.session['error_msg'] = "Bulk deletion failed: {}: {}".format(type(error).__name__, error)
progress.session['error_msg'] = "Bulk deletion failed: {}".format(
simple_error(error))
progress.session.save()
# If no error, check result flag (false means user canceled).
@ -1992,8 +1993,8 @@ class MasterView(View):
progress.session.save()
def execute_error_message(self, error):
return "Execution of {} failed: {}: {}".format(self.get_model_title(),
type(error).__name__, error)
return "Execution of {} failed: {}".format(self.get_model_title(),
simple_error(error))
def get_execute_success_url(self, obj, **kwargs):
return self.get_action_url('view', obj, **kwargs)

View file

@ -38,7 +38,7 @@ from rattail.db import model, api, Session as RattailSession
from rattail.db.util import maxlen
from rattail.gpc import GPC
from rattail.time import localtime, make_utc
from rattail.util import pretty_quantity, prettify, OrderedDict
from rattail.util import pretty_quantity, prettify, OrderedDict, simple_error
from rattail.vendors.invoices import iter_invoice_parsers, require_invoice_parser
from rattail.threads import Thread
@ -1839,8 +1839,8 @@ class ReceivingBatchView(PurchasingBatchView):
if progress:
progress.session.load()
progress.session['error'] = True
progress.session['error_msg'] = "Auto-receive failed: {}: {}".format(
type(error).__name__, error)
progress.session['error_msg'] = "Auto-receive failed: {}".format(
simple_error(error))
progress.session.save()
# if no error, check result flag (false means user canceled)

View file

@ -38,6 +38,7 @@ from rattail.files import resource_path
from rattail.time import localtime
from rattail.reporting import get_report_handler
from rattail.threads import Thread
from rattail.util import simple_error
import colander
from mako.template import Template
@ -410,8 +411,8 @@ class GenerateReport(View):
if progress:
progress.session.load()
progress.session['error'] = True
progress.session['error_msg'] = "Failed to generate report: {}: {}".format(
type(error).__name__, error)
progress.session['error_msg'] = "Failed to generate report: {}".format(
simple_error(error))
progress.session.save()
# if no error, check result flag (false means user canceled)