tailbone/rattail/pyramid/views/departments.py

118 lines
3.5 KiB
Python
Raw Normal View History

2012-04-10 22:28:02 -05:00
#!/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
"""
# import transaction
# from pyramid.httpexceptions import HTTPFound
# from pyramid.view import view_config
2012-04-10 22:28:02 -05:00
# from edbob.pyramid import Session
from edbob.pyramid.views import SearchableAlchemyGridView, AlchemyGridView
2012-04-10 22:28:02 -05:00
import rattail
# @view_config(route_name='department.delete')
# def delete_department(context, request):
# uuid = request.matchdict['uuid']
# dept = Session.query(rattail.Department).get(uuid) if uuid else None
# assert dept
# with transaction.manager:
# q = Session.query(rattail.Product)
# q = q.filter(rattail.Product.department_uuid == dept.uuid)
# if q.count():
# q.update({'department_uuid': None}, synchronize_session=False)
# Session.delete(dept)
# return HTTPFound(location=request.route_url('departments.list'))
class DepartmentsGrid(SearchableAlchemyGridView):
mapped_class = rattail.Department
route_name = 'departments'
route_url = '/departments'
renderer = '/departments/index.mako'
permission = 'departments.list'
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
route_name = 'departments.by_vendor'
route_url = '/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)
2012-04-10 22:28:02 -05:00
return q
def grid(self):
g = self.make_grid()
g.configure(
include=[
g.name,
],
readonly=True)
return g
2012-04-16 00:51:12 -05:00
2012-04-10 22:28:02 -05:00
def includeme(config):
# config.add_route('department.delete', '/department/{uuid}/delete')
# config.scan(__name__)
DepartmentsGrid.add_route(config)
DepartmentsByVendorGrid.add_route(config)