improve template structure (fixes #18)

This commit is contained in:
Jan Dittberner 2009-03-07 12:38:23 +01:00
parent 84191f4b2c
commit 3f4d76dd99
12 changed files with 70 additions and 62 deletions

View file

@ -12,17 +12,17 @@ class CustomerController(BaseController):
sess = meta.Session() sess = meta.Session()
cust_q = sess.query(customer.Customer) cust_q = sess.query(customer.Customer)
c.customers = cust_q.all() c.customers = cust_q.all()
return render('/customer/index.mako') return render('/derived/customer/index.mako')
def create(self): def create(self):
sess = meta.Session() sess = meta.Session()
return render('/customer/create.mako') return render('/derived/customer/create.mako')
def edit(self, id): def edit(self, id):
sess = meta.Session() sess = meta.Session()
cust_q = sess.query(customer.Customer) cust_q = sess.query(customer.Customer)
c.customer = cust_q.filter(customer.Customer.id==id).one() c.customer = cust_q.filter(customer.Customer.id==id).one()
return render('/customer/edit.mako') return render('/derived/customer/edit.mako')
def delete(self, id): def delete(self, id):
sess = meta.Session() sess = meta.Session()

View file

@ -9,7 +9,4 @@ class IndexController(BaseController):
def index(self): def index(self):
c.menuitems = [(_("Customer management"), "customer", "index")] c.menuitems = [(_("Customer management"), "customer", "index")]
# Return a rendered template return render('/derived/index/index.mako')
# return render('/some/template.mako')
# or, Return a response
return render('/index.mako')

View file

@ -3,5 +3,5 @@
Consists of functions to typically be used within templates, but also Consists of functions to typically be used within templates, but also
available to Controllers. This module is available to both as 'h'. available to Controllers. This module is available to both as 'h'.
""" """
from webhelpers.rails.wrapped import * from webhelpers.html.tags import *
from routes import url_for, redirect_to from routes import url_for, redirect_to

View file

@ -1,20 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>${_('PyAlchemyBiz')}</title>
${h.stylesheet_link_tag('/pyalchemybiz.css')}
${h.javascript_include_tag(
'/javascripts/pyalchemybiz.js', builtins=True)}
</head>
<body>
<div class="content">
${next.body()}\
<p class="footer">
${_("Return to the %s.") % \
h.link_to(_('FrontPage'),
h.url_for(controller="index", action="index"))}
</p>
</div>
</body>
</html>

View file

@ -0,0 +1,30 @@
## -*- coding: utf-8 -*-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>${self.title()}</title>
${h.stylesheet_link('/pyalchemybiz.css')}
${h.javascript_link('/javascripts/jquery.js', '/javascripts/pyalchemybiz.js')}
${self.head()}
</head>
<body>
${self.header()}
${self.tabs()}
${self.menu()}
${self.heading()}
${self.breadcrumbs()}
${next.body()}
${self.footer()}
</body>
</html>
<%def name="title()">${_('PyAlchemyBiz')}</%def>
<%def name="head()"></%def>
<%def name="header()"><a name="top"></a></%def>
<%def name="tabs()"></%def>
<%def name="menu()"></%def>
<%def name="heading()"><h1>${c.heading or _('PyAlchemyBiz')}</h1></%def>
<%def name="breadcrumbs()"></%def>
<%def name="footer()"><p><a href="#top">Top ^</a></p></%def>

View file

@ -0,0 +1,5 @@
<%inherit file="/base/base.mako" />
${next.body()}
<%def name="title()">${parent.title()} - ${_('Customer management')}</%def>
<%def name="heading()"><h1>${_('Customer management')}</h1></%def>

View file

@ -1,15 +0,0 @@
<%inherit file="/base.mako" />
<h1>${_('Customer management')}</h1>
<h2>${_('Create new customer')}</h2>
${h.start_form(h.url_for(action='process_create'), method='post')}
<div id="createcustomerform">
<label for="firstname">${_('First name:')}</label><br />
${h.text_field('firstname')}<br />
<label for="lastname">${_('Last name:')}</label><br />
${h.text_field('lastname')}<br />
${h.submit(_('Add new customer'))}
</div>
${h.end_form()}

View file

@ -1,15 +0,0 @@
<%inherit file="/base.mako" />
<h1>${_('Customer management')}</h1>
<h2>${_('Edit customer')}</h2>
${h.start_form(h.url_for(action='process_edit'), method='post')}
<div id="editcustomerform">
<label for="firstname">${_('First name:')}</label><br />
${h.text_field('firstname', c.customer.person.firstname)}<br />
<label for="lastname">${_('Last name:')}</label><br />
${h.text_field('lastname', c.customer.person.lastname)}<br />
${h.submit(_('Save changes'))}
</div>
${h.end_form()}

View file

@ -0,0 +1,14 @@
<%inherit file="/base/customer.mako" />
${h.form(h.url_for(action='process_create'))}
<fieldset id="createcustomerform">
<label for="firstname">${_('First name:')}</label><br />
${h.text('firstname')}<br />
<label for="lastname">${_('Last name:')}</label><br />
${h.text('lastname')}<br />
${h.submit('submit', _('Add new customer'))}
</fieldset>
${h.end_form()}
<%def name="heading()"><h1>${_('Create new customer')}</h1></%def>

View file

@ -0,0 +1,14 @@
<%inherit file="/base/customer.mako" />
${h.form(h.url_for(action='process_edit'))}
<fieldset id="editcustomerform">
<label for="firstname">${_('First name:')}</label><br />
${h.text('firstname', c.customer.person.firstname)}<br />
<label for="lastname">${_('Last name:')}</label><br />
${h.text('lastname', c.customer.person.lastname)}<br />
${h.submit('save', _('Save changes'))}
</fieldset>
${h.end_form()}
<%def name="heading()"><h1>${_('Edit customer')}</h1></%def>

View file

@ -1,6 +1,4 @@
<%inherit file="/base.mako" /> <%inherit file="/base/customer.mako" />
<h1>${_('Customer management')}</h1>
<ul id="customers"> <ul id="customers">
% for customer in c.customers: % for customer in c.customers:

View file

@ -1,4 +1,4 @@
<%inherit file="base.mako" /> <%inherit file="/base/base.mako" />
<ul id="menu"> <ul id="menu">
% for item in c.menuitems: % for item in c.menuitems: