tailbone/rattail/pyramid/views/departments.py
2012-10-04 08:40:27 -07:00

111 lines
3.2 KiB
Python

#!/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/>.
#
################################################################################
"""
``rattail.pyramid.views.departments`` -- Department Views
"""
from edbob.pyramid.views import (
SearchableAlchemyGridView, AlchemyGridView, AutocompleteView)
import rattail
class DepartmentsGrid(SearchableAlchemyGridView):
mapped_class = rattail.Department
config_prefix = 'departments'
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('number', 'name')
def grid(self):
g = self.make_grid()
g.configure(
include=[
g.number,
g.name,
],
readonly=True)
return g
class DepartmentsByVendorGrid(AlchemyGridView):
mapped_class = rattail.Department
config_prefix = 'departments.by_vendor'
checkboxes = True
partial_only = True
def query(self):
q = self.make_query()
q = q.outerjoin(rattail.Product)
q = q.join(rattail.ProductCost)
q = q.join(rattail.Vendor)
q = q.filter(rattail.Vendor.uuid == self.request.params['uuid'])
q = q.distinct()
q = q.order_by(rattail.Department.name)
return q
def grid(self):
g = self.make_grid()
g.configure(
include=[
g.name,
],
readonly=True)
return g
class DepartmentsAutocomplete(AutocompleteView):
mapped_class = rattail.Department
fieldname = 'name'
def includeme(config):
config.add_route('departments', '/departments')
config.add_view(DepartmentsGrid, route_name='departments',
renderer='/departments/index.mako',
permission='departments.list')
config.add_route('departments.autocomplete', '/departments/autocomplete')
config.add_view(DepartmentsAutocomplete, route_name='departments.autocomplete',
renderer='json', permission='departments.list')
config.add_route('departments.by_vendor', '/departments/by-vendor')
config.add_view(DepartmentsByVendorGrid, route_name='departments.by_vendor',
permission='departments.list')