# vim:fileencoding=utf8 """ Copyright © 2011 Pádraig Brady
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import cgi import datetime import re import wsgiref.handlers #from google.appengine.api import users from google.appengine.api import mail from google.appengine.api import memcache from google.appengine.ext import webapp from google.appengine.ext import db class Comment(db.Model): user = db.UserProperty() author = db.StringProperty() url = db.StringProperty() page = db.StringProperty(required=True) content = db.TextProperty() date = db.DateTimeProperty(auto_now_add=True) def age(date): age = datetime.datetime.now() - date if age.days: return date.strftime("%d %b %Y") elif not age.seconds: return "just now" else: hours = age.seconds/3600 if hours: return "%s hours ago" % hours mins = age.seconds/60 if mins: return "%s minutes ago" % mins return "%s seconds ago" % age.seconds def getcache(key, compute, time=600): value = memcache.get(key) if value is None: value = compute() memcache.set(key, value, time=time) return value class MainPage(webapp.RequestHandler): def get(self): mode = self.request.get('mode') if mode != "count": self.response.out.write("""
""") if mode == "count": value = memcache.get(self.request.path) if value is not None: self.response.out.write('%d' % value) return #TODO: can have simpler query for just counting. May not need Gql at all? comments = db.GqlQuery("SELECT * FROM Comment WHERE page = '%s' ORDER BY date" % self.request.path) if mode == "count": value=comments.count() memcache.set(self.request.path, value, 600) #timeout as can delete comments in dashboard self.response.out.write('%d' % value) return num=0 for comment in comments: self.response.out.write('\n