Fix grid pager styles; add default config for version grids
also remove all old grid code from v1 MasterView, since it now is entirely superseded by v2 master
This commit is contained in:
parent
55ca7d5117
commit
df1c0b0b5e
|
@ -276,3 +276,30 @@
|
|||
display: block;
|
||||
padding: 2px 0;
|
||||
}
|
||||
|
||||
|
||||
/******************************
|
||||
* pager
|
||||
******************************/
|
||||
|
||||
.pager {
|
||||
margin-bottom: 20px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.pager p {
|
||||
font-size: 10pt;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.pager .showing {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.pager #grid-page-count {
|
||||
font-size: 8pt;
|
||||
}
|
||||
|
||||
.pager .page-links {
|
||||
float: right;
|
||||
}
|
||||
|
|
|
@ -147,19 +147,6 @@ class MasterView(View):
|
|||
grid = self.make_mobile_grid()
|
||||
return self.render_to_response('index', {'grid': grid}, mobile=True)
|
||||
|
||||
def make_mobile_grid(self, **kwargs):
|
||||
factory = self.get_mobile_grid_factory()
|
||||
kwargs = self.make_mobile_grid_kwargs(**kwargs)
|
||||
kwargs.setdefault('key', self.get_mobile_grid_key())
|
||||
kwargs.setdefault('request', self.request)
|
||||
kwargs.setdefault('data', self.get_mobile_data(session=kwargs.get('session')))
|
||||
kwargs.setdefault('model_class', self.get_model_class(error=False))
|
||||
grid = factory(**kwargs)
|
||||
self.preconfigure_mobile_grid(grid)
|
||||
self.configure_mobile_grid(grid)
|
||||
grid.load_settings()
|
||||
return grid
|
||||
|
||||
@classmethod
|
||||
def get_mobile_grid_key(cls):
|
||||
"""
|
||||
|
@ -181,38 +168,6 @@ class MasterView(View):
|
|||
"""
|
||||
return self.get_data(session=session)
|
||||
|
||||
def make_mobile_grid_kwargs(self, **kwargs):
|
||||
"""
|
||||
Must return a dictionary of kwargs to be passed to the factory when
|
||||
creating new mobile grid instances.
|
||||
"""
|
||||
defaults = {
|
||||
'route_prefix': self.get_route_prefix(),
|
||||
'pageable': self.pageable,
|
||||
'sortable': False,
|
||||
'filterable': self.mobile_filterable,
|
||||
}
|
||||
if self.mobile_filterable:
|
||||
defaults['filters'] = self.make_mobile_filters()
|
||||
defaults.update(kwargs)
|
||||
return defaults
|
||||
|
||||
def make_mobile_row_grid_kwargs(self, **kwargs):
|
||||
"""
|
||||
Must return a dictionary of kwargs to be passed to the factory when
|
||||
creating new mobile *row* grid instances.
|
||||
"""
|
||||
defaults = {
|
||||
'route_prefix': self.get_route_prefix(),
|
||||
'pageable': self.pageable,
|
||||
'sortable': False,
|
||||
'filterable': self.mobile_rows_filterable,
|
||||
}
|
||||
if self.mobile_rows_filterable:
|
||||
defaults['filters'] = self.make_mobile_row_filters()
|
||||
defaults.update(kwargs)
|
||||
return defaults
|
||||
|
||||
def make_mobile_filters(self):
|
||||
"""
|
||||
Returns a set of filters for the mobile grid, if applicable.
|
||||
|
@ -223,25 +178,6 @@ class MasterView(View):
|
|||
Returns a set of filters for the mobile row grid, if applicable.
|
||||
"""
|
||||
|
||||
def preconfigure_mobile_grid(self, grid):
|
||||
"""
|
||||
Optionally perform pre-configuration for the mobile grid, to establish
|
||||
some sane defaults etc.
|
||||
"""
|
||||
|
||||
def configure_mobile_grid(self, grid):
|
||||
"""
|
||||
Configure the mobile grid. The primary objective here is to define
|
||||
which columns to show and in which order etc. Along the way you're
|
||||
free to customize any column(s) you like, as needed.
|
||||
"""
|
||||
listitem = self.mobile_listitem_field()
|
||||
if listitem:
|
||||
grid.append(listitem)
|
||||
grid.configure(include=[grid.listitem])
|
||||
else:
|
||||
grid.configure()
|
||||
|
||||
def mobile_listitem_field(self):
|
||||
"""
|
||||
Must return a FormAlchemy field to be appended to grid, or ``None`` if
|
||||
|
@ -282,11 +218,6 @@ class MasterView(View):
|
|||
|
||||
return ListItemRenderer
|
||||
|
||||
def render_mobile_row_listitem(self, row, **kwargs):
|
||||
if row is None:
|
||||
return ''
|
||||
return tags.link_to(row, '#')
|
||||
|
||||
def create(self):
|
||||
"""
|
||||
View for creating a new model record.
|
||||
|
@ -386,23 +317,6 @@ class MasterView(View):
|
|||
'grid': grid,
|
||||
})
|
||||
|
||||
def make_version_grid(self, instance=None, **kwargs):
|
||||
"""
|
||||
Make and return a new (configured) version grid instance.
|
||||
"""
|
||||
if instance is None:
|
||||
instance = self.get_instance()
|
||||
factory = self.get_version_grid_factory()
|
||||
key = self.get_version_grid_key()
|
||||
data = self.get_version_data(instance)
|
||||
kwargs = self.make_version_grid_kwargs(**kwargs)
|
||||
kwargs['model_class'] = continuum.transaction_class(self.get_model_class())
|
||||
grid = factory(key, self.request, data=data, **kwargs)
|
||||
self.preconfigure_version_grid(grid)
|
||||
self.configure_version_grid(grid)
|
||||
grid.load_settings()
|
||||
return grid
|
||||
|
||||
@classmethod
|
||||
def get_version_grid_key(cls):
|
||||
"""
|
||||
|
@ -440,44 +354,6 @@ class MasterView(View):
|
|||
classes.append(cls)
|
||||
return classes
|
||||
|
||||
def make_version_grid_kwargs(self, **kwargs):
|
||||
"""
|
||||
Return a dictionary of kwargs to be passed to the factory when
|
||||
constructing a new version grid.
|
||||
"""
|
||||
defaults = {
|
||||
'width': 'full',
|
||||
'pageable': True,
|
||||
}
|
||||
if 'main_actions' not in kwargs:
|
||||
route = '{}.version'.format(self.get_route_prefix())
|
||||
instance = kwargs.get('instance') or self.get_instance()
|
||||
url = lambda txn, i: self.request.route_url(route, uuid=instance.uuid, txnid=txn.id)
|
||||
defaults['main_actions'] = [
|
||||
self.make_action('view', icon='zoomin', url=url),
|
||||
]
|
||||
defaults.update(kwargs)
|
||||
return defaults
|
||||
|
||||
def preconfigure_version_grid(self, g):
|
||||
g.issued_at.set(label="Changed")
|
||||
g.user.set(label="Changed by")
|
||||
g.remote_addr.set(label="IP Address")
|
||||
g.append(fa.Field('comment', value=lambda txn: txn.meta.get('comment')))
|
||||
g.default_sortkey = 'issued_at'
|
||||
g.default_sortdir = 'desc'
|
||||
|
||||
def configure_version_grid(self, g):
|
||||
"""
|
||||
Configure the version grid, customizing as necessary.
|
||||
"""
|
||||
g.configure(include=[
|
||||
g.issued_at,
|
||||
g.user,
|
||||
g.remote_addr,
|
||||
g.comment,
|
||||
], readonly=True)
|
||||
|
||||
def view_version(self):
|
||||
"""
|
||||
View showing diff details of a particular object version.
|
||||
|
@ -614,23 +490,6 @@ class MasterView(View):
|
|||
def get_mobile_row_data(self, parent):
|
||||
return self.get_row_data(parent)
|
||||
|
||||
def make_mobile_row_grid(self, **kwargs):
|
||||
"""
|
||||
Make a new (configured) rows grid instance for mobile.
|
||||
"""
|
||||
parent = kwargs.pop('instance', self.get_instance())
|
||||
kwargs['instance'] = parent
|
||||
kwargs['data'] = self.get_mobile_row_data(parent)
|
||||
kwargs['key'] = 'mobile.{}.{}'.format(self.get_grid_key(), self.request.matchdict[self.get_model_key()])
|
||||
kwargs.setdefault('request', self.request)
|
||||
kwargs.setdefault('model_class', self.model_row_class)
|
||||
kwargs = self.make_mobile_row_grid_kwargs(**kwargs)
|
||||
factory = self.get_mobile_row_grid_factory()
|
||||
grid = factory(**kwargs)
|
||||
self.configure_mobile_row_grid(grid)
|
||||
grid.load_settings()
|
||||
return grid
|
||||
|
||||
def mobile_row_listitem_field(self):
|
||||
"""
|
||||
Must return a FormAlchemy field to be appended to row grid, or ``None``
|
||||
|
@ -639,14 +498,6 @@ class MasterView(View):
|
|||
return fa.Field('listitem', value=lambda obj: obj,
|
||||
renderer=self.mobile_row_listitem_renderer())
|
||||
|
||||
def configure_mobile_row_grid(self, grid):
|
||||
listitem = self.mobile_row_listitem_field()
|
||||
if listitem:
|
||||
grid.append(listitem)
|
||||
grid.configure(include=[grid.listitem])
|
||||
else:
|
||||
grid.configure()
|
||||
|
||||
def mobile_row_route_url(self, route_name, **kwargs):
|
||||
route_name = 'mobile.{}.{}'.format(self.get_row_route_prefix(), route_name)
|
||||
return self.request.route_url(route_name, **kwargs)
|
||||
|
@ -676,22 +527,6 @@ class MasterView(View):
|
|||
def make_row_grid_tools(self, obj):
|
||||
return self.make_default_row_grid_tools(obj)
|
||||
|
||||
def make_row_grid(self, **kwargs):
|
||||
"""
|
||||
Make and return a new (configured) rows grid instance.
|
||||
"""
|
||||
parent = kwargs.pop('instance', self.get_instance())
|
||||
data = self.get_row_data(parent)
|
||||
kwargs['instance'] = parent
|
||||
kwargs = self.make_row_grid_kwargs(**kwargs)
|
||||
key = '{}.{}'.format(self.get_grid_key(), self.request.matchdict[self.get_model_key()])
|
||||
factory = self.get_row_grid_factory()
|
||||
grid = factory(key, self.request, data=data, model_class=self.model_row_class, **kwargs)
|
||||
self._preconfigure_row_grid(grid)
|
||||
self.configure_row_grid(grid)
|
||||
grid.load_settings()
|
||||
return grid
|
||||
|
||||
def get_effective_row_query(self):
|
||||
"""
|
||||
Convenience method which returns the "effective" query for the master
|
||||
|
@ -703,12 +538,6 @@ class MasterView(View):
|
|||
main_actions=[])
|
||||
return grid._fa_grid.rows
|
||||
|
||||
def _preconfigure_row_grid(self, g):
|
||||
pass
|
||||
|
||||
def configure_row_grid(self, grid):
|
||||
grid.configure()
|
||||
|
||||
def get_row_data(self, instance):
|
||||
"""
|
||||
Generate the base data set for a rows grid.
|
||||
|
@ -739,48 +568,6 @@ class MasterView(View):
|
|||
"""
|
||||
return "{}.rows".format(cls.get_permission_prefix())
|
||||
|
||||
def make_row_grid_kwargs(self, **kwargs):
|
||||
"""
|
||||
Return a dict of kwargs to be used when constructing a new rows grid.
|
||||
"""
|
||||
route_prefix = self.get_row_route_prefix()
|
||||
permission_prefix = self.get_row_permission_prefix()
|
||||
|
||||
defaults = {
|
||||
'width': 'full',
|
||||
'filterable': self.rows_filterable,
|
||||
'sortable': self.rows_sortable,
|
||||
'pageable': True,
|
||||
'default_pagesize': self.rows_default_pagesize,
|
||||
'row_attrs': self.row_grid_row_attrs,
|
||||
'model_title': self.get_row_model_title(),
|
||||
'model_title_plural': self.get_row_model_title_plural(),
|
||||
'permission_prefix': permission_prefix,
|
||||
'route_prefix': route_prefix,
|
||||
}
|
||||
|
||||
if self.has_rows and 'main_actions' not in defaults:
|
||||
actions = []
|
||||
|
||||
# view action
|
||||
if self.rows_viewable:
|
||||
view = lambda r, i: self.get_row_action_url('view', r)
|
||||
actions.append(grids.GridAction('view', icon='zoomin', url=view))
|
||||
|
||||
# edit action
|
||||
if self.rows_editable:
|
||||
actions.append(grids.GridAction('edit', icon='pencil', url=self.row_edit_action_url))
|
||||
|
||||
# delete action
|
||||
if self.rows_deletable and self.request.has_perm('{}.delete_row'.format(permission_prefix)):
|
||||
actions.append(grids.GridAction('delete', icon='trash', url=self.row_delete_action_url))
|
||||
defaults['delete_speedbump'] = self.rows_deletable_speedbump
|
||||
|
||||
defaults['main_actions'] = actions
|
||||
|
||||
defaults.update(kwargs)
|
||||
return defaults
|
||||
|
||||
def row_edit_action_url(self, row, i):
|
||||
return self.get_row_action_url('edit', row)
|
||||
|
||||
|
@ -1238,35 +1025,6 @@ class MasterView(View):
|
|||
# default previously came from cls.get_normalized_model_name() but this is hopefully better
|
||||
return cls.get_route_prefix()
|
||||
|
||||
def make_grid_kwargs(self, **kwargs):
|
||||
"""
|
||||
Return a dictionary of kwargs to be passed to the factory when creating
|
||||
new grid instances.
|
||||
"""
|
||||
defaults = {
|
||||
'width': 'full',
|
||||
'filterable': self.filterable,
|
||||
'sortable': True,
|
||||
'default_sortkey': getattr(self, 'default_sortkey', None),
|
||||
'sortdir': getattr(self, 'sortdir', 'asc'),
|
||||
'pageable': self.pageable,
|
||||
'checkboxes': self.checkboxes or (
|
||||
self.mergeable and self.request.has_perm('{}.merge'.format(self.get_permission_prefix()))),
|
||||
'checked': self.checked,
|
||||
'row_attrs': self.get_row_attrs,
|
||||
'cell_attrs': self.get_cell_attrs,
|
||||
'model_title': self.get_model_title(),
|
||||
'model_title_plural': self.get_model_title_plural(),
|
||||
'permission_prefix': self.get_permission_prefix(),
|
||||
'route_prefix': self.get_route_prefix(),
|
||||
}
|
||||
if 'main_actions' not in kwargs and 'more_actions' not in kwargs:
|
||||
main, more = self.get_grid_actions()
|
||||
defaults['main_actions'] = main
|
||||
defaults['more_actions'] = more
|
||||
defaults.update(kwargs)
|
||||
return defaults
|
||||
|
||||
def get_grid_actions(self):
|
||||
main, more = self.get_main_actions(), self.get_more_actions()
|
||||
if len(more) == 1:
|
||||
|
@ -1356,30 +1114,6 @@ class MasterView(View):
|
|||
values = [getattr(row, k) for k in keys]
|
||||
return dict(zip(keys, values))
|
||||
|
||||
def make_grid(self, **kwargs):
|
||||
"""
|
||||
Make and return a new (configured) grid instance.
|
||||
"""
|
||||
factory = self.get_grid_factory()
|
||||
key = self.get_grid_key()
|
||||
if 'data' in kwargs:
|
||||
data = kwargs.pop('data')
|
||||
else:
|
||||
data = self.get_data(session=kwargs.get('session'))
|
||||
configure = kwargs.pop('configure', None)
|
||||
kwargs = self.make_grid_kwargs(**kwargs)
|
||||
grid = factory(key, self.request, data=data, model_class=self.get_model_class(error=False), **kwargs)
|
||||
if configure:
|
||||
configure(grid)
|
||||
else:
|
||||
self._preconfigure_grid(grid)
|
||||
self.configure_grid(grid)
|
||||
grid.load_settings()
|
||||
return grid
|
||||
|
||||
def _preconfigure_grid(self, grid):
|
||||
pass
|
||||
|
||||
def get_data(self, session=None):
|
||||
"""
|
||||
Generate the base data set for the grid. This typically will be a
|
||||
|
@ -1404,20 +1138,6 @@ class MasterView(View):
|
|||
"""
|
||||
return session.query(self.get_model_class())
|
||||
|
||||
def get_effective_data(self, session=None, **kwargs):
|
||||
"""
|
||||
Convenience method which returns the "effective" data for the master
|
||||
grid, filtered and sorted to match what would show on the UI, but not
|
||||
paged etc.
|
||||
"""
|
||||
if session is None:
|
||||
session = self.Session()
|
||||
kwargs.setdefault('pageable', False)
|
||||
kwargs.setdefault('main_actions', [])
|
||||
kwargs.setdefault('more_actions', [])
|
||||
grid = self.make_grid(session=session, **kwargs)
|
||||
return grid._fa_grid.rows
|
||||
|
||||
def get_effective_query(self, session=None, **kwargs):
|
||||
return self.get_effective_data(session=session, **kwargs)
|
||||
|
||||
|
|
|
@ -397,8 +397,16 @@ class MasterView2(MasterView):
|
|||
def configure_row_grid(self, grid):
|
||||
pass
|
||||
|
||||
def configure_version_grid(self, grid):
|
||||
pass
|
||||
def configure_version_grid(self, g):
|
||||
g.default_sortkey = 'issued_at'
|
||||
g.default_sortdir = 'desc'
|
||||
g.set_renderer('comment', self.render_version_comment)
|
||||
g.set_label('issued_at', "Changed")
|
||||
g.set_label('user', "Changed by")
|
||||
g.set_label('remote_addr', "IP Address")
|
||||
|
||||
def render_version_comment(self, transaction, column):
|
||||
return transaction.meta.get('comment', "")
|
||||
|
||||
def configure_mobile_grid(self, grid):
|
||||
pass
|
||||
|
|
Loading…
Reference in a new issue