add Vendor CRUD
This commit is contained in:
parent
4bd4c9647e
commit
ef2fb3d66c
12
rattail/pyramid/templates/vendors/crud.mako
vendored
Normal file
12
rattail/pyramid/templates/vendors/crud.mako
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
<%inherit file="/crud.mako" />
|
||||
|
||||
<%def name="context_menu_items()">
|
||||
<li>${h.link_to("Back to Vendors", url('vendors'))}</li>
|
||||
% if form.readonly:
|
||||
<li>${h.link_to("Edit this Vendor", url('vendor.update', uuid=form.fieldset.model.uuid))}</li>
|
||||
% elif form.updating:
|
||||
<li>${h.link_to("View this Vendor", url('vendor.read', uuid=form.fieldset.model.uuid))}</li>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
${parent.body()}
|
6
rattail/pyramid/templates/vendors/index.mako
vendored
6
rattail/pyramid/templates/vendors/index.mako
vendored
|
@ -2,4 +2,10 @@
|
|||
|
||||
<%def name="title()">Vendors</%def>
|
||||
|
||||
<%def name="context_menu_items()">
|
||||
% if request.has_perm('vendors.create'):
|
||||
<li>${h.link_to("Create a new Vendor", url('vendor.create'))}</li>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
${parent.body()}
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue