Add initial/basic support for "simple" mobile grid filter w/ radio buttons
so far only one such filter is (presumably?) supported..etc.
This commit is contained in:
parent
9da7ba21bf
commit
f47157102c
10 changed files with 104 additions and 19 deletions
|
@ -65,6 +65,7 @@ class MasterView(View):
|
|||
|
||||
supports_mobile = False
|
||||
mobile_creatable = False
|
||||
mobile_filterable = False
|
||||
|
||||
listing = False
|
||||
creating = False
|
||||
|
@ -197,11 +198,19 @@ class MasterView(View):
|
|||
defaults = {
|
||||
'route_prefix': self.get_route_prefix(),
|
||||
'pageable': self.pageable,
|
||||
'sortable': True,
|
||||
'sortable': False,
|
||||
'filterable': self.mobile_filterable,
|
||||
}
|
||||
if self.mobile_filterable:
|
||||
defaults['filters'] = self.make_mobile_filters()
|
||||
defaults.update(kwargs)
|
||||
return defaults
|
||||
|
||||
def make_mobile_filters(self):
|
||||
"""
|
||||
Returns a set of filters for the mobile grid, if applicable.
|
||||
"""
|
||||
|
||||
def preconfigure_mobile_grid(self, grid):
|
||||
"""
|
||||
Optionally perform pre-configuration for the mobile grid, to establish
|
||||
|
|
|
@ -33,16 +33,42 @@ import sqlalchemy as sa
|
|||
from rattail import pod
|
||||
from rattail.db import model
|
||||
from rattail.gpc import GPC
|
||||
from rattail.util import pretty_quantity
|
||||
from rattail.util import pretty_quantity, prettify
|
||||
|
||||
import formalchemy as fa
|
||||
import formencode as fe
|
||||
from webhelpers2.html import tags
|
||||
|
||||
from tailbone import forms
|
||||
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 ReceivingBatchView(PurchasingBatchView):
|
||||
"""
|
||||
Master view for receiving batches
|
||||
|
@ -55,12 +81,21 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
rows_deletable = False
|
||||
supports_mobile = True
|
||||
mobile_creatable = True
|
||||
mobile_filterable = True
|
||||
mobile_rows_viewable = True
|
||||
|
||||
@property
|
||||
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 mobile_create(self):
|
||||
"""
|
||||
Mobile view for creating a new receiving batch
|
||||
|
@ -115,12 +150,8 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
return kwargs
|
||||
|
||||
def get_mobile_data(self, session=None):
|
||||
# TODO: this hard-codes list view to show Pending only
|
||||
# TODO: this hard-codes the sort by batch ID desc
|
||||
return super(ReceivingBatchView, self).get_mobile_data(session=session)\
|
||||
.filter(model.PurchaseBatch.executed == None)\
|
||||
.filter(sa.or_(
|
||||
model.PurchaseBatch.complete == None,
|
||||
model.PurchaseBatch.complete == False))\
|
||||
.order_by(model.PurchaseBatch.id.desc())
|
||||
|
||||
def configure_mobile_grid(self, g):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue