Add Family and Product.family to the general grid/crud UI.

This commit is contained in:
Lance Edgar 2014-04-13 00:04:30 -07:00
parent e4ef46d4fc
commit 087342b09c
5 changed files with 141 additions and 0 deletions

View file

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

View file

@ -0,0 +1,11 @@
<%inherit file="/grid.mako" />
<%def name="title()">Families</%def>
<%def name="context_menu_items()">
% if request.has_perm('families.create'):
<li>${h.link_to("Create a new Family", url('family.create'))}</li>
% endif
</%def>
${parent.body()}

View file

@ -58,6 +58,7 @@ def includeme(config):
config.include('tailbone.views.customers') config.include('tailbone.views.customers')
config.include('tailbone.views.departments') config.include('tailbone.views.departments')
config.include('tailbone.views.employees') config.include('tailbone.views.employees')
config.include('tailbone.views.families')
config.include('tailbone.views.labels') config.include('tailbone.views.labels')
config.include('tailbone.views.people') config.include('tailbone.views.people')
config.include('tailbone.views.products') config.include('tailbone.views.products')

113
tailbone/views/families.py Normal file
View file

@ -0,0 +1,113 @@
#!/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 <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Family Views
"""
from . import SearchableAlchemyGridView, CrudView
from rattail.db import model
class FamiliesGrid(SearchableAlchemyGridView):
mapped_class = model.Family
config_prefix = 'families'
sort = 'name'
def filter_map(self):
return self.make_filter_map(
exact=['code'],
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('code', 'name')
def grid(self):
g = self.make_grid()
g.configure(
include=[
g.code,
g.name,
],
readonly=True)
if self.request.has_perm('families.read'):
g.viewable = True
g.view_route_name = 'family.read'
if self.request.has_perm('families.update'):
g.editable = True
g.edit_route_name = 'family.update'
if self.request.has_perm('families.delete'):
g.deletable = True
g.delete_route_name = 'family.delete'
return g
class FamilyCrud(CrudView):
mapped_class = model.Family
home_route = 'families'
def fieldset(self, model):
fs = self.make_fieldset(model)
fs.configure(
include=[
fs.code,
fs.name,
])
return fs
def add_routes(config):
config.add_route('families', '/families')
config.add_route('family.create', '/families/new')
config.add_route('family.read', '/families/{uuid}')
config.add_route('family.update', '/families/{uuid}/edit')
config.add_route('family.delete', '/families/{uuid}/delete')
def includeme(config):
add_routes(config)
config.add_view(FamiliesGrid, route_name='families',
renderer='/families/index.mako',
permission='families.list')
config.add_view(FamilyCrud, attr='create', route_name='family.create',
renderer='/families/crud.mako',
permission='families.create')
config.add_view(FamilyCrud, attr='read', route_name='family.read',
renderer='/families/crud.mako',
permission='families.read')
config.add_view(FamilyCrud, attr='update', route_name='family.update',
renderer='/families/crud.mako',
permission='families.update')
config.add_view(FamilyCrud, attr='delete', route_name='family.delete',
permission='families.delete')

View file

@ -42,6 +42,7 @@ from rattail import sil
from rattail import batches from rattail import batches
from rattail.threads import Thread from rattail.threads import Thread
from rattail.exceptions import LabelPrintingError from rattail.exceptions import LabelPrintingError
from rattail.db import model
from rattail.db.model import ( from rattail.db.model import (
Product, ProductPrice, ProductCost, ProductCode, Product, ProductPrice, ProductCost, ProductCode,
Brand, Vendor, Department, Subdepartment, LabelProfile) Brand, Vendor, Department, Subdepartment, LabelProfile)
@ -90,6 +91,8 @@ class ProductsGrid(SearchableAlchemyGridView):
return { return {
'brand': 'brand':
lambda q: q.outerjoin(Brand), lambda q: q.outerjoin(Brand),
'family':
lambda q: q.outerjoin(model.Family),
'department': 'department':
lambda q: q.outerjoin(Department, lambda q: q.outerjoin(Department,
Department.uuid == Product.department_uuid), Department.uuid == Product.department_uuid),
@ -138,6 +141,7 @@ class ProductsGrid(SearchableAlchemyGridView):
ilike=['description', 'size'], ilike=['description', 'size'],
upc=filter_upc(), upc=filter_upc(),
brand=self.filter_ilike(Brand.name), brand=self.filter_ilike(Brand.name),
family=self.filter_ilike(model.Family.name),
department=self.filter_ilike(Department.name), department=self.filter_ilike(Department.name),
subdepartment=self.filter_ilike(Subdepartment.name), subdepartment=self.filter_ilike(Subdepartment.name),
vendor=self.filter_ilike(Vendor.name), vendor=self.filter_ilike(Vendor.name),