# HG changeset patch
# User cmlenz
# Date 1188483599 0
# Node ID 71d3edd302ae176a817b5d899beb46fa90e86dcf
# Parent 5a2059ce1f0b6f2332edeebeee5f64f51ab367c7
GenshiTutorial: various updates to sync with wiki page.
diff --git a/examples/tutorial/geddit/controller.py b/examples/tutorial/geddit/controller.py
--- a/examples/tutorial/geddit/controller.py
+++ b/examples/tutorial/geddit/controller.py
@@ -8,11 +8,10 @@
import cherrypy
from formencode import Invalid
from genshi.filters import HTMLFormFiller
-from paste.evalexception.middleware import EvalException
-from geddit.form import SubmissionForm, CommentForm
+from geddit.form import LinkForm, CommentForm
from geddit.lib import template
-from geddit.model import Submission, Comment
+from geddit.model import Link, Comment
class Root(object):
@@ -23,19 +22,16 @@
@cherrypy.expose
@template.output('index.html')
def index(self):
- return template.render(
- submissions=sorted(self.data.values(),
- key=operator.attrgetter('time'),
- reverse=True)
- )
+ links = sorted(self.data.values(), key=operator.attrgetter('time'))
+ return template.render(links=links)
@cherrypy.expose
@template.output('info.html')
def info(self, code):
- submission = self.data.get(code)
- if not submission:
+ link = self.data.get(code)
+ if not link:
raise cherrypy.NotFound()
- return template.render(submission=submission)
+ return template.render(link=link)
@cherrypy.expose
@template.output('submit.html')
@@ -43,11 +39,11 @@
if cherrypy.request.method == 'POST':
if cancel:
raise cherrypy.HTTPRedirect('/')
- form = SubmissionForm()
+ form = LinkForm()
try:
data = form.to_python(data)
- submission = Submission(**data)
- self.data[submission.code] = submission
+ link = Link(**data)
+ self.data[link.id] = link
raise cherrypy.HTTPRedirect('/')
except Invalid, e:
errors = e.unpack_errors()
@@ -59,23 +55,23 @@
@cherrypy.expose
@template.output('comment.html')
def comment(self, code, cancel=False, **data):
- submission = self.data.get(code)
- if not submission:
+ link = self.data.get(code)
+ if not link:
raise cherrypy.NotFound()
if cherrypy.request.method == 'POST':
if cancel:
- raise cherrypy.HTTPRedirect('/info/%s' % submission.code)
+ raise cherrypy.HTTPRedirect('/info/%s' % link.id)
form = CommentForm()
try:
data = form.to_python(data)
- comment = submission.add_comment(**data)
- raise cherrypy.HTTPRedirect('/info/%s' % submission.code)
+ comment = link.add_comment(**data)
+ raise cherrypy.HTTPRedirect('/info/%s' % link.id)
except Invalid, e:
errors = e.unpack_errors()
else:
errors = {}
- return template.render(submission=submission, comment=None,
+ return template.render(link=link, comment=None,
errors=errors) | HTMLFormFiller(data=data)
@@ -99,7 +95,8 @@
fileobj.close()
cherrypy.engine.on_stop_engine_list.append(_save_data)
- # Some global configuration; note that this could be moved into a configuration file
+ # Some global configuration; note that this could be moved into a
+ # configuration file
cherrypy.config.update({
'request.throw_errors': True,
'tools.encode.on': True, 'tools.encode.encoding': 'utf-8',
@@ -108,10 +105,7 @@
'tools.staticdir.root': os.path.abspath(os.path.dirname(__file__)),
})
- # Initialize the application, and add EvalException for more helpful error messages
- app = cherrypy.Application(Root(data))
- app.wsgiapp.pipeline.append(('paste_exc', EvalException))
- cherrypy.quickstart(app, '/', {
+ cherrypy.quickstart(Root(data), '/', {
'/media': {
'tools.staticdir.on': True,
'tools.staticdir.dir': 'static'
diff --git a/examples/tutorial/geddit/form.py b/examples/tutorial/geddit/form.py
--- a/examples/tutorial/geddit/form.py
+++ b/examples/tutorial/geddit/form.py
@@ -1,7 +1,7 @@
from formencode import Schema, validators
-class SubmissionForm(Schema):
+class LinkForm(Schema):
username = validators.UnicodeString(not_empty=True)
url = validators.URL(not_empty=True, add_http=True, check_exists=False)
title = validators.UnicodeString(not_empty=True)
diff --git a/examples/tutorial/geddit/model.py b/examples/tutorial/geddit/model.py
--- a/examples/tutorial/geddit/model.py
+++ b/examples/tutorial/geddit/model.py
@@ -1,14 +1,14 @@
from datetime import datetime
-class Submission(object):
+class Link(object):
def __init__(self, username, url, title):
self.username = username
self.url = url
self.title = title
self.time = datetime.utcnow()
- self.code = hex(hash(tuple([username, url, title, self.time])))[2:]
+ self.id = hex(hash(tuple([username, url, title, self.time])))[2:]
self.comments = []
def __repr__(self):
diff --git a/examples/tutorial/geddit/static/layout.css b/examples/tutorial/geddit/static/layout.css
--- a/examples/tutorial/geddit/static/layout.css
+++ b/examples/tutorial/geddit/static/layout.css
@@ -2,6 +2,7 @@
body { background: #ddd; color: #333; font: normal 90%/1.3 Arial,Helvetica,sans-serif; }
:link, :visited { color: #c10000; text-decoration: none; }
:link:hover, :visited:hover { text-decoration: underline; }
+:link img, :visited img { border: none; }
h1 { color: #666;
font: normal xx-large/1.5 Georgia,serif; margin: 0 0 .5em;
}
@@ -21,7 +22,11 @@
#footer hr { display: none; }
.legalese { color: #999; margin: 0; }
-ol.submissions li .info { font-size: 85%; }
-ol.submissions li .info :link, ol.submissions li .info :visited { color: #666; }
+ol.links li .info { font-size: 85%; }
+ol.links li .info :link, ol.links li .info :visited { color: #666; }
+
ul.comments { list-style: none; margin: 1em 0; padding: 0 0 0 1em; }
ul.comments li { color: #999; margin: 0 0 1em; }
+ul.comments blockquote { color: #333; font-style: normal; margin: 0;
+ padding: 0;
+}
diff --git a/examples/tutorial/geddit/templates/comment.html b/examples/tutorial/geddit/templates/comment.html
--- a/examples/tutorial/geddit/templates/comment.html
+++ b/examples/tutorial/geddit/templates/comment.html
@@ -4,10 +4,10 @@
xmlns:py="http://genshi.edgewall.org/">
In reply to ${comment.username} at ${comment.time.strftime('%M/%d/%Y %H:%m')}: diff --git a/examples/tutorial/geddit/templates/index.html b/examples/tutorial/geddit/templates/index.html --- a/examples/tutorial/geddit/templates/index.html +++ b/examples/tutorial/geddit/templates/index.html @@ -10,14 +10,13 @@
${link.title}
+ ${link.url}+ posted by ${link.username} at ${link.time.strftime('%m/%d/%Y %H:%M')}
+ comment +
+-
${comment.username}
at ${comment.time.strftime('%m/%d/%Y %H:%M')}