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 import model, Session as RattailSession
from rattail.db.util import short_session from rattail.db.util import short_session
from rattail.threads import Thread 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 from rattail.progress import SocketProgress
import colander import colander
@ -1057,7 +1057,8 @@ class BatchMasterView(MasterView):
if progress: if progress:
progress.session.load() progress.session.load()
progress.session['error'] = True 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() progress.session.save()
return return
@ -1113,7 +1114,8 @@ class BatchMasterView(MasterView):
if progress: if progress:
progress.session.load() progress.session.load()
progress.session['error'] = True 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() progress.session.save()
return return
@ -1262,7 +1264,7 @@ class BatchMasterView(MasterView):
}, mobile=True) }, mobile=True)
def execute_error_message(self, error): 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): 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 import model, Session as RattailSession
from rattail.db.continuum import model_transaction_query from rattail.db.continuum import model_transaction_query
from rattail.core import Object 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.time import localtime
from rattail.threads import Thread from rattail.threads import Thread
from rattail.csvutil import UnicodeDictWriter from rattail.csvutil import UnicodeDictWriter
from rattail.files import temp_path from rattail.files import temp_path
from rattail.excel import ExcelWriter from rattail.excel import ExcelWriter
from rattail.gpc import GPC from rattail.gpc import GPC
from rattail.util import OrderedDict
import colander import colander
import deform import deform
@ -978,7 +977,8 @@ class MasterView(View):
if progress: if progress:
progress.session.load() progress.session.load()
progress.session['error'] = True 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() progress.session.save()
return return
@ -1835,7 +1835,8 @@ class MasterView(View):
if progress: if progress:
progress.session.load() progress.session.load()
progress.session['error'] = True 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() progress.session.save()
# If no error, check result flag (false means user canceled). # If no error, check result flag (false means user canceled).
@ -1992,8 +1993,8 @@ class MasterView(View):
progress.session.save() progress.session.save()
def execute_error_message(self, error): def execute_error_message(self, error):
return "Execution of {} failed: {}: {}".format(self.get_model_title(), return "Execution of {} failed: {}".format(self.get_model_title(),
type(error).__name__, error) simple_error(error))
def get_execute_success_url(self, obj, **kwargs): def get_execute_success_url(self, obj, **kwargs):
return self.get_action_url('view', 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.db.util import maxlen
from rattail.gpc import GPC from rattail.gpc import GPC
from rattail.time import localtime, make_utc 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.vendors.invoices import iter_invoice_parsers, require_invoice_parser
from rattail.threads import Thread from rattail.threads import Thread
@ -1839,8 +1839,8 @@ class ReceivingBatchView(PurchasingBatchView):
if progress: if progress:
progress.session.load() progress.session.load()
progress.session['error'] = True progress.session['error'] = True
progress.session['error_msg'] = "Auto-receive failed: {}: {}".format( progress.session['error_msg'] = "Auto-receive failed: {}".format(
type(error).__name__, error) simple_error(error))
progress.session.save() progress.session.save()
# if no error, check result flag (false means user canceled) # 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.time import localtime
from rattail.reporting import get_report_handler from rattail.reporting import get_report_handler
from rattail.threads import Thread from rattail.threads import Thread
from rattail.util import simple_error
import colander import colander
from mako.template import Template from mako.template import Template
@ -410,8 +411,8 @@ class GenerateReport(View):
if progress: if progress:
progress.session.load() progress.session.load()
progress.session['error'] = True progress.session['error'] = True
progress.session['error_msg'] = "Failed to generate report: {}: {}".format( progress.session['error_msg'] = "Failed to generate report: {}".format(
type(error).__name__, error) simple_error(error))
progress.session.save() progress.session.save()
# if no error, check result flag (false means user canceled) # if no error, check result flag (false means user canceled)