Make all batches support mobile by default

with default pending/etc. filter also
This commit is contained in:
Lance Edgar 2017-07-11 15:25:05 -05:00
parent 48f5da4511
commit 60104f05c7
6 changed files with 71 additions and 70 deletions

View file

@ -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)

View file

@ -9,3 +9,34 @@
<li>${grid.listitem.render_readonly()}</li>
% endfor
</ul>
## <table data-role="table" class="ui-responsive table-stroke">
## <thead>
## <tr>
## % for column in grid.iter_visible_columns():
## ${grid.column_header(column)}
## % endfor
## </tr>
## </thead>
## <tbody>
## % for i, row in enumerate(grid.iter_rows(), 1):
## <tr>
## % for column in grid.iter_visible_columns():
## <td>${grid.render_cell(row, column)}</td>
## % endfor
## </tr>
## % endfor
## </tbody>
## </table>
% if grid.pageable and grid.pager:
<br />
<div data-role="controlgroup" data-type="horizontal">
${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}
</div>
% endif

View file

@ -10,34 +10,3 @@
<%def name="title()">${model_title_plural}</%def>
${grid.render_complete()|n}
## <table data-role="table" class="ui-responsive table-stroke">
## <thead>
## <tr>
## % for column in grid.iter_visible_columns():
## ${grid.column_header(column)}
## % endfor
## </tr>
## </thead>
## <tbody>
## % for i, row in enumerate(grid.iter_rows(), 1):
## <tr>
## % for column in grid.iter_visible_columns():
## <td>${grid.render_cell(row, column)}</td>
## % endfor
## </tr>
## % endfor
## </tbody>
## </table>
% if grid.pageable and grid.pager:
<br />
<div data-role="controlgroup" data-type="horizontal">
${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'})}
</div>
% endif

View file

@ -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)

View file

@ -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",

View file

@ -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.