update category views

This commit is contained in:
Lance Edgar 2012-10-09 16:05:26 -07:00
parent fd19661132
commit 1c280f8062
6 changed files with 54 additions and 37 deletions

View file

@ -1,2 +0,0 @@
<%inherit file="/base.mako" />
${parent.body()}

View file

@ -1,10 +1,12 @@
<%inherit file="/categories/base.mako" />
<%inherit file="/crud.mako" /> <%inherit file="/crud.mako" />
<%def name="crud_name()">Category</%def>
<%def name="context_menu_items()"> <%def name="context_menu_items()">
<li>${h.link_to("Back to Categories", url('categories.list'))}</li> <li>${h.link_to("Back to Categories", url('categories'))}</li>
% if form.readonly:
<li>${h.link_to("Edit this Category", url('category.update', uuid=form.fieldset.model.uuid))}</li>
% elif form.updating:
<li>${h.link_to("View this Category", url('category.read', uuid=form.fieldset.model.uuid))}</li>
% endif
</%def> </%def>
${parent.body()} ${parent.body()}

View file

@ -1,2 +0,0 @@
<%inherit file="/categories/crud.mako" />
${parent.body()}

View file

@ -1,11 +1,10 @@
<%inherit file="/categories/base.mako" /> <%inherit file="/grid.mako" />
<%inherit file="/index.mako" />
<%def name="title()">Categories</%def> <%def name="title()">Categories</%def>
<%def name="context_menu_items()"> <%def name="context_menu_items()">
% if request.has_perm('categories.create'): % if request.has_perm('categories.create'):
<li>${h.link_to("Create a new Category", url('category.new'))}</li> <li>${h.link_to("Create a new Category", url('category.create'))}</li>
% endif % endif
</%def> </%def>

View file

@ -1,2 +0,0 @@
<%inherit file="/categories/crud.mako" />
${parent.body()}

View file

@ -26,55 +26,55 @@
``rattail.pyramid.views.categories`` -- Category Views ``rattail.pyramid.views.categories`` -- Category Views
""" """
from edbob.pyramid.views import GridView from edbob.pyramid.views import SearchableAlchemyGridView, CrudView
from edbob.pyramid.views.crud import Crud
import rattail import rattail
class CategoryGrid(GridView): class CategoriesGrid(SearchableAlchemyGridView):
mapped_class = rattail.Category mapped_class = rattail.Category
route_name = 'categories.list' config_prefix = 'categories'
route_prefix = 'category' sort = 'number'
def filter_map(self): def filter_map(self):
return self.make_filter_map( return self.make_filter_map(exact=['number'], ilike=['name'])
exact=['number'],
ilike=['name'])
def search_config(self, fmap): def filter_config(self):
return self.make_search_config( return self.make_filter_config(
fmap,
include_filter_name=True, include_filter_name=True,
filter_type_name='lk') filter_type_name='lk')
def grid_config(self, search, fmap):
return self.make_grid_config(search, fmap,
sort='number')
def sort_map(self): def sort_map(self):
return self.make_sort_map('number', 'name') return self.make_sort_map('number', 'name')
def grid(self, data, config): def grid(self):
g = self.make_grid(data, config) g = self.make_grid()
g.configure( g.configure(
include=[ include=[
g.number, g.number,
g.name, g.name,
], ],
readonly=True) 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 return g
class CategoryCrud(Crud): class CategoryCrud(CrudView):
mapped_class = rattail.Category mapped_class = rattail.Category
home_route = 'categories.list' home_route = 'categories'
url_prefix = '/categories'
def fieldset(self, obj): def fieldset(self, model):
fs = self.make_fieldset(obj) fs = self.make_fieldset(model)
fs.configure( fs.configure(
include=[ include=[
fs.number, fs.number,
@ -84,5 +84,27 @@ class CategoryCrud(Crud):
def includeme(config): 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')