Rebranded to Tailbone.
This commit is contained in:
parent
47944767dc
commit
40efd8a3bc
111 changed files with 188 additions and 209 deletions
30
tailbone/views/grids/__init__.py
Normal file
30
tailbone/views/grids/__init__.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2012 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
# Rattail is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
"""
|
||||
Grid Views
|
||||
"""
|
||||
|
||||
from .core import *
|
||||
from .alchemy import *
|
181
tailbone/views/grids/alchemy.py
Normal file
181
tailbone/views/grids/alchemy.py
Normal file
|
@ -0,0 +1,181 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2012 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
# Rattail is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
"""
|
||||
FormAlchemy Grid Views
|
||||
"""
|
||||
|
||||
from webhelpers import paginate
|
||||
|
||||
from .core import GridView
|
||||
from ... import grids
|
||||
from ... import Session
|
||||
|
||||
|
||||
__all__ = ['AlchemyGridView', 'SortableAlchemyGridView',
|
||||
'PagedAlchemyGridView', 'SearchableAlchemyGridView']
|
||||
|
||||
|
||||
class AlchemyGridView(GridView):
|
||||
|
||||
def make_query(self, session=Session):
|
||||
query = session.query(self.mapped_class)
|
||||
return self.modify_query(query)
|
||||
|
||||
def modify_query(self, query):
|
||||
return query
|
||||
|
||||
def query(self):
|
||||
return self.make_query()
|
||||
|
||||
def make_grid(self, **kwargs):
|
||||
self.update_grid_kwargs(kwargs)
|
||||
return grids.AlchemyGrid(
|
||||
self.request, self.mapped_class, self._data, **kwargs)
|
||||
|
||||
def grid(self):
|
||||
return self.make_grid()
|
||||
|
||||
def __call__(self):
|
||||
self._data = self.query()
|
||||
grid = self.grid()
|
||||
return grids.util.render_grid(grid)
|
||||
|
||||
|
||||
class SortableAlchemyGridView(AlchemyGridView):
|
||||
|
||||
sort = None
|
||||
|
||||
@property
|
||||
def config_prefix(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def join_map(self):
|
||||
return {}
|
||||
|
||||
def make_sort_map(self, *args, **kwargs):
|
||||
return grids.util.get_sort_map(
|
||||
self.mapped_class, names=args or None, **kwargs)
|
||||
|
||||
def sorter(self, field):
|
||||
return grids.util.sorter(field)
|
||||
|
||||
def sort_map(self):
|
||||
return self.make_sort_map()
|
||||
|
||||
def make_sort_config(self, **kwargs):
|
||||
return grids.util.get_sort_config(
|
||||
self.config_prefix, self.request, **kwargs)
|
||||
|
||||
def sort_config(self):
|
||||
return self.make_sort_config(sort=self.sort)
|
||||
|
||||
def modify_query(self, query):
|
||||
return grids.util.sort_query(
|
||||
query, self._sort_config, self.sort_map(), self.join_map())
|
||||
|
||||
def make_grid(self, **kwargs):
|
||||
self.update_grid_kwargs(kwargs)
|
||||
return grids.AlchemyGrid(
|
||||
self.request, self.mapped_class, self._data,
|
||||
sort_map=self.sort_map(), config=self._sort_config, **kwargs)
|
||||
|
||||
def grid(self):
|
||||
return self.make_grid()
|
||||
|
||||
def __call__(self):
|
||||
self._sort_config = self.sort_config()
|
||||
self._data = self.query()
|
||||
grid = self.grid()
|
||||
return grids.util.render_grid(grid)
|
||||
|
||||
|
||||
class PagedAlchemyGridView(SortableAlchemyGridView):
|
||||
|
||||
full = True
|
||||
|
||||
def make_pager(self):
|
||||
config = self._sort_config
|
||||
query = self.query()
|
||||
return paginate.Page(
|
||||
query, item_count=query.count(),
|
||||
items_per_page=int(config['per_page']),
|
||||
page=int(config['page']),
|
||||
url=paginate.PageURL_WebOb(self.request))
|
||||
|
||||
def __call__(self):
|
||||
self._sort_config = self.sort_config()
|
||||
self._data = self.make_pager()
|
||||
grid = self.grid()
|
||||
grid.pager = self._data
|
||||
return grids.util.render_grid(grid)
|
||||
|
||||
|
||||
class SearchableAlchemyGridView(PagedAlchemyGridView):
|
||||
|
||||
def filter_exact(self, field):
|
||||
return grids.search.filter_exact(field)
|
||||
|
||||
def filter_ilike(self, field):
|
||||
return grids.search.filter_ilike(field)
|
||||
|
||||
def make_filter_map(self, **kwargs):
|
||||
return grids.search.get_filter_map(self.mapped_class, **kwargs)
|
||||
|
||||
def filter_map(self):
|
||||
return self.make_filter_map()
|
||||
|
||||
def make_filter_config(self, **kwargs):
|
||||
return grids.search.get_filter_config(
|
||||
self.config_prefix, self.request, self.filter_map(), **kwargs)
|
||||
|
||||
def filter_config(self):
|
||||
return self.make_filter_config()
|
||||
|
||||
def make_search_form(self):
|
||||
return grids.search.get_search_form(
|
||||
self.request, self.filter_map(), self._filter_config)
|
||||
|
||||
def search_form(self):
|
||||
return self.make_search_form()
|
||||
|
||||
def modify_query(self, query):
|
||||
join_map = self.join_map()
|
||||
query = grids.search.filter_query(
|
||||
query, self._filter_config, self.filter_map(), join_map)
|
||||
if hasattr(self, '_sort_config'):
|
||||
self._sort_config['joins'] = self._filter_config['joins']
|
||||
query = grids.util.sort_query(
|
||||
query, self._sort_config, self.sort_map(), join_map)
|
||||
return query
|
||||
|
||||
def __call__(self):
|
||||
self._filter_config = self.filter_config()
|
||||
search = self.search_form()
|
||||
self._sort_config = self.sort_config()
|
||||
self._data = self.make_pager()
|
||||
grid = self.grid()
|
||||
grid.pager = self._data
|
||||
kwargs = self.render_kwargs()
|
||||
return grids.util.render_grid(grid, search, **kwargs)
|
68
tailbone/views/grids/core.py
Normal file
68
tailbone/views/grids/core.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2012 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
# Rattail is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
"""
|
||||
Core Grid View
|
||||
"""
|
||||
|
||||
from .. import View
|
||||
from ... import grids
|
||||
|
||||
|
||||
__all__ = ['GridView']
|
||||
|
||||
|
||||
class GridView(View):
|
||||
|
||||
route_name = None
|
||||
route_url = None
|
||||
renderer = None
|
||||
permission = None
|
||||
|
||||
full = False
|
||||
checkboxes = False
|
||||
deletable = False
|
||||
|
||||
partial_only = False
|
||||
|
||||
def update_grid_kwargs(self, kwargs):
|
||||
kwargs.setdefault('full', self.full)
|
||||
kwargs.setdefault('checkboxes', self.checkboxes)
|
||||
kwargs.setdefault('deletable', self.deletable)
|
||||
kwargs.setdefault('partial_only', self.partial_only)
|
||||
|
||||
def make_grid(self, **kwargs):
|
||||
self.update_grid_kwargs(kwargs)
|
||||
return grids.Grid(self.request, **kwargs)
|
||||
|
||||
def grid(self):
|
||||
return self.make_grid()
|
||||
|
||||
def render_kwargs(self):
|
||||
return {}
|
||||
|
||||
def __call__(self):
|
||||
grid = self.grid()
|
||||
kwargs = self.render_kwargs()
|
||||
return grids.util.render_grid(grid, **kwargs)
|
Loading…
Add table
Add a link
Reference in a new issue