From ef2fb3d66c94abdcc9b5cbea5bd794aeb980d2fa Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 24 Sep 2012 15:39:35 -0700 Subject: [PATCH] add Vendor CRUD --- rattail/pyramid/templates/vendors/crud.mako | 12 +++++ rattail/pyramid/templates/vendors/index.mako | 6 +++ rattail/pyramid/views/vendors.py | 47 +++++++++++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 rattail/pyramid/templates/vendors/crud.mako diff --git a/rattail/pyramid/templates/vendors/crud.mako b/rattail/pyramid/templates/vendors/crud.mako new file mode 100644 index 00000000..a60036d9 --- /dev/null +++ b/rattail/pyramid/templates/vendors/crud.mako @@ -0,0 +1,12 @@ +<%inherit file="/crud.mako" /> + +<%def name="context_menu_items()"> +
  • ${h.link_to("Back to Vendors", url('vendors'))}
  • + % if form.readonly: +
  • ${h.link_to("Edit this Vendor", url('vendor.update', uuid=form.fieldset.model.uuid))}
  • + % elif form.updating: +
  • ${h.link_to("View this Vendor", url('vendor.read', uuid=form.fieldset.model.uuid))}
  • + % endif + + +${parent.body()} diff --git a/rattail/pyramid/templates/vendors/index.mako b/rattail/pyramid/templates/vendors/index.mako index e0e9c0d1..62d69078 100644 --- a/rattail/pyramid/templates/vendors/index.mako +++ b/rattail/pyramid/templates/vendors/index.mako @@ -2,4 +2,10 @@ <%def name="title()">Vendors +<%def name="context_menu_items()"> + % if request.has_perm('vendors.create'): +
  • ${h.link_to("Create a new Vendor", url('vendor.create'))}
  • + % endif + + ${parent.body()} diff --git a/rattail/pyramid/views/vendors.py b/rattail/pyramid/views/vendors.py index 8962f18f..2685f398 100644 --- a/rattail/pyramid/views/vendors.py +++ b/rattail/pyramid/views/vendors.py @@ -26,7 +26,8 @@ ``rattail.pyramid.views.vendors`` -- Vendor Views """ -from edbob.pyramid.views import SearchableAlchemyGridView, AutocompleteView +from edbob.pyramid.views import (SearchableAlchemyGridView, CrudView, + AutocompleteView) import rattail @@ -59,9 +60,34 @@ class VendorsGrid(SearchableAlchemyGridView): g.contact, ], readonly=True) + if self.request.has_perm('vendors.read'): + g.clickable = True + g.click_route_name = 'vendor.read' + if self.request.has_perm('vendors.update'): + g.editable = True + g.edit_route_name = 'vendor.update' + if self.request.has_perm('vendors.delete'): + g.deletable = True + g.delete_route_name = 'vendor.delete' return g +class VendorCrud(CrudView): + + mapped_class = rattail.Vendor + home_route = 'vendors' + + def fieldset(self, model): + fs = self.make_fieldset(model) + fs.configure( + include=[ + fs.id.label("ID"), + fs.name, + fs.special_discount, + ]) + return fs + + class VendorsAutocomplete(AutocompleteView): mapped_class = rattail.Vendor @@ -78,3 +104,22 @@ def includeme(config): config.add_route('vendors.autocomplete', '/vendors/autocomplete') config.add_view(VendorsAutocomplete, route_name='vendors.autocomplete', renderer='json', permission='vendors.list') + + config.add_route('vendor.create', '/vendors/new') + config.add_view(VendorCrud, attr='create', route_name='vendor.create', + renderer='/vendors/crud.mako', + permission='vendors.create') + + config.add_route('vendor.read', '/vendors/{uuid}') + config.add_view(VendorCrud, attr='read', route_name='vendor.read', + renderer='/vendors/crud.mako', + permission='vendors.read') + + config.add_route('vendor.update', '/vendors/{uuid}/edit') + config.add_view(VendorCrud, attr='update', route_name='vendor.update', + renderer='/vendors/crud.mako', + permission='vendors.update') + + config.add_route('vendor.delete', '/vendors/{uuid}/delete') + config.add_view(VendorCrud, attr='delete', route_name='vendor.delete', + permission='vendors.delete')