Refactor views to use Grid.set_sort_defaults() method

This commit is contained in:
Lance Edgar 2017-12-04 22:40:10 -06:00
parent 7d79727c2e
commit 4902fab187
36 changed files with 42 additions and 59 deletions

View file

@ -70,8 +70,7 @@ class BatchMasterView2(MasterView2, BatchMasterView):
g.sorters['created_by'] = g.make_sorter(model.User.username) g.sorters['created_by'] = g.make_sorter(model.User.username)
g.sorters['executed_by'] = g.make_sorter(model.User.username) g.sorters['executed_by'] = g.make_sorter(model.User.username)
g.default_sortkey = 'id' g.set_sort_defaults('id', 'desc')
g.default_sortdir = 'desc'
g.set_enum('status_code', self.model_class.STATUS) 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.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) g.set_enum('status_code', self.model_row_class.STATUS)

View file

@ -83,8 +83,7 @@ class EmailBouncesView(MasterView):
g.filters['processed'].default_verb = 'is_null' g.filters['processed'].default_verb = 'is_null'
g.filters['processed_by'] = g.make_filter('processed_by', model.User.username) g.filters['processed_by'] = g.make_filter('processed_by', model.User.username)
g.sorters['processed_by'] = g.make_sorter(model.User.username) g.sorters['processed_by'] = g.make_sorter(model.User.username)
g.default_sortkey = 'bounced' g.set_sort_defaults('bounced', 'desc')
g.default_sortdir = 'desc'
g.set_label('config_key', "Source") g.set_label('config_key', "Source")
g.set_label('bounce_recipient_address', "Bounced To") g.set_label('bounce_recipient_address', "Bounced To")

View file

@ -50,7 +50,7 @@ class BrandsView(MasterView):
super(BrandsView, self).configure_grid(g) super(BrandsView, self).configure_grid(g)
g.filters['name'].default_active = True g.filters['name'].default_active = True
g.filters['name'].default_verb = 'contains' g.filters['name'].default_verb = 'contains'
g.default_sortkey = 'name' g.set_sort_defaults('name')
g.set_link('name') g.set_link('name')

View file

@ -58,7 +58,7 @@ class CategoriesView(MasterView):
super(CategoriesView, self).configure_grid(g) super(CategoriesView, self).configure_grid(g)
g.filters['name'].default_active = True g.filters['name'].default_active = True
g.filters['name'].default_verb = 'contains' g.filters['name'].default_verb = 'contains'
g.default_sortkey = 'code' g.set_sort_defaults('code')
g.set_link('code') g.set_link('code')
g.set_link('number') g.set_link('number')
g.set_link('name') g.set_link('name')

View file

@ -57,7 +57,7 @@ class CustomerGroupsView(MasterView):
super(CustomerGroupsView, self).configure_grid(g) super(CustomerGroupsView, self).configure_grid(g)
g.filters['name'].default_active = True g.filters['name'].default_active = True
g.filters['name'].default_verb = 'contains' g.filters['name'].default_verb = 'contains'
g.default_sortkey = 'name' g.set_sort_defaults('name')
g.set_link('id') g.set_link('id')
g.set_link('name') g.set_link('name')

View file

@ -104,7 +104,7 @@ class CustomersView(MasterView):
g.sorters['email'] = lambda q, d: q.order_by(getattr(model.CustomerEmailAddress.address, d)()) 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.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('id', "ID")
g.set_label('phone', "Phone Number") g.set_label('phone', "Phone Number")

View file

@ -95,8 +95,7 @@ class CustomerOrderItemsView(MasterView):
g.set_sorter('person', model.Person.display_name) g.set_sorter('person', model.Person.display_name)
g.set_sorter('order_created', model.CustomerOrder.created) g.set_sorter('order_created', model.CustomerOrder.created)
g.default_sortkey = 'order_created' g.set_sort_defaults('order_created', 'desc')
g.default_sortdir = 'desc'
g.set_type('case_quantity', 'quantity') g.set_type('case_quantity', 'quantity')
g.set_type('cases_ordered', 'quantity') g.set_type('cases_ordered', 'quantity')

View file

@ -75,8 +75,7 @@ class CustomerOrdersView(MasterView):
g.set_sorter('customer', model.Customer.name) g.set_sorter('customer', model.Customer.name)
g.set_sorter('person', model.Person.display_name) g.set_sorter('person', model.Person.display_name)
g.default_sortkey = 'created' g.set_sort_defaults('created', 'desc')
g.default_sortdir = 'desc'
# TODO: enum choices renderer # TODO: enum choices renderer
g.set_label('status_code', "Status") g.set_label('status_code', "Status")

