add various CRUD things

This commit is contained in:
Lance Edgar 2012-11-18 08:38:11 -08:00
parent 704907fe59
commit b290a25691
11 changed files with 191 additions and 16 deletions

View file

@ -47,7 +47,7 @@ class GPCFieldRenderer(formalchemy.TextFieldRenderer):
return len(str(GPC(0))) return len(str(GPC(0)))
class PriceFieldRenderer(formalchemy.FieldRenderer): class PriceFieldRenderer(formalchemy.TextFieldRenderer):
""" """
Renderer for fields which reference a :class:`ProductPrice` instance. Renderer for fields which reference a :class:`ProductPrice` instance.
""" """

View file

@ -0,0 +1,12 @@
<%inherit file="/crud.mako" />
<%def name="context_menu_items()">
<li>${h.link_to("Back to Departments", url('departments'))}</li>
% if form.readonly:
<li>${h.link_to("Edit this Department", url('department.update', uuid=form.fieldset.model.uuid))}</li>
% elif form.updating:
<li>${h.link_to("View this Department", url('department.read', uuid=form.fieldset.model.uuid))}</li>
% endif
</%def>
${parent.body()}

View file

@ -2,4 +2,10 @@
<%def name="title()">Departments</%def> <%def name="title()">Departments</%def>
<%def name="context_menu_items()">
% if request.has_perm('departments.create'):
<li>${h.link_to("Create a new Department", url('department.create'))}</li>
% endif
</%def>
${parent.body()} ${parent.body()}

View file

@ -2,6 +2,11 @@
<%def name="context_menu_items()"> <%def name="context_menu_items()">
<li>${h.link_to("Back to Products", url('products'))}</li> <li>${h.link_to("Back to Products", url('products'))}</li>
% if form.readonly:
<li>${h.link_to("Edit this Product", url('product.update', uuid=form.fieldset.model.uuid))}</li>
% elif form.updating:
<li>${h.link_to("View this Product", url('product.read', uuid=form.fieldset.model.uuid))}</li>
% endif
</%def> </%def>
${parent.body()} ${parent.body()}

View file

@ -96,6 +96,9 @@
</%def> </%def>
<%def name="context_menu_items()"> <%def name="context_menu_items()">
% if request.has_perm('products.create'):
<li>${h.link_to("Create a new Product", url('product.create'))}</li>
% endif
% if request.has_perm('batches.create'): % if request.has_perm('batches.create'):
<li>${h.link_to("Create Batch from Results", url('products.create_batch'))}</li> <li>${h.link_to("Create Batch from Results", url('products.create_batch'))}</li>
% endif % endif

View file

@ -0,0 +1,12 @@
<%inherit file="/crud.mako" />
<%def name="context_menu_items()">
<li>${h.link_to("Back to Subdepartments", url('subdepartments'))}</li>
% if form.readonly:
<li>${h.link_to("Edit this Subdepartment", url('subdepartment.update', uuid=form.fieldset.model.uuid))}</li>
% elif form.updating:
<li>${h.link_to("View this Subdepartment", url('subdepartment.read', uuid=form.fieldset.model.uuid))}</li>
% endif
</%def>
${parent.body()}

View file

@ -2,4 +2,10 @@
<%def name="title()">Subdepartments</%def> <%def name="title()">Subdepartments</%def>
<%def name="context_menu_items()">
% if request.has_perm('subdepartments.create'):
<li>${h.link_to("Create a new Subdepartment", url('subdepartment.create'))}</li>
% endif
</%def>
${parent.body()} ${parent.body()}

View file

