add customer views
This commit is contained in:
parent
96046d9089
commit
4949ec8818
7
rattail/pyramid/templates/customers/crud.mako
Normal file
7
rattail/pyramid/templates/customers/crud.mako
Normal file
|
@ -0,0 +1,7 @@
|
|||
<%inherit file="/crud.mako" />
|
||||
|
||||
<%def name="context_menu_items()">
|
||||
<p>${h.link_to("Back to Customers", url('customers'))}</p>
|
||||
</%def>
|
||||
|
||||
${parent.body()}
|
5
rattail/pyramid/templates/customers/index.mako
Normal file
5
rattail/pyramid/templates/customers/index.mako
Normal file
|
@ -0,0 +1,5 @@
|
|||
<%inherit file="/index.mako" />
|
||||
|
||||
<%def name="title()">Customers</%def>
|
||||
|
||||
${parent.body()}
|
49
rattail/pyramid/templates/customers/read.mako
Normal file
49
rattail/pyramid/templates/customers/read.mako
Normal file
|
@ -0,0 +1,49 @@
|
|||
<%inherit file="/customers/crud.mako" />
|
||||
|
||||
${parent.body()}
|
||||
|
||||
<h2>People</h2>
|
||||
% if fieldset.model.people:
|
||||
<p>Customer account is associated with the following people:</p>
|
||||
<div class="grid hoverable">
|
||||
<table>
|
||||
<thead>
|
||||
<th>First Name</th>
|
||||
<th>Last Name</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
% for i, person in enumerate(fieldset.model.people, 1):
|
||||
<tr class="${'odd' if i % 2 else 'even'}">
|
||||
<td>${person.first_name or ''}</td>
|
||||
<td>${person.last_name or ''}</td>
|
||||
</tr>
|
||||
% endfor
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
% else:
|
||||
<p>Customer account is not associated with any people.</p>
|
||||
% endif
|
||||
|
||||
<h2>Groups</h2>
|
||||
% if fieldset.model.groups:
|
||||
<p>Customer account belongs to the following groups:</p>
|
||||
<div class="grid hoverable">
|
||||
<table>
|
||||
<thead>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
% for i, group in enumerate(fieldset.model.groups, 1):
|
||||
<tr class="${'odd' if i % 2 else 'even'}">
|
||||
<td>${group.id}</td>
|
||||
<td>${group.name or ''}</td>
|
||||
</tr>
|
||||
% endfor
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
% else:
|
||||
<p>Customer account doesn't belong to any groups.</p>
|
||||
% endif
|
118
rattail/pyramid/views/customers.py
Normal file
118
rattail/pyramid/views/customers.py
Normal file
|
@ -0,0 +1,118 @@
|
|||
#!/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.customers`` -- Customer Views
|
||||
"""
|
||||
|
||||
from sqlalchemy import and_
|
||||
|
||||
from edbob.pyramid.views import SearchableAlchemyGridView
|
||||
from edbob.pyramid.views.crud import Crud
|
||||
|
||||
import rattail
|
||||
|
||||
|
||||
class CustomersGrid(SearchableAlchemyGridView):
|
||||
|
||||
mapped_class = rattail.Customer
|
||||
route_name = 'customers'
|
||||
route_url = '/customers'
|
||||
renderer = '/customers/index.mako'
|
||||
permission = 'customers.list'
|
||||
sort = 'name'
|
||||
clickable = True
|
||||
|
||||
def join_map(self):
|
||||
return {
|
||||
'email':
|
||||
lambda q: q.outerjoin(rattail.CustomerEmailAddress, and_(
|
||||
rattail.CustomerEmailAddress.parent_uuid == rattail.Customer.uuid,
|
||||
rattail.CustomerEmailAddress.preference == 1)),
|
||||
'phone':
|
||||
lambda q: q.outerjoin(rattail.CustomerPhoneNumber, and_(
|
||||
rattail.CustomerPhoneNumber.parent_uuid == rattail.Customer.uuid,
|
||||
rattail.CustomerPhoneNumber.preference == 1)),
|
||||
}
|
||||
|
||||
def filter_map(self):
|
||||
return self.make_filter_map(
|
||||
exact=['id'],
|
||||
ilike=['name'],
|
||||
email=self.filter_ilike(rattail.CustomerEmailAddress.address),
|
||||
phone=self.filter_ilike(rattail.CustomerPhoneNumber.number))
|
||||
|
||||
def filter_config(self):
|
||||
return self.make_filter_config(
|
||||
include_filter_name=True,
|
||||
filter_type_name='lk',
|
||||
filter_label_phone="Phone Number",
|
||||
filter_label_email="Email Address",
|
||||
filter_label_id="ID")
|
||||
|
||||
def sort_map(self):
|
||||
return self.make_sort_map(
|
||||
'id', 'name',
|
||||
email=self.sorter(rattail.CustomerEmailAddress.address),
|
||||
phone=self.sorter(rattail.CustomerPhoneNumber.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)
|
||||
|
||||
def attrs(row, i):
|
||||
return {'onclick': "location.href = '%s';"
|
||||
% self.request.route_url('customer.read', uuid=row.uuid)}
|
||||
|
||||
g.row_attrs = attrs
|
||||
return g
|
||||
|
||||
|
||||
class CustomerCrud(Crud):
|
||||
|
||||
mapped_class = rattail.Customer
|
||||
home_route = 'customers'
|
||||
|
||||
def fieldset(self, obj):
|
||||
fs = self.make_fieldset(obj)
|
||||
fs.configure(
|
||||
include=[
|
||||
fs.id.label("ID"),
|
||||
fs.name,
|
||||
fs.phone,
|
||||
fs.email,
|
||||
])
|
||||
return fs
|
||||
|
||||
|
||||
def includeme(config):
|
||||
CustomersGrid.add_route(config)
|
||||
CustomerCrud.add_routes(config)
|
Loading…
Reference in a new issue