Make all batches support mobile by default
with default pending/etc. filter also
This commit is contained in:
parent
48f5da4511
commit
60104f05c7
6 changed files with 71 additions and 70 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue