From 6821c922fc3466316ec4e3b07c98d893773c8fdb Mon Sep 17 00:00:00 2001
From: Drew Fisher <drew.m.fisher@gmail.com>
Date: Sun, 27 Mar 2011 02:35:26 -0500
Subject: [PATCH] Switch to web.py 0.3

The web.py framework changed some behavior between 0.2 and 0.3;
this commit updates shortlog to run 0.3 out of the box.

Signed-off-by: Drew Fisher <drew.m.fisher@gmail.com>
---
 shortlog.py | 51 ++++++++++++++-------------------------------------
 1 file changed, 14 insertions(+), 37 deletions(-)

diff --git a/shortlog.py b/shortlog.py
index 806c640..122553d 100644
--- a/shortlog.py
+++ b/shortlog.py
@@ -38,7 +38,7 @@ urls = (
 	)
 
 ## This is the way to do it in web.py 0.3+
-#app = web.application(urls, globals())
+app = web.application(urls, globals())
 
 ## Workaround for autoreloading and sessions when using web.config.debug = True
 ## Note: I don't actually use sessions
@@ -105,12 +105,7 @@ class year:
 		entries = map( readFile, filelist)
 		commentcounts = map(len, map( getCommentFiles, dates))
 		render = web.template.render(pwd + "/templates")
-		# This mess is because web.py 0.2 doesn't include passing common useful functions to the template engine
-		web.template.Template.globals['xrange'] = xrange
-		web.template.Template.globals['len'] = len
-		print render.multiday(zip(dates, entries, commentcounts), "Entries from %s" % theyear)
-		# This is the web.py 0.3+ way to do it.
-		#return render.multiday(dates, entries, "Entries from %s" % theyear)
+		return render.multiday(zip(dates, entries, commentcounts), "Entries from %s" % theyear)
 
 class month:
 	def GET(self, theyear, themonth):
@@ -122,9 +117,7 @@ class month:
 		entries = map( readFile, filelist)
 		commentcounts = map(len, map( getCommentFiles, dates))
 		render = web.template.render(pwd + "/templates")
-		web.template.Template.globals['xrange'] = xrange
-		web.template.Template.globals['len'] = len
-		print render.multiday(zip(dates, entries, commentcounts), "Entries from %s, %s" % (monthnames[themonth], theyear))
+		return render.multiday(zip(dates, entries, commentcounts), "Entries from %s, %s" % (monthnames[themonth], theyear))
 
 class day:
 	def GET(self, year, month, day):
@@ -138,14 +131,10 @@ class day:
 			for f in files:
 				comments.append(loadComment(f))
 			render = web.template.render(pwd + "/templates")
-			web.template.Template.globals['xrange'] = xrange
-			web.template.Template.globals['len'] = len
-			print render.day("%s-%s-%s" % (year, month, day), paras, comments)
+			return render.day("%s-%s-%s" % (year, month, day), paras, comments)
 		else:
 			render = web.template.render(pwd + "/templates")
-			web.template.Template.globals['xrange'] = xrange
-			web.template.Template.globals['len'] = len
-			print render.noentry("%s-%s-%s" % (year, month, day))
+			return render.noentry("%s-%s-%s" % (year, month, day))
 
 	def verify(self, test):
 		if len(test) != 4:
@@ -187,13 +176,7 @@ class day:
 		s.sendmail("shortlog@zarvox.org", ["drew.m.fisher@gmail.com"], "To: Drew Fisher <drew.m.fisher@gmail.com>\nFrom: Shortlog <shortlog@zarvox.org>\nSubject: [shortlog] new comment on %s-%s-%s\n\nName: %s\nEmail: %s\nWebsite: %s\nComment: %s" % (year, month, day, name, email, website, comment ))
 		s.quit()
 		web.header('Content-Type', 'text/html')
-		print "<html><body>Thanks! Your comment has been submitted and will be posted pending review.</body></html>"
-#		paras = readFile(pwd + "/entries/" + year + "-" + month + "-" + day + ".txt")
-#		render = web.template.render(pwd + "/templates")
-#		web.template.Template.globals['xrange'] = xrange
-#		web.template.Template.globals['len'] = len
-#		print render.day("%s-%s-%s" % (year, month, day), paras)
-
+		return "<html><body>Thanks! Your comment has been submitted and will be posted pending review.</body></html>"
 
 class pastyear:
 	def GET(self):
@@ -203,9 +186,7 @@ class pastyear:
 		entries = map( readFile, filelist)
 		commentcounts = map(len, map( getCommentFiles, dates))
 		render = web.template.render(pwd + "/templates")
-		web.template.Template.globals['xrange'] = xrange
-		web.template.Template.globals['len'] = len
-		print render.multiday(zip(dates, entries, commentcounts))
+		return render.multiday(zip(dates, entries, commentcounts))
 
 class pastmonth:
 	def GET(self):
@@ -215,9 +196,7 @@ class pastmonth:
 		entries = map( readFile, filelist)
 		commentcounts = map(len, map( getCommentFiles, dates))
 		render = web.template.render(pwd + "/templates")
-		web.template.Template.globals['xrange'] = xrange
-		web.template.Template.globals['len'] = len
-		print render.multiday(zip(dates, entries, commentcounts))
+		return render.multiday(zip(dates, entries, commentcounts))
 
 class pastweek:
 	def GET(self):
@@ -227,9 +206,7 @@ class pastweek:
 		entries = map( readFile, filelist)
 		commentcounts = map(len, map( getCommentFiles, dates))
 		render = web.template.render(pwd + "/templates")
-		web.template.Template.globals['xrange'] = xrange
-		web.template.Template.globals['len'] = len
-		print render.multiday(zip(dates, entries, commentcounts))
+		return render.multiday(zip(dates, entries, commentcounts))
 
 class redir:
 	def GET(self): 
@@ -255,17 +232,17 @@ class feed:
 					"timestamp": (mtime.isoformat() + "-06:00") }
 			entries.append(second)
 		render = web.template.render(pwd +"/templates")
-		print render.feed(group_timestamp, entries)
+		return render.feed(group_timestamp, entries)
 
 # web.py 0.3+ way
-#application = web.application(urls, globals()).wsgifunc()
+application = web.application(urls, globals()).wsgifunc()
 
 # web.py 0.2 way
-application = web.wsgifunc(web.webpyfunc(urls, globals()))
+#application = web.wsgifunc(web.webpyfunc(urls, globals()))
 
 if __name__ == "__main__":
 	## The web.py 0.3+ way
-	#app.run()
+	app.run()
 	## The web.py 0.2 way
-	web.run(urls, globals())
+	#web.run(urls, globals())
 
-- 
2.39.5