improve customer controller and templates (addresses #21)
* add footer actions to customer view template * add pagination to customer list
This commit is contained in:
parent
e3fe3f8353
commit
7bfe4996b2
3 changed files with 63 additions and 9 deletions
|
@ -1,12 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
|
||||
from pyalchemybiz.lib.base import BaseController, _, c, render, redirect_to
|
||||
from pyalchemybiz.lib.base import BaseController, _, c, render, redirect_to, \
|
||||
request
|
||||
from pyalchemybiz.model import customer, meta, person
|
||||
from pylons.decorators import validate
|
||||
from pylons.decorators.rest import restrict
|
||||
import formencode
|
||||
from formencode import htmlfill
|
||||
import webhelpers.paginate as paginate
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -35,7 +37,12 @@ class CustomerController(BaseController):
|
|||
"""
|
||||
Show a customer list.
|
||||
"""
|
||||
c.customers = meta.Session.query(customer.Customer).all()
|
||||
records = meta.Session.query(customer.Customer)
|
||||
c.paginator = paginate.Page(
|
||||
records,
|
||||
page = int(request.params.get('page', 1)),
|
||||
items_per_page = 10,
|
||||
)
|
||||
return render('/derived/customer/list.mako')
|
||||
|
||||
def view(self, id=None):
|
||||
|
|
|
@ -1,9 +1,46 @@
|
|||
<%inherit file="/base/customer.mako" />
|
||||
|
||||
<ul id="customers">
|
||||
% for customer in c.customers:
|
||||
<li>${customer} [${h.link_to(_('view customer'), h.url_for(id=customer.id, action='view'))}] [${h.link_to(_('edit customer'), h.url_for(id=customer.id, action="edit"))}] [${h.link_to(_('delete customer'), h.url_for(id=customer.id, action="delete"))}]</li>
|
||||
% endfor
|
||||
</ul>
|
||||
<%def name="heading()"><h1>Customer List</h1></%def>
|
||||
|
||||
${h.link_to(_('create new customer'), h.url_for(action="new"))}
|
||||
<%def name="buildrow(customer, odd=True)">
|
||||
%if odd:
|
||||
<tr class="odd">
|
||||
%else:
|
||||
<tr class="even">
|
||||
%endif
|
||||
<td>
|
||||
${h.link_to(
|
||||
customer.id,
|
||||
h.url_for(
|
||||
controller=u'customer',
|
||||
action='view',
|
||||
id=unicode(customer.id)
|
||||
)
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
${customer}
|
||||
</td>
|
||||
</tr>
|
||||
</%def>
|
||||
|
||||
%if len(c.paginator):
|
||||
<p>${c.paginator.pager(_('$link_first $link_previous $first_item to $last_item of $item_count $link_next $link_last'))}</p>
|
||||
<table class="paginator">
|
||||
<tr>
|
||||
<th>${_('Customer ID')}</th>
|
||||
<th>${_('Customer')}</th>
|
||||
</tr>
|
||||
<% counter=0 %>
|
||||
%for item in c.paginator:
|
||||
${buildrow(item, counter%2)}
|
||||
<% counter += 1 %>
|
||||
%endfor
|
||||
</table>
|
||||
<p>${c.paginator.pager('~2~')}</p>
|
||||
%else:
|
||||
<p>
|
||||
${_('No customers have yet been created.')}
|
||||
${h.link_to(_('Add one'), h.url_for(controller='customer', action='new'))}.
|
||||
</p>
|
||||
%endif
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<%inherit file="/base/customer.mako" />
|
||||
|
||||
<%def name="heading()"><h1>${_('View customer')}</h1></%def>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
|
@ -11,4 +13,12 @@
|
|||
</tbody>
|
||||
</table>
|
||||
|
||||
<%def name="heading()"><h1>${_('View customer')}</h1></%def>
|
||||
<%def name="footer()">
|
||||
<p>
|
||||
${h.link_to(_('All Customers'), h.url_for(controller='customer', action='list', id=None))}
|
||||
| ${h.link_to(_('New Customer'), h.url_for(controller='customer', action='new', id=None))}
|
||||
| ${h.link_to(_('Edit Customer'), h.url_for(controller='customer', action='edit'))}
|
||||
| ${h.link_to(_('Delete Customer'), h.url_for(controller='customer', action='delete'))}
|
||||
</p>
|
||||
${parent.footer()}
|
||||
</%def>
|
||||
|
|
Loading…
Reference in a new issue