diff --git a/rattail/pyramid/templates/categories/base.mako b/rattail/pyramid/templates/categories/base.mako
deleted file mode 100644
index 27f7dd90..00000000
--- a/rattail/pyramid/templates/categories/base.mako
+++ /dev/null
@@ -1,2 +0,0 @@
-<%inherit file="/base.mako" />
-${parent.body()}
diff --git a/rattail/pyramid/templates/categories/crud.mako b/rattail/pyramid/templates/categories/crud.mako
index 1e373321..8a36d063 100644
--- a/rattail/pyramid/templates/categories/crud.mako
+++ b/rattail/pyramid/templates/categories/crud.mako
@@ -1,10 +1,12 @@
-<%inherit file="/categories/base.mako" />
<%inherit file="/crud.mako" />
-<%def name="crud_name()">Category%def>
-
<%def name="context_menu_items()">
-
${h.link_to("Back to Categories", url('categories.list'))}
+ ${h.link_to("Back to Categories", url('categories'))}
+ % if form.readonly:
+ ${h.link_to("Edit this Category", url('category.update', uuid=form.fieldset.model.uuid))}
+ % elif form.updating:
+ ${h.link_to("View this Category", url('category.read', uuid=form.fieldset.model.uuid))}
+ % endif
%def>
${parent.body()}
diff --git a/rattail/pyramid/templates/categories/edit.mako b/rattail/pyramid/templates/categories/edit.mako
deleted file mode 100644
index 590cf3bb..00000000
--- a/rattail/pyramid/templates/categories/edit.mako
+++ /dev/null
@@ -1,2 +0,0 @@
-<%inherit file="/categories/crud.mako" />
-${parent.body()}
diff --git a/rattail/pyramid/templates/categories/index.mako b/rattail/pyramid/templates/categories/index.mako
index 3389f3b7..03591137 100644
--- a/rattail/pyramid/templates/categories/index.mako
+++ b/rattail/pyramid/templates/categories/index.mako
@@ -1,11 +1,10 @@
-<%inherit file="/categories/base.mako" />
-<%inherit file="/index.mako" />
+<%inherit file="/grid.mako" />
<%def name="title()">Categories%def>
<%def name="context_menu_items()">
% if request.has_perm('categories.create'):
- ${h.link_to("Create a new Category", url('category.new'))}
+ ${h.link_to("Create a new Category", url('category.create'))}
% endif
%def>
diff --git a/rattail/pyramid/templates/categories/new.mako b/rattail/pyramid/templates/categories/new.mako
deleted file mode 100644
index 590cf3bb..00000000
--- a/rattail/pyramid/templates/categories/new.mako
+++ /dev/null
@@ -1,2 +0,0 @@
-<%inherit file="/categories/crud.mako" />
-${parent.body()}
diff --git a/rattail/pyramid/views/categories.py b/rattail/pyramid/views/categories.py
index 51c6b6ec..166adc8b 100644
--- a/rattail/pyramid/views/categories.py
+++ b/rattail/pyramid/views/categories.py
@@ -26,55 +26,55 @@
``rattail.pyramid.views.categories`` -- Category Views
"""
-from edbob.pyramid.views import GridView
-from edbob.pyramid.views.crud import Crud
+from edbob.pyramid.views import SearchableAlchemyGridView, CrudView
import rattail
-class CategoryGrid(GridView):
+class CategoriesGrid(SearchableAlchemyGridView):
mapped_class = rattail.Category
- route_name = 'categories.list'
- route_prefix = 'category'
+ config_prefix = 'categories'
+ sort = 'number'
def filter_map(self):
- return self.make_filter_map(
- exact=['number'],
- ilike=['name'])
+ return self.make_filter_map(exact=['number'], ilike=['name'])
- def search_config(self, fmap):
- return self.make_search_config(
- fmap,
+ def filter_config(self):
+ return self.make_filter_config(
include_filter_name=True,
filter_type_name='lk')
- def grid_config(self, search, fmap):
- return self.make_grid_config(search, fmap,
- sort='number')
-
def sort_map(self):
return self.make_sort_map('number', 'name')
- def grid(self, data, config):
- g = self.make_grid(data, config)
+ def grid(self):
+ g = self.make_grid()
g.configure(
include=[
g.number,
g.name,
],
readonly=True)
+ if self.request.has_perm('categories.read'):
+ g.clickable = True
+ g.click_route_name = 'category.read'
+ if self.request.has_perm('categories.update'):
+ g.editable = True
+ g.edit_route_name = 'category.update'
+ if self.request.has_perm('categories.delete'):
+ g.deletable = True
+ g.delete_route_name = 'category.delete'
return g
-class CategoryCrud(Crud):
+class CategoryCrud(CrudView):
mapped_class = rattail.Category
- home_route = 'categories.list'
- url_prefix = '/categories'
+ home_route = 'categories'
- def fieldset(self, obj):
- fs = self.make_fieldset(obj)
+ def fieldset(self, model):
+ fs = self.make_fieldset(model)
fs.configure(
include=[
fs.number,
@@ -84,5 +84,27 @@ class CategoryCrud(Crud):
def includeme(config):
- CategoryGrid.add_route(config, 'categories.list', '/categories')
- CategoryCrud.add_routes(config)
+
+ config.add_route('categories', '/categories')
+ config.add_view(CategoriesGrid, route_name='categories',
+ renderer='/categories/index.mako',
+ permission='categories.list')
+
+ config.add_route('category.create', '/categories/new')
+ config.add_view(CategoryCrud, attr='create', route_name='category.create',
+ renderer='/categories/crud.mako',
+ permission='categories.create')
+
+ config.add_route('category.read', '/categories/{uuid}')
+ config.add_view(CategoryCrud, attr='read', route_name='category.read',
+ renderer='/categories/crud.mako',
+ permission='categories.read')
+
+ config.add_route('category.update', '/categories/{uuid}/edit')
+ config.add_view(CategoryCrud, attr='update', route_name='category.update',
+ renderer='/categories/crud.mako',
+ permission='categories.update')
+
+ config.add_route('category.delete', '/categories/{uuid}/delete')
+ config.add_view(CategoryCrud, attr='delete', route_name='category.delete',
+ permission='categories.delete')