1
0
Fork 0

* basic template and JQuery infrastructure

* gva controller
This commit is contained in:
Jan Dittberner 2008-06-03 20:24:32 +00:00
parent 014f674b6d
commit 292c102db8
7 changed files with 74 additions and 109 deletions

View file

@ -17,7 +17,7 @@ def make_map():
map.connect('error/:action/:id', controller='error')
# CUSTOM ROUTES HERE
map.connect('', controller='gva', action='index')
map.connect(':controller/:action/:id')
map.connect('*url', controller='template', action='view')

View file

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
import logging
from gnuviechadminweb.lib.base import *
log = logging.getLogger(__name__)
class GvaController(BaseController):
def index(self):
# Return a rendered template
return render('/main.mako')

View file

@ -1,108 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Pylons Default Page</title>
<style>
body { background-color: #fff; color: #333; }
body, p {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 12px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
line-height: 13px;
}
a { color: #000; }
a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; }
</style>
</head>
<body>
<h1>Welcome to your Pylons Web Application</h1>
<h2>Weren't expecting to see this page?</h2>
<p>The <tt>gnuviechadminweb/public/</tt> directory is searched for static files
<i>before</i> your controllers are run. Remove this file (<tt>gnuviechadminweb/public/index.html</tt>)
and edit the routes in <tt>gnuviechadminweb/config/routing.py</tt> to point the
<a href="/">root path</a> to a 'hello' controller we'll create below:
<pre> map.connect('', controller='hello', action='index')</pre>
</p>
<h2>Getting Started</h2>
<p>You're now ready to start creating your own web application. To create a 'hello' controller,
run the following command in your project's root directory:
<pre>
gnuviechadminweb$ paster controller hello
</pre>
This generates the following the following code in <tt>gnuviechadminweb/controllers/hello.py</tt>:
<pre>
import logging
from gnuviechadminweb.lib.base import *
log = logging.getLogger(__name__)
class HelloController(BaseController):
def index(self):
# Return a rendered template
# return render('/some/template.mako)
# or, Return a response
return 'Hello World'
</pre>
</p>
<p>This controller simply prints out 'Hello World' to the browser. Pylons' default routes
automatically set up this controller to respond at the <a href="/hello">/hello</a> URL.
With the additional route described above, this controller will also respond at the
<a href="/">root path</a>.
</p>
<h3>Using a template</h3>
<p>To call a template and do something a little more complex, this following example
shows how to print out some request information from a
<a href="http://www.makotemplates.org">Mako</a> template.
</p>
<p>Create a <tt>serverinfo.mako</tt> file in your project's <tt>gnuviechadminweb/templates/</tt>
directory with the following contents:
</p>
<pre>
&lt;h2&gt;
Server info for ${request.host}
&lt;/h2&gt;
&lt;p&gt;
The URL you called: ${h.url_for()}
&lt;/p&gt;
&lt;p&gt;
The name you set: ${c.name}
&lt;/p&gt;
&lt;p&gt;The WSGI environ:&lt;br /&gt;
&lt;pre&gt;${c.pretty_environ}&lt;/pre&gt;
&lt;/p&gt;
</pre>
Then add the following to your 'hello' controller class:
<pre>
def serverinfo(self):
import cgi
import pprint
c.pretty_environ = cgi.escape(pprint.pformat(request.environ))
c.name = 'The Black Knight'
return render('/serverinfo.mako')
</pre>
You can now view the page at: <tt><a href="/hello/serverinfo">/hello/serverinfo</a></tt>
</p>
</body>
</html>

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
<%inherit file="site.mako" />
<h1>Main page</h1>
<%def name="title()">Main page</%def>

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
<html>
<head>
<title>${self.title()}</title>
${h.javascript_include_tag('jquery.js')}
</head>
<body>
<ul id="menu">
% for item in c.menu:
<li class="${h.cssclasses(item)}">${h.menulink(item)}</li>
% endfor
</ul>
<div id="content">
${next.body()}
</div>
</body>
</html>
<%def name="title()">Site</%def>

View file

@ -0,0 +1,7 @@
from gnuviechadminweb.tests import *
class TestGvaController(TestController):
def test_index(self):
response = self.app.get(url_for(controller='gva'))
# Test response...