diff --git a/tailbone/newgrids/filters.py b/tailbone/newgrids/filters.py index f0857059..8b817afb 100644 --- a/tailbone/newgrids/filters.py +++ b/tailbone/newgrids/filters.py @@ -212,7 +212,8 @@ class MobileFilter(GridFilter): """ default_verbs = ['equal'] - def __init__(self, key, **kwargs): + def __init__(self, model_class, key, **kwargs): + self.model_class = model_class kwargs.setdefault('default_active', True) kwargs.setdefault('default_verb', 'equal') super(MobileFilter, self).__init__(key, **kwargs) diff --git a/tailbone/templates/mobile/grid_complete.mako b/tailbone/templates/mobile/grid_complete.mako index 8fa765bc..6402d6f0 100644 --- a/tailbone/templates/mobile/grid_complete.mako +++ b/tailbone/templates/mobile/grid_complete.mako @@ -9,3 +9,34 @@
  • ${grid.listitem.render_readonly()}
  • % endfor + +## +## +## +## % for column in grid.iter_visible_columns(): +## ${grid.column_header(column)} +## % endfor +## +## +## +## % for i, row in enumerate(grid.iter_rows(), 1): +## +## % for column in grid.iter_visible_columns(): +## +## % endfor +## +## % endfor +## +##
    ${grid.render_cell(row, column)}
    + +% if grid.pageable and grid.pager: +
    +
    + ${grid.pager.pager('$link_first $link_previous $link_next $link_last', + symbol_first='<< first', symbol_last='last >>', + symbol_previous='< prev', symbol_next='next >', + link_attr={'class': 'ui-btn ui-corner-all'}, + curpage_attr={'class': 'ui-btn ui-corner-all'}, + dotdot_attr={'class': 'ui-btn ui-corner-all'})|n} +
    +% endif diff --git a/tailbone/templates/mobile/master/index.mako b/tailbone/templates/mobile/master/index.mako index ea2c7034..25af12de 100644 --- a/tailbone/templates/mobile/master/index.mako +++ b/tailbone/templates/mobile/master/index.mako @@ -10,34 +10,3 @@ <%def name="title()">${model_title_plural} ${grid.render_complete()|n} - -## -## -## -## % for column in grid.iter_visible_columns(): -## ${grid.column_header(column)} -## % endfor -## -## -## -## % for i, row in enumerate(grid.iter_rows(), 1): -## -## % for column in grid.iter_visible_columns(): -## -## % endfor -## -## % endfor -## -##
    ${grid.render_cell(row, column)}
    - -% if grid.pageable and grid.pager: -
    -
    - ${grid.pager.pager('$link_first $link_previous $link_next $link_last', - symbol_first='<< first', symbol_last='last >>', - symbol_previous='< prev', symbol_next='next >', - link_attr={'class': 'ui-btn ui-corner-all'}, - curpage_attr={'class': 'ui-btn ui-corner-all'}, - dotdot_attr={'class': 'ui-btn ui-corner-all'})} -
    -% endif diff --git a/tailbone/views/batch/core.py b/tailbone/views/batch/core.py index 30ee2a85..3886c037 100644 --- a/tailbone/views/batch/core.py +++ b/tailbone/views/batch/core.py @@ -35,12 +35,13 @@ import logging from cStringIO import StringIO import six +import sqlalchemy as sa from sqlalchemy import orm from rattail.db import model, Session as RattailSession from rattail.threads import Thread from rattail.csvutil import UnicodeDictWriter -from rattail.util import load_object +from rattail.util import load_object, prettify import formalchemy as fa from pyramid import httpexceptions @@ -71,6 +72,8 @@ class BatchMasterView(MasterView): refresh_after_create = False edit_with_rows = False cloneable = False + supports_mobile = True + mobile_filterable = True def __init__(self, request): super(BatchMasterView, self).__init__(request) @@ -177,6 +180,14 @@ class BatchMasterView(MasterView): ], readonly=True) + def make_mobile_filters(self): + """ + Returns a set of filters for the mobile grid. + """ + filters = grids.filters.GridFilterSet() + filters['status'] = MobileBatchStatusFilter(self.model_class, 'status', default_value='pending') + return filters + def _preconfigure_fieldset(self, fs): """ Apply some commonly-useful pre-configuration to the main batch @@ -1151,3 +1162,29 @@ class StatusRenderer(forms.renderers.EnumFieldRenderer): if row.status_text: return HTML.tag('span', title=row.status_text, c=status_code_text) return status_code_text + + +class MobileBatchStatusFilter(grids.filters.MobileFilter): + + value_choices = ['pending', 'complete', 'executed', 'all'] + + def filter_equal(self, query, value): + + if value == 'pending': + return query.filter(self.model_class.executed == None)\ + .filter(sa.or_( + self.model_class.complete == None, + self.model_class.complete == False)) + + if value == 'complete': + return query.filter(self.model_class.executed == None)\ + .filter(self.model_class.complete == True) + + if value == 'executed': + return query.filter(self.model_class.executed != None) + + return query + + def iter_choices(self): + for value in self.value_choices: + yield value, prettify(value) diff --git a/tailbone/views/purchases/batch.py b/tailbone/views/purchases/batch.py index 50c56fde..bad76099 100644 --- a/tailbone/views/purchases/batch.py +++ b/tailbone/views/purchases/batch.py @@ -80,7 +80,6 @@ class PurchaseBatchView(BatchMasterView): rows_creatable = True rows_editable = True edit_with_rows = False - supports_mobile = True order_form_header_columns = [ "UPC", diff --git a/tailbone/views/purchasing/receiving.py b/tailbone/views/purchasing/receiving.py index 2638f0bb..4871a5ac 100644 --- a/tailbone/views/purchasing/receiving.py +++ b/tailbone/views/purchasing/receiving.py @@ -43,32 +43,6 @@ from tailbone import forms, newgrids as grids from tailbone.views.purchasing import PurchasingBatchView -class MobileBatchStatusFilter(grids.filters.MobileFilter): - - value_choices = ['pending', 'complete', 'executed', 'all'] - - def filter_equal(self, query, value): - - if value == 'pending': - return query.filter(model.PurchaseBatch.executed == None)\ - .filter(sa.or_( - model.PurchaseBatch.complete == None, - model.PurchaseBatch.complete == False)) - - if value == 'complete': - return query.filter(model.PurchaseBatch.executed == None)\ - .filter(model.PurchaseBatch.complete == True) - - if value == 'executed': - return query.filter(model.PurchaseBatch.executed != None) - - return query - - def iter_choices(self): - for value in self.value_choices: - yield value, prettify(value) - - class MobileItemStatusFilter(grids.filters.MobileFilter): value_choices = ['incomplete', 'unexpected', 'damaged', 'expired', 'all'] @@ -116,9 +90,7 @@ class ReceivingBatchView(PurchasingBatchView): model_title_plural = "Receiving Batches" creatable = False rows_deletable = False - supports_mobile = True mobile_creatable = True - mobile_filterable = True mobile_rows_filterable = True mobile_rows_viewable = True @@ -126,14 +98,6 @@ class ReceivingBatchView(PurchasingBatchView): def batch_mode(self): return self.enum.PURCHASE_BATCH_MODE_RECEIVING - def make_mobile_filters(self): - """ - Returns a set of filters for the mobile grid. - """ - filters = grids.filters.GridFilterSet() - filters['status'] = MobileBatchStatusFilter('status', default_value='pending') - return filters - def make_mobile_row_filters(self): """ Returns a set of filters for the mobile row grid.