diff --git a/rattail/pyramid/templates/brands/crud.mako b/rattail/pyramid/templates/brands/crud.mako new file mode 100644 index 00000000..4da3d733 --- /dev/null +++ b/rattail/pyramid/templates/brands/crud.mako @@ -0,0 +1,12 @@ +<%inherit file="/crud.mako" /> + +<%def name="context_menu_items()"> +
  • ${h.link_to("Back to Brands", url('brands'))}
  • + % if form.readonly: +
  • ${h.link_to("Edit this Brand", url('brand.update', uuid=form.fieldset.model.uuid))}
  • + % elif form.updating: +
  • ${h.link_to("View this Brand", url('brand.read', uuid=form.fieldset.model.uuid))}
  • + % endif + + +${parent.body()} diff --git a/rattail/pyramid/templates/brands/index.mako b/rattail/pyramid/templates/brands/index.mako new file mode 100644 index 00000000..eff4ce0a --- /dev/null +++ b/rattail/pyramid/templates/brands/index.mako @@ -0,0 +1,11 @@ +<%inherit file="/grid.mako" /> + +<%def name="title()">Brands + +<%def name="context_menu_items()"> + % if request.has_perm('brands.create'): +
  • ${h.link_to("Create a new Brand", url('brand.create'))}
  • + % endif + + +${parent.body()} diff --git a/rattail/pyramid/views/brands.py b/rattail/pyramid/views/brands.py new file mode 100644 index 00000000..247fe15b --- /dev/null +++ b/rattail/pyramid/views/brands.py @@ -0,0 +1,108 @@ +#!/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 . +# +################################################################################ + +""" +``rattail.pyramid.views.brands`` -- Brand Views +""" + +from edbob.pyramid.views import SearchableAlchemyGridView, CrudView + +import rattail + + +class BrandsGrid(SearchableAlchemyGridView): + + mapped_class = rattail.Brand + config_prefix = 'brands' + sort = 'name' + + def filter_map(self): + return self.make_filter_map(ilike=['name']) + + def filter_config(self): + return self.make_filter_config( + include_filter_name=True, + filter_type_name='lk') + + def sort_map(self): + return self.make_sort_map('name') + + def grid(self): + g = self.make_grid() + g.configure( + include=[ + g.name, + ], + readonly=True) + if self.request.has_perm('brands.read'): + g.clickable = True + g.click_route_name = 'brand.read' + if self.request.has_perm('brands.update'): + g.editable = True + g.edit_route_name = 'brand.update' + if self.request.has_perm('brands.delete'): + g.deletable = True + g.delete_route_name = 'brand.delete' + return g + + +class BrandCrud(CrudView): + + mapped_class = rattail.Brand + home_route = 'brands' + + def fieldset(self, model): + fs = self.make_fieldset(model) + fs.configure( + include=[ + fs.name, + ]) + return fs + + +def includeme(config): + + config.add_route('brands', '/brands') + config.add_view(BrandsGrid, route_name='brands', + renderer='/brands/index.mako', + permission='brands.list') + + config.add_route('brand.create', '/brands/new') + config.add_view(BrandCrud, attr='create', route_name='brand.create', + renderer='/brands/crud.mako', + permission='brands.create') + + config.add_route('brand.read', '/brands/{uuid}') + config.add_view(BrandCrud, attr='read', route_name='brand.read', + renderer='/brands/crud.mako', + permission='brands.read') + + config.add_route('brand.update', '/brands/{uuid}/edit') + config.add_view(BrandCrud, attr='update', route_name='brand.update', + renderer='/brands/crud.mako', + permission='brands.update') + + config.add_route('brand.delete', '/brands/{uuid}/delete') + config.add_view(BrandCrud, attr='delete', route_name='brand.delete', + permission='brands.delete')