]> git.zarvox.org Git - shortlog.git/commitdiff
Switch to web.py 0.3
authorDrew Fisher <drew.m.fisher@gmail.com>
Sun, 27 Mar 2011 07:35:26 +0000 (02:35 -0500)
committerDrew Fisher <drew.m.fisher@gmail.com>
Sun, 27 Mar 2011 07:35:26 +0000 (02:35 -0500)
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

index 806c64000be798a43c46debc74aac8dfef729873..122553d8f6b33956ee9e6a5806339bb0d0e968c4 100644 (file)
@@ -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())