add Brand views
This commit is contained in:
parent
ef2fb3d66c
commit
0046021bc6
12
rattail/pyramid/templates/brands/crud.mako
Normal file
12
rattail/pyramid/templates/brands/crud.mako
Normal file
|
@ -0,0 +1,12 @@
|
|||
<%inherit file="/crud.mako" />
|
||||
|
||||
<%def name="context_menu_items()">
|
||||
<li>${h.link_to("Back to Brands", url('brands'))}</li>
|
||||
% if form.readonly:
|
||||
<li>${h.link_to("Edit this Brand", url('brand.update', uuid=form.fieldset.model.uuid))}</li>
|
||||
% elif form.updating:
|
||||
<li>${h.link_to("View this Brand", url('brand.read', uuid=form.fieldset.model.uuid))}</li>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
${parent.body()}
|
11
rattail/pyramid/templates/brands/index.mako
Normal file
11
rattail/pyramid/templates/brands/index.mako
Normal file
|
@ -0,0 +1,11 @@
|
|||
<%inherit file="/grid.mako" />
|
||||
|
||||
<%def name="title()">Brands</%def>
|
||||
|
||||
<%def name="context_menu_items()">
|
||||
% if request.has_perm('brands.create'):
|
||||
<li>${h.link_to("Create a new Brand", url('brand.create'))}</li>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
${parent.body()}
|
108
rattail/pyramid/views/brands.py
Normal file
108
rattail/pyramid/views/brands.py
Normal file
|
@ -0,0 +1,108 @@
|
|||
#!/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.brands`` -- Brand Views
|
||||
"""
|
||||
|
||||
from edbob.pyramid.views import SearchableAlchemyGridView, CrudView
|
||||
|
||||
import rattail
|
||||
|
||||
|
||||
class BrandsGrid(SearchableAlchemyGridView):
|
||||
|
||||
mapped_class = rattail.Brand
|
||||
config_prefix = 'brands'
|
||||
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('name')
|
||||
|
||||
def grid(self):
|
||||
g = self.make_grid()
|
||||
g.configure(
|
||||
include=[
|
||||
g.name,
|
||||
],
|
||||
readonly=True)
|
||||
if self.request.has_perm('brands.read'):
|
||||
g.clickable = True
|
||||
g.click_route_name = 'brand.read'
|
||||
if self.request.has_perm('brands.update'):
|
||||
g.editable = True
|
||||
g.edit_route_name = 'brand.update'
|
||||
if self.request.has_perm('brands.delete'):
|
||||
g.deletable = True
|
||||
g.delete_route_name = 'brand.delete'
|
||||
return g
|
||||
|
||||
|
||||
class BrandCrud(CrudView):
|
||||
|
||||
mapped_class = rattail.Brand
|
||||
home_route = 'brands'
|
||||
|
||||
def fieldset(self, model):
|
||||
fs = self.make_fieldset(model)
|
||||
fs.configure(
|
||||
include=[
|
||||
fs.name,
|
||||
])
|
||||
return fs
|
||||
|
||||
|
||||
def includeme(config):
|
||||
|
||||
config.add_route('brands', '/brands')
|
||||
config.add_view(BrandsGrid, route_name='brands',
|
||||
renderer='/brands/index.mako',
|
||||
permission='brands.list')
|
||||
|
||||
config.add_route('brand.create', '/brands/new')
|
||||
config.add_view(BrandCrud, attr='create', route_name='brand.create',
|
||||
renderer='/brands/crud.mako',
|
||||
permission='brands.create')
|
||||
|
||||
config.add_route('brand.read', '/brands/{uuid}')
|
||||
config.add_view(BrandCrud, attr='read', route_name='brand.read',
|
||||
renderer='/brands/crud.mako',
|
||||
permission='brands.read')
|
||||
|
||||
config.add_route('brand.update', '/brands/{uuid}/edit')
|
||||
config.add_view(BrandCrud, attr='update', route_name='brand.update',
|
||||
renderer='/brands/crud.mako',
|
||||
permission='brands.update')
|
||||
|
||||
config.add_route('brand.delete', '/brands/{uuid}/delete')
|
||||
config.add_view(BrandCrud, attr='delete', route_name='brand.delete',
|
||||
permission='brands.delete')
|
Loading…
Reference in a new issue