[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r21928: {weather} Add awkward page template mechanism to make pages look more (in weather/trunk: . data lib/weather)



Author: kaner
Date: 2010-03-12 17:46:36 +0000 (Fri, 12 Mar 2010)
New Revision: 21928

Removed:
   weather/trunk/data/subscribe.template
Modified:
   weather/trunk/Weather.py
   weather/trunk/lib/weather/constants.py
   weather/trunk/lib/weather/poller.py
Log:
Add awkward page template mechanism to make pages look more nice


Modified: weather/trunk/Weather.py
===================================================================
--- weather/trunk/Weather.py	2010-03-12 15:38:47 UTC (rev 21927)
+++ weather/trunk/Weather.py	2010-03-12 17:46:36 UTC (rev 21928)
@@ -15,14 +15,17 @@
 from email.mime.base import MIMEBase
 from email.mime.text import MIMEText
 
-import weather.constants
+from weather.constants import PAGE_TEMPLATE, PAGE_SIGNUP
 from weather.queries import CHECK_SUBS_Q, INSERT_SUBS_Q, CHECK_SUBS_AUTH_Q, ACK_SUB_Q, UNSUBSCRIBE_Q
 from weather.poller import WeatherPoller
 from weather.config import pollPeriod, URLbase
 
+def pageOut(text):
+    return PAGE_TEMPLATE % text
+
 class WeatherIndex(resource.Resource):
     def render(self, request):
-        return open("subscribe.template").read()
+        return pageOut(PAGE_SIGNUP)
 
 class SubscribeRequest(resource.Resource):
     def __init__(self, dbConn):
@@ -52,7 +55,7 @@
         # Do we already have a subscription for this address for this node?
         if len(result) is not 0:
             self.request.setResponseCode(http.OK)
-            self.request.write("Error: Already subscribed.")
+            self.request.write(pageOut("Error: Already subscribed."))
             self.request.finish()
         else:
             # Alright, subscribe it
@@ -71,14 +74,15 @@
         try:
             self._sendConfirmationMail(url)
         except Exception, e:
-            self.error = "Unknown error while sending confirmation mail." + \
-                         "Please try again later." + \
-                         "[Exception %s]" % sys.exc_info()[0]
+            self.error = "Unknown error while sending confirmation mail. " + \
+                         "Please try again later."
+            #             "[Exception %s]" % sys.exc_info()[0]
             self._rollBack()
             return
 
         self.request.setResponseCode(http.OK)
-        self.request.write(THANKS_OUT % self.email)
+        text = THANKS_OUT % self.email
+        self.request.write(pageOut(text))
         self.request.finish()
 
     def _rollBack(self):
@@ -89,7 +93,7 @@
 
     def _errOut(self, result):
         self.request.setResponseCode(http.INTERNAL_SERVER_ERROR)
-        self.request.write(self.error)
+        self.request.write(pageOut(self.error))
         self.request.finish()
 
     def _errback(self, failure):
@@ -173,7 +177,7 @@
     def _checkRet(self, result, request):
         if len(result) is 0:
             request.setResponseCode(http.OK)
-            request.write("Error: No subscription with your auth code.")
+            request.write(pageOut("Error: No subscription with your auth code"))
             request.finish()
         else:
             self.unsubs_auth = str(result[0][0])
@@ -188,16 +192,17 @@
     def _subDone(self, result, request):
         url = URLbase + "/unsubscribe?auth=" + self.unsubs_auth
         link = "<a href=\"" + url + "\">" + url + "</a>"
-        request.write("<p>Subscription finished. Thank you very much.")
-        request.write("You can unsubscribe anytime with the following link: ")
-        request.write(link)
-        #request.write(URLbase + "/unsubscribe?auth=" + self.unsubs_auth)
-        request.write("</p>")
+        pageout = "<p>Subscription finished. Thank you very much."
+        pageout += "You can unsubscribe anytime with the following link: "
+        pageout += link
+        pageout += "</p>"
+        request.write(pageOut(pageout))
         request.finish()
 
     def _errback(self, failure, request):
         request.setResponseCode(http.INTERNAL_SERVER_ERROR)
-        request.write("Error: %s" % (failure.getErrorMessage()))
+        text = "Error: %s" % (failure.getErrorMessage())
+        request.write(pageOut(text))
         request.finish()
 
 class UnsubscribeRequest(resource.Resource):
@@ -218,12 +223,13 @@
 
     def _deleteDone(self, result, request):
         request.setResponseCode(http.OK)
-        request.write("Subscription deleted. Goodbye.")
+        request.write(pageOut("Subscription deleted. Goodbye."))
         request.finish()
 
     def _errback(self, failure, request):
         request.setResponseCode(http.INTERNAL_SERVER_ERROR)
-        request.write("Error: %s" % (failure.getErrorMessage()))
+        text = "Error: %s" % (failure.getErrorMessage())
+        request.write(pageOut(text))
         request.finish()
 
 class RootResource(resource.Resource):

Deleted: weather/trunk/data/subscribe.template
===================================================================
--- weather/trunk/data/subscribe.template	2010-03-12 15:38:47 UTC (rev 21927)
+++ weather/trunk/data/subscribe.template	2010-03-12 17:46:36 UTC (rev 21928)
@@ -1,61 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<html>
-<head>
-  <title>Tor Weather</title>
-  <link rel="stylesheet" type="text/css" href="./stylesheet.css">
-</head>
-<body>
-<div class="center">
-<table class="banner" border="0" cellpadding="0" cellspacing="0" summary="">
-    <tr>
-
-        <td class="banner-left"><a href="https://www.torproject.org/";><img src="top-left.png" alt="Click to go to home page" width="193" height="79"></a></td>
-        <td class="banner-middle">
-        &nbsp;
-        </td>
-        <td class="banner-right">
-	</td>
-    </tr>
-</table>
-<div class="main-column">
-<h2>Tor Weather</h2>
-
-<hr>
-
-<h3>Sign Up!</h3>
-
-<br>
-<form method="post" action="/subscribe">
-You can use this form to request status updates to tell you when a particular
-Tor node has become unreachable for a sustained period of time.
-<br><br>
-
-<p>
-Email:<br>
-<input type="text" name="email" size="50" maxlength="255" value="Enter one email address" onclick="if (this.value == 'Enter one email address') {this.value = ''}" />
-</p><p>
-Node fingerprint:<br>
-<input type="text" name="node" size="50" maxlength="255" value="Enter one Tor node ID" onclick="if (this.value == 'Enter one Tor node ID') {this.value = ''}" />
-</p><p>
-<input type="submit" class="submit" value="Subscribe to Tor Weather" name="sa"/>
-</p>
-<hr>
-<h3>FAQ</h3>
-<br>
-<p>Q: <b>Where can I find the fingerprint for my server?</b></p>
-<p>A: <i>Often your node fingerprint can be found on unix-like machines in the file: <tt>/var/lib/tor/fingerprint</tt></i></p>
-<p>Q: <b>Will I be overloaded with alerts that I cannot suppress?</b></p>
-<p>A: <i>No.</i>
-<p>Q: <b>Can I unsubscribe easily?</b></p>
-<p>A: <i>Yes.</i>
-<p>Q: <b>I'm having a problem, can you help me?</b></p>
-<p>A: <i>Yes. Send an email to <tt>tor-weather @ torproject dot org</tt></i>
-<br>
-<hr>
-<br>
-<p><i>Please note that while we won't ever intentionally publish them, the address/node pairs sent to this server are not protected against SMTP eavesdropping, hacking, or lawyers.</i>
-</form>
-</div>
-</div>
-</body>
-</html>

Modified: weather/trunk/lib/weather/constants.py
===================================================================
--- weather/trunk/lib/weather/constants.py	2010-03-12 15:38:47 UTC (rev 21927)
+++ weather/trunk/lib/weather/constants.py	2010-03-12 17:46:36 UTC (rev 21928)
@@ -35,3 +35,72 @@
     If you do *not* wish to receive Tor Weather Reports, you do not need to do 
     anything.
 """
+
+PAGE_TEMPLATE = """
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+  <title>Tor Weather</title>
+  <link rel="stylesheet" type="text/css" href="./stylesheet.css">
+</head>
+<body>
+<div class="center">
+<table class="banner" border="0" cellpadding="0" cellspacing="0" summary="">
+    <tr>
+
+        <td class="banner-left"><a href="https://www.torproject.org/";><img src="top-left.png" alt="Click to go to home page" width="193" height="79"></a></td>
+        <td class="banner-middle">
+        &nbsp;
+        </td>
+        <td class="banner-right">
+	</td>
+    </tr>
+</table>
+<div class="main-column">
+<h2>Tor Weather</h2>
+
+<hr>
+
+%s
+
+</div>
+</div>
+</body>
+</html>
+"""
+
+PAGE_SIGNUP = """
+<h3>Sign Up!</h3>
+
+<br>
+<form method="post" action="/subscribe">
+You can use this form to request status updates to tell you when a particular
+Tor node has become unreachable for a sustained period of time.
+<br><br>
+
+<p>
+Email:<br>
+<input type="text" name="email" size="50" maxlength="255" value="Enter one email address" onclick="if (this.value == 'Enter one email address') {this.value = ''}" />
+</p><p>
+Node fingerprint:<br>
+<input type="text" name="node" size="50" maxlength="255" value="Enter one Tor node ID" onclick="if (this.value == 'Enter one Tor node ID') {this.value = ''}" />
+</p><p>
+<input type="submit" class="submit" value="Subscribe to Tor Weather" name="sa"/>
+</p>
+<hr>
+<h3>FAQ</h3>
+<br>
+<p>Q: <b>Where can I find the fingerprint for my server?</b></p>
+<p>A: <i>Often your node fingerprint can be found on unix-like machines in the file: <tt>/var/lib/tor/fingerprint</tt></i></p>
+<p>Q: <b>Will I be overloaded with alerts that I cannot suppress?</b></p>
+<p>A: <i>No.</i>
+<p>Q: <b>Can I unsubscribe easily?</b></p>
+<p>A: <i>Yes.</i>
+<p>Q: <b>I'm having a problem, can you help me?</b></p>
+<p>A: <i>Yes. Send an email to <tt>tor-weather @ torproject dot org</tt></i>
+<br>
+<hr>
+<br>
+<p><i>Please note that while we won't ever intentionally publish them, the address/node pairs sent to this server are not protected against SMTP eavesdropping, hacking, or lawyers.</i>
+</form>
+"""

Modified: weather/trunk/lib/weather/poller.py
===================================================================
--- weather/trunk/lib/weather/poller.py	2010-03-12 15:38:47 UTC (rev 21927)
+++ weather/trunk/lib/weather/poller.py	2010-03-12 17:46:36 UTC (rev 21928)
@@ -17,7 +17,6 @@
         self.dbConn = dbConn
 
     def poller(self):
-        print "Polling.."
         self._checkAll()
         return server.NOT_DONE_YET
 
@@ -30,7 +29,6 @@
     def _checkRet(self, resultList):
         # Loop through result list and check each node
         for result in resultList:
-            print "Result: ", result
             checkHost = result[2]
             if not self._checkHost(checkHost):
                 print "Server %s seems to be offline" % checkHost
@@ -42,7 +40,6 @@
         print "Error: ", failure.getErrorMessage()
 
     def _checkHost(self, hostID):
-        print "Checking host %s" % hostID
         torPing = TorPing()
         return torPing.ping(hostID)
 
@@ -73,4 +70,3 @@
         smtp = smtplib.SMTP("localhost:25")
         smtp.sendmail(mailFrom, dbRow[1], message.as_string())
         smtp.quit()
-