extended commit (see note)

- Cleaned up dependencies.

- Added ``rattail.pyramid.includeme()``.

- Added ``CustomerGroup`` CRUD view (read only).

- Added hot links to ``Customer`` CRUD view.

- Added ``Store`` index, CRUD views.

- Updated ``rattail.pyramid.views.includeme()``.

- Added ``email_preference`` to ``Customer`` CRUD.
This commit is contained in:
Lance Edgar 2012-09-17 11:59:24 -07:00
parent 123fa375ea
commit 1578dd3b55
10 changed files with 237 additions and 109 deletions

View file

@ -26,53 +26,9 @@
``rattail.pyramid`` -- Rattail's Pyramid Framework
"""
# import os.path
# import pyramid_beaker
# from pyramid.config import Configurator
# import edbob
from rattail.pyramid._version import __version__
# def main(global_config, **settings):
# """
# This function returns a Pyramid WSGI application.
# """
# # Here you can insert any code to modify the ``settings`` dict.
# # You can:
# # * Add additional keys to serve as constants or "global variables" in the
# # application.
# # * Set default values for settings that may have been omitted.
# # * Override settings that you don't want the user to change.
# # * Raise an exception if a setting is missing or invalid.
# # * Convert values from strings to their intended type.
# settings['mako.directories'] = [
# 'something:templates',
# 'edbob.pyramid:templates',
# ]
# # Configure Pyramid
# config = Configurator(settings=settings)
# config.include('edbob.pyramid')
# config.include('something.subscribers')
# config.scan()
# # Configure Beaker
# session_factory = pyramid_beaker.session_factory_from_settings(settings)
# config.set_session_factory(session_factory)
# pyramid_beaker.set_cache_regions_from_settings(settings)
# # Configure edbob
# edbob.basic_logging()
# edbob.init('something', os.path.abspath(settings['edbob.config']))
# # Add static views
# # config.add_static_view('css', 'static/css', cache_max_age=3600)
# # config.add_static_view('img', 'static/img', cache_max_age=3600)
# # config.add_static_view('js', 'static/js', cache_max_age=3600)
# return config.make_wsgi_app()
def includeme(config):
config.include('rattail.pyramid.subscribers')
config.include('rattail.pyramid.views')

View file

@ -0,0 +1,7 @@
<%inherit file="/crud.mako" />
<%def name="context_menu_items()">
<li>${h.link_to("Back to Customer Groups", url('customer_groups'))}</li>
</%def>
${parent.body()}

View file

@ -7,7 +7,7 @@ ${parent.body()}
<h2>People</h2>
% if customer.people:
<p>Customer account is associated with the following people:</p>
<div class="grid hoverable">
<div class="grid clickable">
<table>
<thead>
<th>First Name</th>
@ -15,7 +15,7 @@ ${parent.body()}
</thead>
<tbody>
% for i, person in enumerate(customer.people, 1):
<tr class="${'odd' if i % 2 else 'even'}">
<tr class="${'odd' if i % 2 else 'even'}" url="${url('person.read', uuid=person.uuid)}">
<td>${person.first_name or ''}</td>
<td>${person.last_name or ''}</td>
</tr>
@ -30,7 +30,7 @@ ${parent.body()}
<h2>Groups</h2>
% if customer.groups:
<p>Customer account belongs to the following groups:</p>
<div class="grid hoverable">
<div class="grid clickable">
<table>
<thead>
<th>ID</th>
@ -38,7 +38,7 @@ ${parent.body()}
</thead>
<tbody>
% for i, group in enumerate(customer.groups, 1):
<tr class="${'odd' if i % 2 else 'even'}">
<tr class="${'odd' if i % 2 else 'even'}" url="${url('customer_group.read', uuid=group.uuid)}">
<td>${group.id}</td>
<td>${group.name or ''}</td>
</tr>

View file

@ -0,0 +1,7 @@
<%inherit file="/crud.mako" />
<%def name="context_menu_items()">
<li>${h.link_to("Back to Stores", url('stores'))}</li>
</%def>
${parent.body()}

View file

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

View file

@ -29,8 +29,13 @@
def includeme(config):
config.include('rattail.pyramid.views.batches')
# config.include('rattail.pyramid.views.categories')
config.include('rattail.pyramid.views.customer_groups')
config.include('rattail.pyramid.views.customers')
config.include('rattail.pyramid.views.departments')
config.include('rattail.pyramid.views.categories')
config.include('rattail.pyramid.views.products')
config.include('rattail.pyramid.views.employees')
config.include('rattail.pyramid.views.labels')
config.include('rattail.pyramid.views.products')
config.include('rattail.pyramid.views.stores')
config.include('rattail.pyramid.views.subdepartments')
config.include('rattail.pyramid.views.vendors')

View file

@ -26,7 +26,7 @@
``rattail.pyramid.views.customergroups`` -- CustomerGroup Views
"""
from edbob.pyramid.views import SearchableAlchemyGridView, AlchemyGridView
from edbob.pyramid.views import SearchableAlchemyGridView, CrudView
import rattail
@ -59,9 +59,30 @@ class CustomerGroupsGrid(SearchableAlchemyGridView):
return g
class CustomerGroupCrud(CrudView):
mapped_class = rattail.CustomerGroup
home_route = 'customer_groups'
pretty_name = "Customer Group"
def fieldset(self, model):
fs = self.make_fieldset(model)
fs.configure(
include=[
fs.id.label("ID"),
fs.name,
])
return fs
def includeme(config):
config.add_route('customer_groups', '/customer-groups')
config.add_view(CustomerGroupsGrid, route_name='customer_groups',
renderer='/customer_groups/index.mako',
permission='customer_groups.list')
config.add_route('customer_group.read', '/customer-groups/{uuid}')
config.add_view(CustomerGroupCrud, attr='read', route_name='customer_group.read',
renderer='/customer_groups/crud.mako',
permission='customer_groups.read')

View file

@ -28,7 +28,9 @@
from sqlalchemy import and_
import edbob
from edbob.pyramid.views import SearchableAlchemyGridView, CrudView
from edbob.pyramid.forms import EnumFieldRenderer
import rattail
@ -94,12 +96,14 @@ class CustomerCrud(CrudView):
def fieldset(self, model):
fs = self.make_fieldset(model)
fs.email_preference.set(renderer=EnumFieldRenderer(edbob.EMAIL_PREFERENCE))
fs.configure(
include=[
fs.id.label("ID"),
fs.name,
fs.phone,
fs.email,
fs.phone.label("Phone Number"),
fs.email.label("Email Address"),
fs.email_preference,
])
return fs

View file

@ -0,0 +1,135 @@
#!/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.stores`` -- Store Views
"""
from sqlalchemy import and_
from edbob.pyramid.views import SearchableAlchemyGridView, CrudView
import rattail
class StoresGrid(SearchableAlchemyGridView):
mapped_class = rattail.Store
config_prefix = 'stores'
sort = 'name'
def join_map(self):
return {
'email':
lambda q: q.outerjoin(rattail.StoreEmailAddress, and_(
rattail.StoreEmailAddress.parent_uuid == rattail.Store.uuid,
rattail.StoreEmailAddress.preference == 1)),
'phone':
lambda q: q.outerjoin(rattail.StorePhoneNumber, and_(
rattail.StorePhoneNumber.parent_uuid == rattail.Store.uuid,
rattail.StorePhoneNumber.preference == 1)),
}
def filter_map(self):
return self.make_filter_map(
exact=['id'],
ilike=['name'],
email=self.filter_ilike(rattail.StoreEmailAddress.address),
phone=self.filter_ilike(rattail.StorePhoneNumber.number))
def filter_config(self):
return self.make_filter_config(
include_filter_name=True,
filter_type_name='lk',
filter_label_id="ID")
def sort_map(self):
return self.make_sort_map(
'id', 'name',
email=self.sorter(rattail.StoreEmailAddress.address),
phone=self.sorter(rattail.StorePhoneNumber.number))
def grid(self):
g = self.make_grid()
g.configure(
include=[
g.id.label("ID"),
g.name,
g.phone.label("Phone Number"),
g.email.label("Email Address"),
],
readonly=True)
g.clickable = True
g.click_route_name = 'store.read'
if self.request.has_perm('stores.update'):
g.editable = True
g.edit_route_name = 'store.update'
if self.request.has_perm('stores.delete'):
g.deletable = True
g.delete_route_name = 'store.delete'
return g
class StoreCrud(CrudView):
mapped_class = rattail.Store
home_route = 'stores'
def fieldset(self, model):
fs = self.make_fieldset(model)
fs.configure(
include=[
fs.id.label("ID"),
fs.name,
fs.phone.label("Phone Number").readonly(),
fs.email.label("Email Address").readonly(),
])
return fs
def includeme(config):
config.add_route('stores', '/stores')
config.add_view(StoresGrid, route_name='stores',
renderer='/stores/index.mako',
permission='stores.list')
config.add_route('store.create', '/stores/new')
config.add_view(StoreCrud, attr='create', route_name='store.create',
renderer='/stores/crud.mako',
permission='stores.create')
config.add_route('store.read', '/stores/{uuid}')
config.add_view(StoreCrud, attr='read', route_name='store.read',
renderer='/stores/crud.mako',
permission='stores.read')
config.add_route('store.update', '/stores/{uuid}/edit')
config.add_view(StoreCrud, attr='update', route_name='store.update',
renderer='/stores/crud.mako',
permission='stores.update')
config.add_route('store.delete', '/stores/{uuid}/delete')
config.add_view(StoreCrud, attr='delete', route_name='store.delete',
permission='stores.delete')

View file

@ -62,26 +62,8 @@ requires = [
#
# package # low high
# Beaker dependency included here because 'pyramid_beaker' uses incorrect
# case in its requirement declaration.
'Beaker', # 1.6.3
# Pyramid 1.3 introduced 'pcreate' command (and friends) to replace
# deprecated 'paster create' (and friends).
'pyramid>=1.3a1', # 1.3b2
'decorator', # 3.3.2
'Mako', # 0.6.2
'pyramid_beaker', # 0.6.1
'pyramid_debugtoolbar', # 1.0
'pyramid_tm', # 0.3
'edbob[db,pyramid]>=0.1a13', # 0.1a14.dev
'rattail>=0.3a4', # 0.3a5.dev
'SQLAlchemy', # 0.7.6
'Tempita', # 0.5.1
'transaction', # 1.2.0
'waitress', # 0.8.1
'WebHelpers', # 1.3
'zope.sqlalchemy', # 0.7
]