From 1c280f80626acd6073979385c132880cccf42239 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 9 Oct 2012 16:05:26 -0700 Subject: [PATCH] update category views --- .../pyramid/templates/categories/base.mako | 2 - .../pyramid/templates/categories/crud.mako | 10 +-- .../pyramid/templates/categories/edit.mako | 2 - .../pyramid/templates/categories/index.mako | 5 +- rattail/pyramid/templates/categories/new.mako | 2 - rattail/pyramid/views/categories.py | 70 ++++++++++++------- 6 files changed, 54 insertions(+), 37 deletions(-) delete mode 100644 rattail/pyramid/templates/categories/base.mako delete mode 100644 rattail/pyramid/templates/categories/edit.mako delete mode 100644 rattail/pyramid/templates/categories/new.mako 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 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 ${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 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 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')