@ -91,29 +91,36 @@ class BrandsAutocomplete(AutocompleteView):
def includeme(config): def includeme(config):
config.add_route('brands', '/brands') config.add_route('brands', '/brands')
config.add_view(BrandsGrid, route_name='brands', config.add_view(BrandsGrid,
route_name='brands',
renderer='/brands/index.mako', renderer='/brands/index.mako',
permission='brands.list') permission='brands.list')
config.add_route('brands.autocomplete', '/brands/autocomplete') config.add_route('brands.autocomplete', '/brands/autocomplete')
config.add_view(BrandsAutocomplete, route_name='brands.autocomplete', config.add_view(BrandsAutocomplete,
renderer='json', permission='brands.list') route_name='brands.autocomplete',
renderer='json',
permission='brands.list')
config.add_route('brand.create', '/brands/new') config.add_route('brand.create', '/brands/new')
config.add_view(BrandCrud, attr='create', route_name='brand.create', config.add_view(BrandCrud, attr='create',
route_name='brand.create',
renderer='/brands/crud.mako', renderer='/brands/crud.mako',
permission='brands.create') permission='brands.create')
config.add_route('brand.read', '/brands/{uuid}') config.add_route('brand.read', '/brands/{uuid}')
config.add_view(BrandCrud, attr='read', route_name='brand.read', config.add_view(BrandCrud, attr='read',
route_name='brand.read',
renderer='/brands/crud.mako', renderer='/brands/crud.mako',
permission='brands.read') permission='brands.read')
config.add_route('brand.update', '/brands/{uuid}/edit') config.add_route('brand.update', '/brands/{uuid}/edit')
config.add_view(BrandCrud, attr='update', route_name='brand.update', config.add_view(BrandCrud, attr='update',
route_name='brand.update',
renderer='/brands/crud.mako', renderer='/brands/crud.mako',
permission='brands.update') permission='brands.update')
config.add_route('brand.delete', '/brands/{uuid}/delete') config.add_route('brand.delete', '/brands/{uuid}/delete')
config.add_view(BrandCrud, attr='delete', route_name='brand.delete', config.add_view(BrandCrud, attr='delete',
route_name='brand.delete',
permission='brands.delete') permission='brands.delete')

View file

@ -28,7 +28,7 @@
from edbob.pyramid.views import ( from edbob.pyramid.views import (
SearchableAlchemyGridView, AlchemyGridView, AutocompleteView) SearchableAlchemyGridView, CrudView, AlchemyGridView, AutocompleteView)
import rattail import rattail
@ -58,9 +58,33 @@ class DepartmentsGrid(SearchableAlchemyGridView):
g.name, g.name,
], ],
readonly=True) readonly=True)
if self.request.has_perm('departments.read'):
g.clickable = True
g.click_route_name = 'department.read'
if self.request.has_perm('departments.update'):
g.editable = True
g.edit_route_name = 'department.update'
if self.request.has_perm('departments.delete'):
g.deletable = True
g.delete_route_name = 'department.delete'
return g return g
class DepartmentCrud(CrudView):
mapped_class = rattail.Department
home_route = 'departments'
def fieldset(self, model):
fs = self.make_fieldset(model)
fs.configure(
include=[
fs.number,
fs.name,
])
return fs
class DepartmentsByVendorGrid(AlchemyGridView): class DepartmentsByVendorGrid(AlchemyGridView):
mapped_class = rattail.Department mapped_class = rattail.Department
@ -97,14 +121,41 @@ class DepartmentsAutocomplete(AutocompleteView):
def includeme(config): def includeme(config):
config.add_route('departments', '/departments') config.add_route('departments', '/departments')
config.add_view(DepartmentsGrid, route_name='departments', config.add_view(DepartmentsGrid,
route_name='departments',
renderer='/departments/index.mako', renderer='/departments/index.mako',
permission='departments.list') permission='departments.list')
config.add_route('departments.autocomplete', '/departments/autocomplete') config.add_route('departments.autocomplete', '/departments/autocomplete')
config.add_view(DepartmentsAutocomplete, route_name='departments.autocomplete', config.add_view(DepartmentsAutocomplete,
renderer='json', permission='departments.list') route_name='departments.autocomplete',
renderer='json',
permission='departments.list')
config.add_route('departments.by_vendor', '/departments/by-vendor') config.add_route('departments.by_vendor', '/departments/by-vendor')
config.add_view(DepartmentsByVendorGrid, route_name='departments.by_vendor', config.add_view(DepartmentsByVendorGrid,
route_name='departments.by_vendor',
permission='departments.list') permission='departments.list')
config.add_route('department.create', '/departments/new')
config.add_view(DepartmentCrud, attr='create',
route_name='department.create',
renderer='/departments/crud.mako',
permission='departments.create')
config.add_route('department.read', '/departments/{uuid}')
config.add_view(DepartmentCrud, attr='read',
route_name='department.read',
renderer='/departments/crud.mako',
permission='departments.read')
config.add_route('department.update', '/departments/{uuid}/edit')
config.add_view(DepartmentCrud, attr='update',
route_name='department.update',
renderer='/departments/crud.mako',
permission='departments.update')
config.add_route('department.delete', '/departments/{uuid}/delete')
config.add_view(DepartmentCrud, attr='delete',
route_name='department.delete',
permission='departments.delete')

View file

@ -54,7 +54,6 @@ class ProductsGrid(SearchableAlchemyGridView):
mapped_class = rattail.Product mapped_class = rattail.Product
config_prefix = 'products' config_prefix = 'products'
sort = 'description' sort = 'description'
clickable = True
def join_map(self): def join_map(self):
@ -169,7 +168,15 @@ class ProductsGrid(SearchableAlchemyGridView):
], ],
readonly=True) readonly=True)
g.click_route_name = 'product.read' if self.request.has_perm('products.read'):
g.clickable = True
g.click_route_name = 'product.read'
if self.request.has_perm('products.update'):
g.editable = True
g.edit_route_name = 'product.update'
if self.request.has_perm('products.delete'):
g.deletable = True
g.delete_route_name = 'product.delete'
q = Session.query(rattail.LabelProfile) q = Session.query(rattail.LabelProfile)
if q.count(): if q.count():
@ -207,6 +214,9 @@ class ProductCrud(CrudView):
fs.regular_price, fs.regular_price,
fs.current_price, fs.current_price,
]) ])
# if not self.readonly:
# del fs.regular_price
# del fs.current_price
return fs return fs
@ -319,7 +329,21 @@ def includeme(config):
renderer='/products/batch.mako', renderer='/products/batch.mako',
permission='batches.create') permission='batches.create')
config.add_route('product.create', '/products/new')
config.add_view(ProductCrud, attr='create', route_name='product.create',
renderer='/products/crud.mako',
permission='products.create')
config.add_route('product.read', '/products/{uuid}') config.add_route('product.read', '/products/{uuid}')
config.add_view(ProductCrud, attr='read', route_name='product.read', config.add_view(ProductCrud, attr='read', route_name='product.read',
renderer='/products/read.mako', renderer='/products/read.mako',
permission='products.read') permission='products.read')
config.add_route('product.update', '/products/{uuid}/edit')
config.add_view(ProductCrud, attr='update', route_name='product.update',
renderer='/products/crud.mako',
permission='products.update')
config.add_route('product.delete', '/products/{uuid}/delete')
config.add_view(ProductCrud, attr='delete', route_name='product.delete',
permission='products.delete')

View file

@ -26,7 +26,7 @@
``rattail.pyramid.views.subdepartments`` -- Subdepartment Views ``rattail.pyramid.views.subdepartments`` -- Subdepartment Views
""" """
from edbob.pyramid.views import SearchableAlchemyGridView from edbob.pyramid.views import SearchableAlchemyGridView, CrudView
import rattail import rattail
@ -54,14 +54,63 @@ class SubdepartmentsGrid(SearchableAlchemyGridView):
include=[ include=[
g.number, g.number,
g.name, g.name,
g.department,
], ],
readonly=True) readonly=True)
if self.request.has_perm('subdepartments.read'):
g.clickable = True
g.click_route_name = 'subdepartment.read'
if self.request.has_perm('subdepartments.update'):
g.editable = True
g.edit_route_name = 'subdepartment.update'
if self.request.has_perm('subdepartments.delete'):
g.deletable = True
g.delete_route_name = 'subdepartment.delete'
return g return g
class SubdepartmentCrud(CrudView):
mapped_class = rattail.Subdepartment
home_route = 'subdepartments'
def fieldset(self, model):
fs = self.make_fieldset(model)
fs.configure(
include=[
fs.number,
fs.name,
fs.department,
])
return fs
def includeme(config): def includeme(config):
config.add_route('subdepartments', '/subdepartments') config.add_route('subdepartments', '/subdepartments')
config.add_view(SubdepartmentsGrid, route_name='subdepartments', config.add_view(SubdepartmentsGrid, route_name='subdepartments',
renderer='/subdepartments/index.mako', renderer='/subdepartments/index.mako',
permission='subdepartments.list') permission='subdepartments.list')
config.add_route('subdepartment.create', '/subdepartments/new')
config.add_view(SubdepartmentCrud, attr='create',
route_name='subdepartment.create',
renderer='/subdepartments/crud.mako',
permission='subdepartments.create')
config.add_route('subdepartment.read', '/subdepartments/{uuid}')
config.add_view(SubdepartmentCrud, attr='read',
route_name='subdepartment.read',
renderer='/subdepartments/crud.mako',
permission='subdepartments.read')
config.add_route('subdepartment.update', '/subdepartments/{uuid}/edit')
config.add_view(SubdepartmentCrud, attr='update',
route_name='subdepartment.update',
renderer='/subdepartments/crud.mako',
permission='subdepartments.update')
config.add_route('subdepartment.delete', '/subdepartments/{uuid}/delete')
config.add_view(SubdepartmentCrud, attr='delete',
route_name='subdepartment.delete',
permission='subdepartments.delete')