Cleanup some view modules per conventions etc.

Mainly this makes extending them easier..
This commit is contained in:
Lance Edgar 2015-02-09 13:30:29 -06:00
parent eedbc5fb9a
commit 0455e472f5
3 changed files with 82 additions and 96 deletions

View file

@ -1,9 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2012 Lance Edgar # Copyright © 2010-2015 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -21,15 +20,16 @@
# along with Rattail. If not, see <http://www.gnu.org/licenses/>. # along with Rattail. If not, see <http://www.gnu.org/licenses/>.
# #
################################################################################ ################################################################################
""" """
Category Views Category Views
""" """
from . import SearchableAlchemyGridView, CrudView from __future__ import unicode_literals
from rattail.db.model import Category from rattail.db.model import Category
from . import SearchableAlchemyGridView, CrudView
class CategoriesGrid(SearchableAlchemyGridView): class CategoriesGrid(SearchableAlchemyGridView):
@ -85,28 +85,27 @@ class CategoryCrud(CrudView):
return fs return fs
def includeme(config): def add_routes(config):
config.add_route('categories', '/categories') config.add_route('categories', '/categories')
config.add_view(CategoriesGrid, route_name='categories',
renderer='/categories/index.mako',
permission='categories.list')
config.add_route('category.create', '/categories/new') config.add_route('category.create', '/categories/new')
config.add_view(CategoryCrud, attr='create', route_name='category.create',
renderer='/categories/crud.mako',
permission='categories.create')
config.add_route('category.read', '/categories/{uuid}') config.add_route('category.read', '/categories/{uuid}')
config.add_view(CategoryCrud, attr='read', route_name='category.read',
renderer='/categories/crud.mako',
permission='categories.read')
config.add_route('category.update', '/categories/{uuid}/edit') config.add_route('category.update', '/categories/{uuid}/edit')
config.add_view(CategoryCrud, attr='update', route_name='category.update',
renderer='/categories/crud.mako',
permission='categories.update')
config.add_route('category.delete', '/categories/{uuid}/delete') config.add_route('category.delete', '/categories/{uuid}/delete')
def includeme(config):
add_routes(config)
# list
config.add_view(CategoriesGrid, route_name='categories',
renderer='/categories/index.mako', permission='categories.list')
# crud
config.add_view(CategoryCrud, attr='create', route_name='category.create',
renderer='/categories/crud.mako', permission='categories.create')
config.add_view(CategoryCrud, attr='read', route_name='category.read',
renderer='/categories/crud.mako', permission='categories.read')
config.add_view(CategoryCrud, attr='update', route_name='category.update',
renderer='/categories/crud.mako', permission='categories.update')
config.add_view(CategoryCrud, attr='delete', route_name='category.delete', config.add_view(CategoryCrud, attr='delete', route_name='category.delete',
permission='categories.delete') permission='categories.delete')

View file

@ -1,9 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2012 Lance Edgar # Copyright © 2010-2015 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -21,16 +20,16 @@
# along with Rattail. If not, see <http://www.gnu.org/licenses/>. # along with Rattail. If not, see <http://www.gnu.org/licenses/>.
# #
################################################################################ ################################################################################
""" """
Department Views Department Views
""" """
from __future__ import unicode_literals
from . import SearchableAlchemyGridView, CrudView, AlchemyGridView, AutocompleteView
from rattail.db.model import Department, Product, ProductCost, Vendor from rattail.db.model import Department, Product, ProductCost, Vendor
from . import SearchableAlchemyGridView, CrudView, AlchemyGridView, AutocompleteView
class DepartmentsGrid(SearchableAlchemyGridView): class DepartmentsGrid(SearchableAlchemyGridView):
@ -117,44 +116,37 @@ class DepartmentsAutocomplete(AutocompleteView):
fieldname = 'name' fieldname = 'name'
def includeme(config): def add_routes(config):
config.add_route('departments', '/departments') 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_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_route('departments.by_vendor', '/departments/by-vendor')
config.add_view(DepartmentsByVendorGrid, config.add_route('department.create', '/departments/new')
route_name='departments.by_vendor', config.add_route('department.read', '/departments/{uuid}')
config.add_route('department.update', '/departments/{uuid}/edit')
config.add_route('department.delete', '/departments/{uuid}/delete')
def includeme(config):
add_routes(config)
# list
config.add_view(DepartmentsGrid, route_name='departments',
renderer='/departments/index.mako', permission='departments.list')
# autocomplete
config.add_view(DepartmentsAutocomplete, route_name='departments.autocomplete',
renderer='json', permission='departments.list')
# departments by vendor list
config.add_view(DepartmentsByVendorGrid,route_name='departments.by_vendor',
permission='departments.list') permission='departments.list')
config.add_route('department.create', '/departments/new') # crud
config.add_view(DepartmentCrud, attr='create', config.add_view(DepartmentCrud, attr='create', route_name='department.create',
route_name='department.create', renderer='/departments/crud.mako', permission='departments.create')
renderer='/departments/crud.mako', config.add_view(DepartmentCrud, attr='read', route_name='department.read',
permission='departments.create') renderer='/departments/crud.mako', permission='departments.read')
config.add_view(DepartmentCrud, attr='update', route_name='department.update',
config.add_route('department.read', '/departments/{uuid}') renderer='/departments/crud.mako', permission='departments.update')
config.add_view(DepartmentCrud, attr='read', config.add_view(DepartmentCrud, attr='delete', route_name='department.delete',
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') permission='departments.delete')

View file

@ -1,9 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2012 Lance Edgar # Copyright © 2010-2015 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -21,15 +20,16 @@
# along with Rattail. If not, see <http://www.gnu.org/licenses/>. # along with Rattail. If not, see <http://www.gnu.org/licenses/>.
# #
################################################################################ ################################################################################
""" """
Subdepartment Views Subdepartment Views
""" """
from . import SearchableAlchemyGridView, CrudView from __future__ import unicode_literals
from rattail.db.model import Subdepartment from rattail.db.model import Subdepartment
from . import SearchableAlchemyGridView, CrudView
class SubdepartmentsGrid(SearchableAlchemyGridView): class SubdepartmentsGrid(SearchableAlchemyGridView):
@ -85,32 +85,27 @@ class SubdepartmentCrud(CrudView):
return fs return fs
def includeme(config): def add_routes(config):
config.add_route('subdepartments', '/subdepartments') config.add_route('subdepartments', '/subdepartments')
config.add_view(SubdepartmentsGrid, route_name='subdepartments',
renderer='/subdepartments/index.mako',
permission='subdepartments.list')
config.add_route('subdepartment.create', '/subdepartments/new') 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_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_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_route('subdepartment.delete', '/subdepartments/{uuid}/delete')
config.add_view(SubdepartmentCrud, attr='delete',
route_name='subdepartment.delete',
def includeme(config):
add_routes(config)
# list
config.add_view(SubdepartmentsGrid, route_name='subdepartments',
renderer='/subdepartments/index.mako', permission='subdepartments.list')
# crud
config.add_view(SubdepartmentCrud, attr='create', route_name='subdepartment.create',
renderer='/subdepartments/crud.mako', permission='subdepartments.create')
config.add_view(SubdepartmentCrud, attr='read', route_name='subdepartment.read',
renderer='/subdepartments/crud.mako', permission='subdepartments.read')
config.add_view(SubdepartmentCrud, attr='update', route_name='subdepartment.update',
renderer='/subdepartments/crud.mako', permission='subdepartments.update')
config.add_view(SubdepartmentCrud, attr='delete', route_name='subdepartment.delete',
permission='subdepartments.delete') permission='subdepartments.delete')