diff --git a/tailbone/templates/grids/buefy.mako b/tailbone/templates/grids/buefy.mako index a3e6e229..cbe33062 100644 --- a/tailbone/templates/grids/buefy.mako +++ b/tailbone/templates/grids/buefy.mako @@ -584,16 +584,28 @@ this.loading = true this.$http.get(`${'$'}{this.ajaxDataUrl}?${'$'}{params}`).then(({ data }) => { - ${grid.component_studly}CurrentData = data.data - this.data = ${grid.component_studly}CurrentData - this.rowStatusMap = data.row_status_map - this.total = data.total_items - this.firstItem = data.first_item - this.lastItem = data.last_item - this.loading = false - this.checkedRows = this.locateCheckedRows(data.checked_rows) - if (success) { - success() + if (!data.error) { + ${grid.component_studly}CurrentData = data.data + this.data = ${grid.component_studly}CurrentData + this.rowStatusMap = data.row_status_map + this.total = data.total_items + this.firstItem = data.first_item + this.lastItem = data.last_item + this.loading = false + this.checkedRows = this.locateCheckedRows(data.checked_rows) + if (success) { + success() + } + } else { + this.$buefy.toast.open({ + message: data.error, + type: 'is-danger', + duration: 2000, // 4 seconds + }) + this.loading = false + if (failure) { + failure() + } } }) .catch((error) => { diff --git a/tailbone/views/master.py b/tailbone/views/master.py index cc2adcaf..c9d6cd7c 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2023 Lance Edgar +# Copyright © 2010-2024 Lance Edgar # # This file is part of Rattail. # @@ -42,8 +42,7 @@ from sqlalchemy_utils.functions import get_primary_keys, get_columns from rattail.db import model, Session as RattailSession from rattail.db.continuum import model_transaction_query -from rattail.util import prettify, simple_error, get_class_hierarchy -from rattail.time import localtime +from rattail.util import simple_error, get_class_hierarchy from rattail.threads import Thread from rattail.csvutil import UnicodeDictWriter from rattail.files import temp_path @@ -324,6 +323,13 @@ class MasterView(View): string, then the view will return the rendered grid only. Otherwise returns the full page. """ + # nb. normally this "save defaults" flag is checked within make_grid() + # but it returns JSON data so we can't just do a redirect when there + # is no user; must return JSON error message instead + if (self.request.GET.get('save-current-filters-as-defaults') == 'true' + and not self.request.user): + return self.json_response({'error': "User is not currently logged in"}) + self.listing = True grid = self.make_grid() @@ -1465,6 +1471,7 @@ class MasterView(View): """ View showing diff details of a particular object version. """ + app = self.get_rattail_app() instance = self.get_instance() model_class = self.get_model_class() route_prefix = self.get_route_prefix() @@ -1512,7 +1519,7 @@ class MasterView(View): 'instance_title_normal': instance_title, 'instance_url': self.get_action_url('versions', instance), 'transaction': transaction, - 'changed': localtime(self.rattail_config, transaction.issued_at, from_utc=True), + 'changed': app.localtime(transaction.issued_at, from_utc=True), 'version_diffs': version_diffs, 'show_prev_next': True, 'prev_url': prev_url, @@ -3502,14 +3509,14 @@ class MasterView(View): Normalize the given object into a data dict, for use when writing to the results file for download. """ + app = self.get_rattail_app() data = {} for field in fields: value = getattr(obj, field, None) # make timestamps zone-aware if isinstance(value, datetime.datetime): - value = localtime(self.rattail_config, value, - from_utc=not self.has_local_times) + value = app.localtime(value, from_utc=not self.has_local_times) data[field] = value @@ -3539,13 +3546,14 @@ class MasterView(View): Coerce the given data dict record, to a "row" dict suitable for use when writing directly to XLSX file. """ + app = self.get_rattail_app() data = dict(data) for key in data: value = data[key] # make timestamps local, "zone-naive" if isinstance(value, datetime.datetime): - value = localtime(self.rattail_config, value, tzinfo=False) + value = app.localtime(value, tzinfo=False) data[key] = value @@ -4001,14 +4009,14 @@ class MasterView(View): Normalize the given row object into a data dict, for use when writing to the results file for download. """ + app = self.get_rattail_app() data = {} for field in fields: value = getattr(row, field, None) # make timestamps zone-aware if isinstance(value, datetime.datetime): - value = localtime(self.rattail_config, value, - from_utc=not self.has_local_times) + value = app.localtime(value, from_utc=not self.has_local_times) data[field] = value @@ -4038,6 +4046,7 @@ class MasterView(View): Coerce the given data dict record, to a "row" dict suitable for use when writing directly to XLSX file. """ + app = self.get_rattail_app() data = dict(data) for key in data: value = data[key] @@ -4048,7 +4057,7 @@ class MasterView(View): # make timestamps local, "zone-naive" elif isinstance(value, datetime.datetime): - value = localtime(self.rattail_config, value, tzinfo=False) + value = app.localtime(value, tzinfo=False) data[key] = value @@ -4099,6 +4108,7 @@ class MasterView(View): """ Return a dict for use when writing the row's data to XLSX download. """ + app = self.get_rattail_app() xlrow = {} for field in fields: value = getattr(row, field, None) @@ -4111,9 +4121,9 @@ class MasterView(View): # but we should make sure they're in "local" time zone effectively. # note however, this assumes a "naive" time value is in UTC zone! if value.tzinfo: - value = localtime(self.rattail_config, value, tzinfo=False) + value = app.localtime(value, tzinfo=False) else: - value = localtime(self.rattail_config, value, from_utc=True, tzinfo=False) + value = app.localtime(value, from_utc=True, tzinfo=False) xlrow[field] = value return xlrow @@ -4177,12 +4187,13 @@ class MasterView(View): """ Return a dict for use when writing the row's data to CSV download. """ + app = self.get_rattail_app() csvrow = {} for field in fields: value = getattr(obj, field, None) if isinstance(value, datetime.datetime): # TODO: this assumes value is *always* naive UTC - value = localtime(self.rattail_config, value, from_utc=True) + value = app.localtime(value, from_utc=True) csvrow[field] = '' if value is None else str(value) return csvrow @@ -4190,12 +4201,13 @@ class MasterView(View): """ Return a dict for use when writing the row's data to CSV download. """ + app = self.get_rattail_app() csvrow = {} for field in fields: value = getattr(row, field, None) if isinstance(value, datetime.datetime): # TODO: this assumes value is *always* naive UTC - value = localtime(self.rattail_config, value, from_utc=True) + value = app.localtime(value, from_utc=True) csvrow[field] = '' if value is None else str(value) return csvrow