View file

@ -60,7 +60,7 @@ class DataSyncChangesView(MasterView):
def configure_grid(self, g): def configure_grid(self, g):
super(DataSyncChangesView, self).configure_grid(g) super(DataSyncChangesView, self).configure_grid(g)
g.default_sortkey = 'obtained' g.set_sort_defaults('obtained')
g.set_type('obtained', 'datetime') g.set_type('obtained', 'datetime')
def restart(self): def restart(self):

View file

@ -54,7 +54,7 @@ class DepartmentsView(MasterView):
super(DepartmentsView, self).configure_grid(g) super(DepartmentsView, self).configure_grid(g)
g.filters['name'].default_active = True g.filters['name'].default_active = True
g.filters['name'].default_verb = 'contains' g.filters['name'].default_verb = 'contains'
g.default_sortkey = 'number' g.set_sort_defaults('number')
g.set_type('product', 'boolean') g.set_type('product', 'boolean')
g.set_type('personnel', 'boolean') g.set_type('personnel', 'boolean')
g.set_link('number') g.set_link('number')

View file

@ -50,7 +50,7 @@ class DepositLinksView(MasterView):
super(DepositLinksView, self).configure_grid(g) super(DepositLinksView, self).configure_grid(g)
g.filters['description'].default_active = True g.filters['description'].default_active = True
g.filters['description'].default_verb = 'contains' g.filters['description'].default_verb = 'contains'
g.default_sortkey = 'code' g.set_sort_defaults('code')
g.set_type('amount', 'currency') g.set_type('amount', 'currency')
g.set_link('code') g.set_link('code')
g.set_link('description') g.set_link('description')

View file

@ -83,7 +83,7 @@ class ProfilesView(MasterView):
g.sorters['subject'] = g.make_simple_sorter('subject', foldcase=True) g.sorters['subject'] = g.make_simple_sorter('subject', foldcase=True)
g.sorters['to'] = g.make_simple_sorter('to', foldcase=True) g.sorters['to'] = g.make_simple_sorter('to', foldcase=True)
g.sorters['enabled'] = g.make_simple_sorter('enabled') g.sorters['enabled'] = g.make_simple_sorter('enabled')
g.default_sortkey = 'key' g.set_sort_defaults('key')
g.set_type('enabled', 'boolean') g.set_type('enabled', 'boolean')
g.set_renderer('to', self.render_to) g.set_renderer('to', self.render_to)
g.set_link('key') g.set_link('key')

View file

@ -110,7 +110,7 @@ class EmployeesView(MasterView):
g.sorters['email'] = lambda q, d: q.order_by(getattr(model.EmployeeEmailAddress.address, d)()) 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.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) g.set_enum('status', self.enum.EMPLOYEE_STATUS)

View file

@ -69,8 +69,7 @@ class ExportMasterView(MasterView):
g.joiners['created_by'] = lambda q: q.join(model.User) g.joiners['created_by'] = lambda q: q.join(model.User)
g.sorters['created_by'] = g.make_sorter(model.User.username) g.sorters['created_by'] = g.make_sorter(model.User.username)
g.filters['created_by'] = g.make_filter('created_by', model.User.username) g.filters['created_by'] = g.make_filter('created_by', model.User.username)
g.default_sortkey = 'created' g.set_sort_defaults('created', 'desc')
g.default_sortdir = 'desc'
g.set_renderer('id', self.render_id) g.set_renderer('id', self.render_id)

View file

