Various grid and form tweaks.

This commit is contained in:
Lance Edgar 2015-02-09 13:20:34 -06:00
parent 3257010a7e
commit eedbc5fb9a
4 changed files with 14 additions and 12 deletions

View file

@ -34,7 +34,8 @@ __all__ = ['AssociationProxyField']
def AssociationProxyField(name, **kwargs):
"""
Returns a ``Field`` class which is aware of SQLAlchemy association proxies.
Returns a FormAlchemy ``Field`` class which is aware of association
proxies.
"""
class ProxyField(Field):
@ -45,10 +46,7 @@ def AssociationProxyField(name, **kwargs):
self.renderer.deserialize())
def value(model):
try:
return getattr(model, name)
except AttributeError:
return None
return getattr(model, name, None)
kwargs.setdefault('value', value)
return ProxyField(name, **kwargs)

View file

@ -31,6 +31,7 @@ div.form-wrapper ul.context-menu li {
div.form,
div.fieldset-form,
div.fieldset {
clear: left;
float: left;
margin-top: 10px;
}

View file

@ -59,7 +59,7 @@ class AlchemyGridView(GridView):
def __call__(self):
self._data = self.query()
grid = self.grid()
return grids.util.render_grid(grid)
return self.render_grid(grid)
class SortableAlchemyGridView(AlchemyGridView):
@ -108,7 +108,7 @@ class SortableAlchemyGridView(AlchemyGridView):
self._sort_config = self.sort_config()
self._data = self.query()
grid = self.grid()
return grids.util.render_grid(grid)
return self.render_grid(grid)
class PagedAlchemyGridView(SortableAlchemyGridView):
@ -127,7 +127,7 @@ class PagedAlchemyGridView(SortableAlchemyGridView):
self._data = self.make_pager()
grid = self.grid()
grid.pager = self._data
return grids.util.render_grid(grid)
return self.render_grid(grid)
class SearchableAlchemyGridView(PagedAlchemyGridView):
@ -184,5 +184,4 @@ class SearchableAlchemyGridView(PagedAlchemyGridView):
self._data = self.make_pager()
grid = self.grid()
grid.pager = self._data
kwargs = self.render_kwargs()
return grids.util.render_grid(grid, search, **kwargs)
return self.render_grid(grid, search)

View file

@ -62,7 +62,11 @@ class GridView(View):
def render_kwargs(self):
return {}
def render_grid(self, grid, search=None, **kwargs):
kwargs = self.render_kwargs()
kwargs['search_form'] = search
return grids.util.render_grid(grid, **kwargs)
def __call__(self):
grid = self.grid()
kwargs = self.render_kwargs()
return grids.util.render_grid(grid, **kwargs)
return self.render_grid(grid)