From 4902fab18779dea93a50088baac2b01ef6e9cf28 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 4 Dec 2017 22:40:10 -0600 Subject: [PATCH] Refactor views to use `Grid.set_sort_defaults()` method --- tailbone/views/batch/core2.py | 5 ++--- tailbone/views/bouncer.py | 3 +-- tailbone/views/brands.py | 2 +- tailbone/views/categories.py | 2 +- tailbone/views/customergroups.py | 2 +- tailbone/views/customers.py | 2 +- tailbone/views/custorders/items.py | 3 +-- tailbone/views/custorders/orders.py | 3 +-- tailbone/views/datasync.py | 2 +- tailbone/views/departments.py | 2 +- tailbone/views/depositlinks.py | 2 +- tailbone/views/email.py | 2 +- tailbone/views/employees.py | 2 +- tailbone/views/exports.py | 3 +-- tailbone/views/families.py | 2 +- tailbone/views/labels/profiles.py | 2 +- tailbone/views/master2.py | 3 +-- tailbone/views/messages.py | 3 +-- tailbone/views/people.py | 2 +- tailbone/views/products.py | 2 +- tailbone/views/purchases/core.py | 5 ++--- tailbone/views/purchases/credits.py | 3 +-- tailbone/views/reportcodes.py | 2 +- tailbone/views/roles.py | 2 +- tailbone/views/settings.py | 2 +- tailbone/views/shifts/core.py | 6 ++---- tailbone/views/stores.py | 2 +- tailbone/views/subdepartments.py | 2 +- tailbone/views/tables.py | 2 +- tailbone/views/taxes.py | 2 +- tailbone/views/tempmon/clients.py | 2 +- tailbone/views/tempmon/probes.py | 2 +- tailbone/views/tempmon/readings.py | 4 +--- tailbone/views/trainwreck.py | 5 ++--- tailbone/views/upgrades.py | 3 +-- tailbone/views/users.py | 8 +++----- 36 files changed, 42 insertions(+), 59 deletions(-) diff --git a/tailbone/views/batch/core2.py b/tailbone/views/batch/core2.py index 48b7d69f..17669b92 100644 --- a/tailbone/views/batch/core2.py +++ b/tailbone/views/batch/core2.py @@ -70,8 +70,7 @@ class BatchMasterView2(MasterView2, BatchMasterView): g.sorters['created_by'] = g.make_sorter(model.User.username) g.sorters['executed_by'] = g.make_sorter(model.User.username) - g.default_sortkey = 'id' - g.default_sortdir = 'desc' + g.set_sort_defaults('id', 'desc') g.set_enum('status_code', self.model_class.STATUS) @@ -99,7 +98,7 @@ class BatchMasterView2(MasterView2, BatchMasterView): g.filters['status_code'].set_value_renderer(grids.filters.EnumValueRenderer(self.model_row_class.STATUS)) - g.default_sortkey = 'sequence' + g.set_sort_defaults('sequence') g.set_enum('status_code', self.model_row_class.STATUS) diff --git a/tailbone/views/bouncer.py b/tailbone/views/bouncer.py index bcbd7131..343d6da0 100644 --- a/tailbone/views/bouncer.py +++ b/tailbone/views/bouncer.py @@ -83,8 +83,7 @@ class EmailBouncesView(MasterView): g.filters['processed'].default_verb = 'is_null' g.filters['processed_by'] = g.make_filter('processed_by', model.User.username) g.sorters['processed_by'] = g.make_sorter(model.User.username) - g.default_sortkey = 'bounced' - g.default_sortdir = 'desc' + g.set_sort_defaults('bounced', 'desc') g.set_label('config_key', "Source") g.set_label('bounce_recipient_address', "Bounced To") diff --git a/tailbone/views/brands.py b/tailbone/views/brands.py index dac064b2..46965cb1 100644 --- a/tailbone/views/brands.py +++ b/tailbone/views/brands.py @@ -50,7 +50,7 @@ class BrandsView(MasterView): super(BrandsView, self).configure_grid(g) g.filters['name'].default_active = True g.filters['name'].default_verb = 'contains' - g.default_sortkey = 'name' + g.set_sort_defaults('name') g.set_link('name') diff --git a/tailbone/views/categories.py b/tailbone/views/categories.py index 7586d6cc..c2a46a77 100644 --- a/tailbone/views/categories.py +++ b/tailbone/views/categories.py @@ -58,7 +58,7 @@ class CategoriesView(MasterView): super(CategoriesView, self).configure_grid(g) g.filters['name'].default_active = True g.filters['name'].default_verb = 'contains' - g.default_sortkey = 'code' + g.set_sort_defaults('code') g.set_link('code') g.set_link('number') g.set_link('name') diff --git a/tailbone/views/customergroups.py b/tailbone/views/customergroups.py index faadb856..74ba59c2 100644 --- a/tailbone/views/customergroups.py +++ b/tailbone/views/customergroups.py @@ -57,7 +57,7 @@ class CustomerGroupsView(MasterView): super(CustomerGroupsView, self).configure_grid(g) g.filters['name'].default_active = True g.filters['name'].default_verb = 'contains' - g.default_sortkey = 'name' + g.set_sort_defaults('name') g.set_link('id') g.set_link('name') diff --git a/tailbone/views/customers.py b/tailbone/views/customers.py index 1ac1a2ad..8135c52c 100644 --- a/tailbone/views/customers.py +++ b/tailbone/views/customers.py @@ -104,7 +104,7 @@ class CustomersView(MasterView): g.sorters['email'] = lambda q, d: q.order_by(getattr(model.CustomerEmailAddress.address, d)()) g.sorters['phone'] = lambda q, d: q.order_by(getattr(model.CustomerPhoneNumber.number, d)()) - g.default_sortkey = 'name' + g.set_sort_defaults('name') g.set_label('id', "ID") g.set_label('phone', "Phone Number") diff --git a/tailbone/views/custorders/items.py b/tailbone/views/custorders/items.py index 2bf27b27..4a14da89 100644 --- a/tailbone/views/custorders/items.py +++ b/tailbone/views/custorders/items.py @@ -95,8 +95,7 @@ class CustomerOrderItemsView(MasterView): g.set_sorter('person', model.Person.display_name) g.set_sorter('order_created', model.CustomerOrder.created) - g.default_sortkey = 'order_created' - g.default_sortdir = 'desc' + g.set_sort_defaults('order_created', 'desc') g.set_type('case_quantity', 'quantity') g.set_type('cases_ordered', 'quantity') diff --git a/tailbone/views/custorders/orders.py b/tailbone/views/custorders/orders.py index cc57c7b2..c10333eb 100644 --- a/tailbone/views/custorders/orders.py +++ b/tailbone/views/custorders/orders.py @@ -75,8 +75,7 @@ class CustomerOrdersView(MasterView): g.set_sorter('customer', model.Customer.name) g.set_sorter('person', model.Person.display_name) - g.default_sortkey = 'created' - g.default_sortdir = 'desc' + g.set_sort_defaults('created', 'desc') # TODO: enum choices renderer g.set_label('status_code', "Status") diff --git a/tailbone/views/datasync.py b/tailbone/views/datasync.py index 1d117fbd..0b568f01 100644 --- a/tailbone/views/datasync.py +++ b/tailbone/views/datasync.py @@ -60,7 +60,7 @@ class DataSyncChangesView(MasterView): def configure_grid(self, g): super(DataSyncChangesView, self).configure_grid(g) - g.default_sortkey = 'obtained' + g.set_sort_defaults('obtained') g.set_type('obtained', 'datetime') def restart(self): diff --git a/tailbone/views/departments.py b/tailbone/views/departments.py index 200ebc00..4fa33edd 100644 --- a/tailbone/views/departments.py +++ b/tailbone/views/departments.py @@ -54,7 +54,7 @@ class DepartmentsView(MasterView): super(DepartmentsView, self).configure_grid(g) g.filters['name'].default_active = True g.filters['name'].default_verb = 'contains' - g.default_sortkey = 'number' + g.set_sort_defaults('number') g.set_type('product', 'boolean') g.set_type('personnel', 'boolean') g.set_link('number') diff --git a/tailbone/views/depositlinks.py b/tailbone/views/depositlinks.py index 6fa7acd5..b7f5876d 100644 --- a/tailbone/views/depositlinks.py +++ b/tailbone/views/depositlinks.py @@ -50,7 +50,7 @@ class DepositLinksView(MasterView): super(DepositLinksView, self).configure_grid(g) g.filters['description'].default_active = True g.filters['description'].default_verb = 'contains' - g.default_sortkey = 'code' + g.set_sort_defaults('code') g.set_type('amount', 'currency') g.set_link('code') g.set_link('description') diff --git a/tailbone/views/email.py b/tailbone/views/email.py index 3aa1b014..35490d5b 100644 --- a/tailbone/views/email.py +++ b/tailbone/views/email.py @@ -83,7 +83,7 @@ class ProfilesView(MasterView): g.sorters['subject'] = g.make_simple_sorter('subject', foldcase=True) g.sorters['to'] = g.make_simple_sorter('to', foldcase=True) g.sorters['enabled'] = g.make_simple_sorter('enabled') - g.default_sortkey = 'key' + g.set_sort_defaults('key') g.set_type('enabled', 'boolean') g.set_renderer('to', self.render_to) g.set_link('key') diff --git a/tailbone/views/employees.py b/tailbone/views/employees.py index 50c7c030..dd6626d9 100644 --- a/tailbone/views/employees.py +++ b/tailbone/views/employees.py @@ -110,7 +110,7 @@ class EmployeesView(MasterView): g.sorters['email'] = lambda q, d: q.order_by(getattr(model.EmployeeEmailAddress.address, d)()) g.sorters['phone'] = lambda q, d: q.order_by(getattr(model.EmployeePhoneNumber.number, d)()) - g.default_sortkey = 'first_name' + g.set_sort_defaults('first_name') g.set_enum('status', self.enum.EMPLOYEE_STATUS) diff --git a/tailbone/views/exports.py b/tailbone/views/exports.py index 4d121a0b..1e044b97 100644 --- a/tailbone/views/exports.py +++ b/tailbone/views/exports.py @@ -69,8 +69,7 @@ class ExportMasterView(MasterView): g.joiners['created_by'] = lambda q: q.join(model.User) g.sorters['created_by'] = g.make_sorter(model.User.username) g.filters['created_by'] = g.make_filter('created_by', model.User.username) - g.default_sortkey = 'created' - g.default_sortdir = 'desc' + g.set_sort_defaults('created', 'desc') g.set_renderer('id', self.render_id) diff --git a/tailbone/views/families.py b/tailbone/views/families.py index 97ce44bc..b9babf66 100644 --- a/tailbone/views/families.py +++ b/tailbone/views/families.py @@ -49,7 +49,7 @@ class FamiliesView(MasterView): def configure_grid(self, g): g.filters['name'].default_active = True g.filters['name'].default_verb = 'contains' - g.default_sortkey = 'code' + g.set_sort_defaults('code') def configure_fieldset(self, fs): fs.configure( diff --git a/tailbone/views/labels/profiles.py b/tailbone/views/labels/profiles.py index 3c06d8c8..de2eaac7 100644 --- a/tailbone/views/labels/profiles.py +++ b/tailbone/views/labels/profiles.py @@ -53,7 +53,7 @@ class ProfilesView(MasterView): def configure_grid(self, g): super(ProfilesView, self).configure_grid(g) - g.default_sortkey = 'ordinal' + g.set_sort_defaults('ordinal') g.set_type('visible', 'boolean') g.set_link('code') g.set_link('description') diff --git a/tailbone/views/master2.py b/tailbone/views/master2.py index e9f8d108..1efa0e38 100644 --- a/tailbone/views/master2.py +++ b/tailbone/views/master2.py @@ -404,8 +404,7 @@ class MasterView2(MasterView): pass def configure_version_grid(self, g): - g.default_sortkey = 'issued_at' - g.default_sortdir = 'desc' + g.set_sort_defaults('issued_at', 'desc') g.set_renderer('comment', self.render_version_comment) g.set_label('issued_at', "Changed") g.set_label('user', "Changed by") diff --git a/tailbone/views/messages.py b/tailbone/views/messages.py index 3e313e81..8b978ad2 100644 --- a/tailbone/views/messages.py +++ b/tailbone/views/messages.py @@ -119,8 +119,7 @@ class MessagesView(MasterView): g.filters['subject'].default_active = True g.filters['subject'].default_verb = 'contains' - g.default_sortkey = 'sent' - g.default_sortdir = 'desc' + g.set_sort_defaults('sent', 'desc') g.set_renderer('sent', self.render_sent) g.set_renderer('sender', self.render_sender) diff --git a/tailbone/views/people.py b/tailbone/views/people.py index c88d48b5..65b9a8e8 100644 --- a/tailbone/views/people.py +++ b/tailbone/views/people.py @@ -92,7 +92,7 @@ class PeopleView(MasterView): g.sorters['email'] = lambda q, d: q.order_by(getattr(model.PersonEmailAddress.address, d)()) g.sorters['phone'] = lambda q, d: q.order_by(getattr(model.PersonPhoneNumber.number, d)()) - g.default_sortkey = 'display_name' + g.set_sort_defaults('display_name') g.set_label('display_name', "Full Name") g.set_label('phone', "Phone Number") diff --git a/tailbone/views/products.py b/tailbone/views/products.py index 050ee708..6f5619f8 100644 --- a/tailbone/views/products.py +++ b/tailbone/views/products.py @@ -220,7 +220,7 @@ class ProductsView(MasterView): g.set_sorter('current_price', self.CurrentPrice.price) g.set_filter('current_price', self.CurrentPrice.price, label="Current Price") - g.default_sortkey = 'upc' + g.set_sort_defaults('upc') if self.print_labels and self.request.has_perm('products.print_labels'): g.more_actions.append(grids.GridAction('print_label', icon='print')) diff --git a/tailbone/views/purchases/core.py b/tailbone/views/purchases/core.py index 4f3337d8..409b659d 100644 --- a/tailbone/views/purchases/core.py +++ b/tailbone/views/purchases/core.py @@ -146,8 +146,7 @@ class PurchaseView(MasterView): g.filters['date_ordered'].default_active = True g.filters['date_ordered'].default_verb = 'equal' - g.default_sortkey = 'date_ordered' - g.default_sortdir = 'desc' + g.set_sort_defaults('date_ordered', 'desc') g.set_enum('status', self.enum.PURCHASE_STATUS) @@ -212,7 +211,7 @@ class PurchaseView(MasterView): def configure_row_grid(self, g): super(PurchaseView, self).configure_row_grid(g) - g.default_sortkey = 'sequence' + g.set_sort_defaults('sequence') g.set_type('cases_ordered', 'quantity') g.set_type('units_ordered', 'quantity') diff --git a/tailbone/views/purchases/credits.py b/tailbone/views/purchases/credits.py index 3056dcb6..464e194b 100644 --- a/tailbone/views/purchases/credits.py +++ b/tailbone/views/purchases/credits.py @@ -67,8 +67,7 @@ class PurchaseCreditView(MasterView): g.set_joiner('vendor', lambda q: q.outerjoin(model.Vendor)) g.set_sorter('vendor', model.Vendor.name) - g.default_sortkey = 'date_received' - g.default_sortdir = 'desc' + g.set_sort_defaults('date_received', 'desc') g.filters['status'].set_value_renderer(grids.filters.EnumValueRenderer(self.enum.PURCHASE_CREDIT_STATUS)) g.filters['status'].default_active = True diff --git a/tailbone/views/reportcodes.py b/tailbone/views/reportcodes.py index 59646cfc..bb3b03ec 100644 --- a/tailbone/views/reportcodes.py +++ b/tailbone/views/reportcodes.py @@ -48,7 +48,7 @@ class ReportCodesView(MasterView): super(ReportCodesView, self).configure_grid(g) g.filters['name'].default_active = True g.filters['name'].default_verb = 'contains' - g.default_sortkey = 'code' + g.set_sort_defaults('code') g.set_link('code') g.set_link('name') diff --git a/tailbone/views/roles.py b/tailbone/views/roles.py index c5e55765..4c79fd37 100644 --- a/tailbone/views/roles.py +++ b/tailbone/views/roles.py @@ -55,7 +55,7 @@ class RolesView(PrincipalMasterView): super(RolesView, self).configure_grid(g) g.filters['name'].default_active = True g.filters['name'].default_verb = 'contains' - g.default_sortkey = 'name' + g.set_sort_defaults('name') g.set_link('name') def _preconfigure_fieldset(self, fs): diff --git a/tailbone/views/settings.py b/tailbone/views/settings.py index b15cac87..7c1b021c 100644 --- a/tailbone/views/settings.py +++ b/tailbone/views/settings.py @@ -51,7 +51,7 @@ class SettingsView(MasterView): super(SettingsView, self).configure_grid(g) g.filters['name'].default_active = True g.filters['name'].default_verb = 'contains' - g.default_sortkey = 'name' + g.set_sort_defaults('name') g.set_link('name') def configure_form(self, f): diff --git a/tailbone/views/shifts/core.py b/tailbone/views/shifts/core.py index 46dc9906..10d9f3e3 100644 --- a/tailbone/views/shifts/core.py +++ b/tailbone/views/shifts/core.py @@ -72,8 +72,7 @@ class ScheduledShiftsView(MasterView): g.filters['employee'] = g.make_filter('employee', model.Person.display_name, default_active=True, default_verb='contains') - g.default_sortkey = 'start_time' - g.default_sortdir = 'desc' + g.set_sort_defaults('start_time', 'desc') g.set_renderer('length', render_shift_length) @@ -123,8 +122,7 @@ class WorkedShiftsView(MasterView): # TODO: these sorters should be automatic once we fix the schema g.sorters['start_time'] = g.make_sorter(model.WorkedShift.punch_in) g.sorters['end_time'] = g.make_sorter(model.WorkedShift.punch_out) - g.default_sortkey = 'start_time' - g.default_sortdir = 'desc' + g.set_sort_defaults('start_time', 'desc') g.set_renderer('length', render_shift_length) diff --git a/tailbone/views/stores.py b/tailbone/views/stores.py index 143aa467..bf8f2a6e 100644 --- a/tailbone/views/stores.py +++ b/tailbone/views/stores.py @@ -72,7 +72,7 @@ class StoresView(MasterView): g.set_sorter('phone', model.StorePhoneNumber.number) g.set_sorter('email', model.StoreEmailAddress.address) - g.default_sortkey = 'id' + g.set_sort_defaults('id') g.set_link('id') g.set_link('name') diff --git a/tailbone/views/subdepartments.py b/tailbone/views/subdepartments.py index c6bf449c..36ae1b53 100644 --- a/tailbone/views/subdepartments.py +++ b/tailbone/views/subdepartments.py @@ -60,7 +60,7 @@ class SubdepartmentsView(MasterView): super(SubdepartmentsView, self).configure_grid(g) g.filters['name'].default_active = True g.filters['name'].default_verb = 'contains' - g.default_sortkey = 'name' + g.set_sort_defaults('name') g.set_link('number') g.set_link('name') diff --git a/tailbone/views/tables.py b/tailbone/views/tables.py index f1e75eb0..b94d590f 100644 --- a/tailbone/views/tables.py +++ b/tailbone/views/tables.py @@ -63,7 +63,7 @@ class TablesView(MasterView): def configure_grid(self, g): g.sorters['name'] = g.make_simple_sorter('name', foldcase=True) g.sorters['row_count'] = g.make_simple_sorter('row_count') - g.default_sortkey = 'name' + g.set_sort_defaults('name') def includeme(config): diff --git a/tailbone/views/taxes.py b/tailbone/views/taxes.py index 75485342..ef2efd75 100644 --- a/tailbone/views/taxes.py +++ b/tailbone/views/taxes.py @@ -50,7 +50,7 @@ class TaxesView(MasterView): super(TaxesView, self).configure_grid(g) g.filters['description'].default_active = True g.filters['description'].default_verb = 'contains' - g.default_sortkey = 'code' + g.set_sort_defaults('code') g.set_link('code') g.set_link('description') diff --git a/tailbone/views/tempmon/clients.py b/tailbone/views/tempmon/clients.py index 2144cf14..d1b9db65 100644 --- a/tailbone/views/tempmon/clients.py +++ b/tailbone/views/tempmon/clients.py @@ -84,7 +84,7 @@ class TempmonClientView(MasterView): g.filters['hostname'].default_verb = 'contains' g.filters['location'].default_active = True g.filters['location'].default_verb = 'contains' - g.default_sortkey = 'config_key' + g.set_sort_defaults('config_key') g.set_type('enabled', 'boolean') g.set_type('online', 'boolean') diff --git a/tailbone/views/tempmon/probes.py b/tailbone/views/tempmon/probes.py index 4add1ca2..b55e9e65 100644 --- a/tailbone/views/tempmon/probes.py +++ b/tailbone/views/tempmon/probes.py @@ -70,7 +70,7 @@ class TempmonProbeView(MasterView): g.joiners['client'] = lambda q: q.join(tempmon.Client) g.sorters['client'] = g.make_sorter(tempmon.Client.config_key) - g.default_sortkey = 'client' + g.set_sort_defaults('client') g.set_enum('appliance_type', self.enum.TEMPMON_APPLIANCE_TYPE) g.set_enum('status', self.enum.TEMPMON_PROBE_STATUS) diff --git a/tailbone/views/tempmon/readings.py b/tailbone/views/tempmon/readings.py index 5181c41e..4e4dc5b8 100644 --- a/tailbone/views/tempmon/readings.py +++ b/tailbone/views/tempmon/readings.py @@ -74,9 +74,7 @@ class TempmonReadingView(MasterView): g.sorters['probe'] = g.make_sorter(tempmon.Probe.description) g.filters['probe'] = g.make_filter('probe', tempmon.Probe.description) - g.default_sortkey = 'taken' - g.default_sortdir = 'desc' - + g.set_sort_defaults('taken', 'desc') g.set_type('taken', 'datetime') g.set_renderer('client_key', self.render_client_key) diff --git a/tailbone/views/trainwreck.py b/tailbone/views/trainwreck.py index aa64c115..5d314106 100644 --- a/tailbone/views/trainwreck.py +++ b/tailbone/views/trainwreck.py @@ -84,8 +84,7 @@ class TransactionView(MasterView): g.filters['start_time'].default_active = True g.filters['start_time'].default_verb = 'equal' g.filters['start_time'].default_value = six.text_type(localtime(self.rattail_config).date()) - g.default_sortkey = 'start_time' - g.default_sortdir = 'desc' + g.set_sort_defaults('start_time', 'desc') g.set_enum('system', self.enum.TRAINWRECK_SYSTEM) g.set_type('total', 'currency') @@ -143,7 +142,7 @@ class TransactionView(MasterView): def configure_row_grid(self, g): super(TransactionView, self).configure_row_grid(g) - g.default_sortkey = 'sequence' + g.set_sort_defaults('sequence') g.set_type('unit_quantity', 'quantity') g.set_type('subtotal', 'currency') diff --git a/tailbone/views/upgrades.py b/tailbone/views/upgrades.py index 6005c14f..8b9cd265 100644 --- a/tailbone/views/upgrades.py +++ b/tailbone/views/upgrades.py @@ -119,8 +119,7 @@ class UpgradeView(MasterView): g.set_enum('status_code', self.enum.UPGRADE_STATUS) g.set_type('created', 'datetime') g.set_type('executed', 'datetime') - g.default_sortkey = 'created' - g.default_sortdir = 'desc' + g.set_sort_defaults('created', 'desc') g.set_link('created') g.set_link('description') # g.set_link('not_until') diff --git a/tailbone/views/users.py b/tailbone/views/users.py index 7fb598b8..4990eb3d 100644 --- a/tailbone/views/users.py +++ b/tailbone/views/users.py @@ -181,7 +181,7 @@ class UsersView(PrincipalMasterView): g.set_sorter('first_name', model.Person.first_name) g.set_sorter('last_name', model.Person.last_name) g.set_sorter('display_name', model.Person.display_name) - g.default_sortkey = 'username' + g.set_sort_defaults('username') g.set_label('person', "Person's Name") @@ -249,8 +249,7 @@ class UsersView(PrincipalMasterView): super(UsersView, self).configure_row_grid(g) g.width = 'half' g.filterable = False - g.default_sortkey = 'occurred' - g.default_sortdir = 'desc' + g.set_sort_defaults('occurred', 'desc') g.set_enum('type_code', self.enum.USER_EVENT) g.set_label('type_code', "Event Type") g.main_actions = [] @@ -333,8 +332,7 @@ class UserEventsView(MasterView): g.set_type('occurred', 'datetime') g.set_renderer('user', self.render_user) g.set_renderer('person', self.render_person) - g.default_sortkey = 'occurred' - g.default_sortdir = 'desc' + g.set_sort_defaults('occurred', 'desc') g.set_label('user', "Username") g.set_label('type_code', "Event Type")