@ -49,7 +49,7 @@ class FamiliesView(MasterView):
def configure_grid(self, g): def configure_grid(self, g):
g.filters['name'].default_active = True g.filters['name'].default_active = True
g.filters['name'].default_verb = 'contains' g.filters['name'].default_verb = 'contains'
g.default_sortkey = 'code' g.set_sort_defaults('code')
def configure_fieldset(self, fs): def configure_fieldset(self, fs):
fs.configure( fs.configure(

View file

@ -53,7 +53,7 @@ class ProfilesView(MasterView):
def configure_grid(self, g): def configure_grid(self, g):
super(ProfilesView, self).configure_grid(g) super(ProfilesView, self).configure_grid(g)
g.default_sortkey = 'ordinal' g.set_sort_defaults('ordinal')
g.set_type('visible', 'boolean') g.set_type('visible', 'boolean')
g.set_link('code') g.set_link('code')
g.set_link('description') g.set_link('description')

View file

@ -404,8 +404,7 @@ class MasterView2(MasterView):
pass pass
def configure_version_grid(self, g): def configure_version_grid(self, g):
g.default_sortkey = 'issued_at' g.set_sort_defaults('issued_at', 'desc')
g.default_sortdir = 'desc'
g.set_renderer('comment', self.render_version_comment) g.set_renderer('comment', self.render_version_comment)
g.set_label('issued_at', "Changed") g.set_label('issued_at', "Changed")
g.set_label('user', "Changed by") g.set_label('user', "Changed by")

View file

@ -119,8 +119,7 @@ class MessagesView(MasterView):
g.filters['subject'].default_active = True g.filters['subject'].default_active = True
g.filters['subject'].default_verb = 'contains' g.filters['subject'].default_verb = 'contains'
g.default_sortkey = 'sent' g.set_sort_defaults('sent', 'desc')
g.default_sortdir = 'desc'
g.set_renderer('sent', self.render_sent) g.set_renderer('sent', self.render_sent)
g.set_renderer('sender', self.render_sender) g.set_renderer('sender', self.render_sender)

View file

@ -92,7 +92,7 @@ class PeopleView(MasterView):
g.sorters['email'] = lambda q, d: q.order_by(getattr(model.PersonEmailAddress.address, d)()) 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.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('display_name', "Full Name")
g.set_label('phone', "Phone Number") g.set_label('phone', "Phone Number")

View file

@ -220,7 +220,7 @@ class ProductsView(MasterView):
g.set_sorter('current_price', self.CurrentPrice.price) g.set_sorter('current_price', self.CurrentPrice.price)
g.set_filter('current_price', self.CurrentPrice.price, label="Current 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'): if self.print_labels and self.request.has_perm('products.print_labels'):
g.more_actions.append(grids.GridAction('print_label', icon='print')) g.more_actions.append(grids.GridAction('print_label', icon='print'))

View file

@ -146,8 +146,7 @@ class PurchaseView(MasterView):
g.filters['date_ordered'].default_active = True g.filters['date_ordered'].default_active = True
g.filters['date_ordered'].default_verb = 'equal' g.filters['date_ordered'].default_verb = 'equal'
g.default_sortkey = 'date_ordered' g.set_sort_defaults('date_ordered', 'desc')
g.default_sortdir = 'desc'
g.set_enum('status', self.enum.PURCHASE_STATUS) g.set_enum('status', self.enum.PURCHASE_STATUS)
@ -212,7 +211,7 @@ class PurchaseView(MasterView):
def configure_row_grid(self, g): def configure_row_grid(self, g):
super(PurchaseView, self).configure_row_grid(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('cases_ordered', 'quantity')
g.set_type('units_ordered', 'quantity') g.set_type('units_ordered', 'quantity')

View file

@ -67,8 +67,7 @@ class PurchaseCreditView(MasterView):
g.set_joiner('vendor', lambda q: q.outerjoin(model.Vendor)) g.set_joiner('vendor', lambda q: q.outerjoin(model.Vendor))
g.set_sorter('vendor', model.Vendor.name) g.set_sorter('vendor', model.Vendor.name)
g.default_sortkey = 'date_received' g.set_sort_defaults('date_received', 'desc')
g.default_sortdir = 'desc'
g.filters['status'].set_value_renderer(grids.filters.EnumValueRenderer(self.enum.PURCHASE_CREDIT_STATUS)) g.filters['status'].set_value_renderer(grids.filters.EnumValueRenderer(self.enum.PURCHASE_CREDIT_STATUS))
g.filters['status'].default_active = True g.filters['status'].default_active = True

View file

@ -48,7 +48,7 @@ class ReportCodesView(MasterView):
super(ReportCodesView, self).configure_grid(g) super(ReportCodesView, self).configure_grid(g)
g.filters['name'].default_active = True g.filters['name'].default_active = True
g.filters['name'].default_verb = 'contains' g.filters['name'].default_verb = 'contains'
g.default_sortkey = 'code' g.set_sort_defaults('code')
g.set_link('code') g.set_link('code')
g.set_link('name') g.set_link('name')

View file

@ -55,7 +55,7 @@ class RolesView(PrincipalMasterView):
super(RolesView, self).configure_grid(g) super(RolesView, self).configure_grid(g)
g.filters['name'].default_active = True g.filters['name'].default_active = True
g.filters['name'].default_verb = 'contains' g.filters['name'].default_verb = 'contains'
g.default_sortkey = 'name' g.set_sort_defaults('name')
g.set_link('name') g.set_link('name')
def _preconfigure_fieldset(self, fs): def _preconfigure_fieldset(self, fs):

View file

@ -51,7 +51,7 @@ class SettingsView(MasterView):
super(SettingsView, self).configure_grid(g) super(SettingsView, self).configure_grid(g)
g.filters['name'].default_active = True g.filters['name'].default_active = True
g.filters['name'].default_verb = 'contains' g.filters['name'].default_verb = 'contains'
g.default_sortkey = 'name' g.set_sort_defaults('name')
g.set_link('name') g.set_link('name')
def configure_form(self, f): def configure_form(self, f):

View file

@ -72,8 +72,7 @@ class ScheduledShiftsView(MasterView):
g.filters['employee'] = g.make_filter('employee', model.Person.display_name, g.filters['employee'] = g.make_filter('employee', model.Person.display_name,
default_active=True, default_verb='contains') default_active=True, default_verb='contains')
g.default_sortkey = 'start_time' g.set_sort_defaults('start_time', 'desc')
g.default_sortdir = 'desc'
g.set_renderer('length', render_shift_length) 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 # TODO: these sorters should be automatic once we fix the schema
g.sorters['start_time'] = g.make_sorter(model.WorkedShift.punch_in) g.sorters['start_time'] = g.make_sorter(model.WorkedShift.punch_in)
g.sorters['end_time'] = g.make_sorter(model.WorkedShift.punch_out) g.sorters['end_time'] = g.make_sorter(model.WorkedShift.punch_out)
g.default_sortkey = 'start_time' g.set_sort_defaults('start_time', 'desc')
g.default_sortdir = 'desc'
g.set_renderer('length', render_shift_length) g.set_renderer('length', render_shift_length)

View file

@ -72,7 +72,7 @@ class StoresView(MasterView):
g.set_sorter('phone', model.StorePhoneNumber.number) g.set_sorter('phone', model.StorePhoneNumber.number)
g.set_sorter('email', model.StoreEmailAddress.address) g.set_sorter('email', model.StoreEmailAddress.address)
g.default_sortkey = 'id' g.set_sort_defaults('id')
g.set_link('id') g.set_link('id')
g.set_link('name') g.set_link('name')

View file

@ -60,7 +60,7 @@ class SubdepartmentsView(MasterView):
super(SubdepartmentsView, self).configure_grid(g) super(SubdepartmentsView, self).configure_grid(g)
g.filters['name'].default_active = True g.filters['name'].default_active = True
g.filters['name'].default_verb = 'contains' g.filters['name'].default_verb = 'contains'
g.default_sortkey = 'name' g.set_sort_defaults('name')
g.set_link('number') g.set_link('number')
g.set_link('name') g.set_link('name')

View file

@ -63,7 +63,7 @@ class TablesView(MasterView):
def configure_grid(self, g): def configure_grid(self, g):
g.sorters['name'] = g.make_simple_sorter('name', foldcase=True) g.sorters['name'] = g.make_simple_sorter('name', foldcase=True)
g.sorters['row_count'] = g.make_simple_sorter('row_count') g.sorters['row_count'] = g.make_simple_sorter('row_count')
g.default_sortkey = 'name' g.set_sort_defaults('name')
def includeme(config): def includeme(config):

View file

@ -50,7 +50,7 @@ class TaxesView(MasterView):
super(TaxesView, self).configure_grid(g) super(TaxesView, self).configure_grid(g)
g.filters['description'].default_active = True g.filters['description'].default_active = True
g.filters['description'].default_verb = 'contains' g.filters['description'].default_verb = 'contains'
g.default_sortkey = 'code' g.set_sort_defaults('code')
g.set_link('code') g.set_link('code')
g.set_link('description') g.set_link('description')

View file

@ -84,7 +84,7 @@ class TempmonClientView(MasterView):
g.filters['hostname'].default_verb = 'contains' g.filters['hostname'].default_verb = 'contains'
g.filters['location'].default_active = True g.filters['location'].default_active = True
g.filters['location'].default_verb = 'contains' 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('enabled', 'boolean')
g.set_type('online', 'boolean') g.set_type('online', 'boolean')

View file

@ -70,7 +70,7 @@ class TempmonProbeView(MasterView):
g.joiners['client'] = lambda q: q.join(tempmon.Client) g.joiners['client'] = lambda q: q.join(tempmon.Client)
g.sorters['client'] = g.make_sorter(tempmon.Client.config_key) 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('appliance_type', self.enum.TEMPMON_APPLIANCE_TYPE)
g.set_enum('status', self.enum.TEMPMON_PROBE_STATUS) g.set_enum('status', self.enum.TEMPMON_PROBE_STATUS)

View file

@ -74,9 +74,7 @@ class TempmonReadingView(MasterView):
g.sorters['probe'] = g.make_sorter(tempmon.Probe.description) g.sorters['probe'] = g.make_sorter(tempmon.Probe.description)
g.filters['probe'] = g.make_filter('probe', tempmon.Probe.description) g.filters['probe'] = g.make_filter('probe', tempmon.Probe.description)
g.default_sortkey = 'taken' g.set_sort_defaults('taken', 'desc')
g.default_sortdir = 'desc'
g.set_type('taken', 'datetime') g.set_type('taken', 'datetime')
g.set_renderer('client_key', self.render_client_key) g.set_renderer('client_key', self.render_client_key)

View file

@ -84,8 +84,7 @@ class TransactionView(MasterView):
g.filters['start_time'].default_active = True g.filters['start_time'].default_active = True
g.filters['start_time'].default_verb = 'equal' g.filters['start_time'].default_verb = 'equal'
g.filters['start_time'].default_value = six.text_type(localtime(self.rattail_config).date()) g.filters['start_time'].default_value = six.text_type(localtime(self.rattail_config).date())
g.default_sortkey = 'start_time' g.set_sort_defaults('start_time', 'desc')
g.default_sortdir = 'desc'
g.set_enum('system', self.enum.TRAINWRECK_SYSTEM) g.set_enum('system', self.enum.TRAINWRECK_SYSTEM)
g.set_type('total', 'currency') g.set_type('total', 'currency')
@ -143,7 +142,7 @@ class TransactionView(MasterView):
def configure_row_grid(self, g): def configure_row_grid(self, g):
super(TransactionView, self).configure_row_grid(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('unit_quantity', 'quantity')
g.set_type('subtotal', 'currency') g.set_type('subtotal', 'currency')

View file

@ -119,8 +119,7 @@ class UpgradeView(MasterView):
g.set_enum('status_code', self.enum.UPGRADE_STATUS) g.set_enum('status_code', self.enum.UPGRADE_STATUS)
g.set_type('created', 'datetime') g.set_type('created', 'datetime')
g.set_type('executed', 'datetime') g.set_type('executed', 'datetime')
g.default_sortkey = 'created' g.set_sort_defaults('created', 'desc')
g.default_sortdir = 'desc'
g.set_link('created') g.set_link('created')
g.set_link('description') g.set_link('description')
# g.set_link('not_until') # g.set_link('not_until')

View file

@ -181,7 +181,7 @@ class UsersView(PrincipalMasterView):
g.set_sorter('first_name', model.Person.first_name) g.set_sorter('first_name', model.Person.first_name)
g.set_sorter('last_name', model.Person.last_name) g.set_sorter('last_name', model.Person.last_name)
g.set_sorter('display_name', model.Person.display_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") g.set_label('person', "Person's Name")
@ -249,8 +249,7 @@ class UsersView(PrincipalMasterView):
super(UsersView, self).configure_row_grid(g) super(UsersView, self).configure_row_grid(g)
g.width = 'half' g.width = 'half'
g.filterable = False g.filterable = False
g.default_sortkey = 'occurred' g.set_sort_defaults('occurred', 'desc')
g.default_sortdir = 'desc'
g.set_enum('type_code', self.enum.USER_EVENT) g.set_enum('type_code', self.enum.USER_EVENT)
g.set_label('type_code', "Event Type") g.set_label('type_code', "Event Type")
g.main_actions = [] g.main_actions = []
@ -333,8 +332,7 @@ class UserEventsView(MasterView):
g.set_type('occurred', 'datetime') g.set_type('occurred', 'datetime')
g.set_renderer('user', self.render_user) g.set_renderer('user', self.render_user)
g.set_renderer('person', self.render_person) g.set_renderer('person', self.render_person)
g.default_sortkey = 'occurred' g.set_sort_defaults('occurred', 'desc')
g.default_sortdir = 'desc'
g.set_label('user', "Username") g.set_label('user', "Username")
g.set_label('type_code', "Event Type") g.set_label('type_code', "Event Type")