Permalink
Browse files

Working model

  • Loading branch information...
1 parent da51def commit af3ffcd6864941290c4d568974adeed5731a1a8c @dustball dustball committed Jul 25, 2013
Showing with 35 additions and 50 deletions.
  1. +23 −49 main.py
  2. +12 −1 templates/index.html
View
72 main.py
@@ -5,69 +5,43 @@
from google.appengine.api import urlfetch
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util, template
+from google.appengine.ext import db
import logging
import pprint
import urllib
import re
import json
+
+class AlarmEvent(db.Model):
+ event = db.StringProperty(required=True)
+ zone = db.StringProperty(required=True)
+ created = db.DateTimeProperty(auto_now_add=True)
+
class IndexHandler(webapp.RequestHandler):
def get(self):
+ alarmevents = AlarmEvent.all().fetch(100)
self.response.out.write(template.render('templates/index.html', locals()))
-#class LogHandler(webapp.RequestHandler):
-# def get(self, pagename, site = PB_WIKI):
-# skip_cache = self.request.get('cache') == '0'
-# version = os.environ['CURRENT_VERSION_ID']
-# shouldRedirect = False
-#
-# redirect_urls = {
-# # From: To
-# 'give': 'Give',
-# 'auction': 'Auction',
-# 'Assemble': 'Give',
-# 'Mobile%20Device%20Lab': 'MobileDeviceLab',
-# 'kickstarter': 'http://www.kickstarter.com/projects/384590180/an-events-space-and-a-design-studio-for-hacker-doj',
-# 'Kickstarter': 'http://www.kickstarter.com/projects/384590180/an-events-space-and-a-design-studio-for-hacker-doj',
-# 'KICKSTARTER': 'http://www.kickstarter.com/projects/384590180/an-events-space-and-a-design-studio-for-hacker-doj',
-# 'key': 'http://signup.hackerdojo.com/key',
-# }
-# if pagename in redirect_urls:
-# url = redirect_urls[pagename]
-# self.redirect(url, permanent=True)
-# else:
-# if CDN_ENABLED:
-# cdn = CDN_HOSTNAME
-# try:
-# pageKey = 'page:%s' % pagename.lower()
-# if not(pagename):
-# pagename = 'FrontPage'
-# page = _request(PB_API_URL % (site, pagename), cache_ttl=604800, force=skip_cache)
-# # fetch a page where a lowercase version may exist
-# if not(page and "name" in page):
-# if memcache.get(pageKey):
-# pagename = memcache.get(pageKey)
-# page = _request(PB_API_URL % (site, pagename), cache_ttl=604800, force=skip_cache)
-# shouldRedirect = True
-# # Convert quasi-camel-case to spaced words
-# title = re.sub('([a-z]|[A-Z])([A-Z])', r'\1 \2', pagename)
-# if page and "name" in page:
-# fiveDays = 432000
-# memcache.set(pageKey, pagename, fiveDays)
-# if shouldRedirect:
-# self.redirect(pagename, permanent=True)
-# else:
-# self.response.out.write(template.render('templates/content.html', locals()))
-# else:
-# raise LookupError
-# except LookupError:
-# self.response.out.write(template.render('templates/404.html', locals()))
-# self.response.set_status(404)
+class LogHandler(webapp.RequestHandler):
+ def get(self):
+ event = self.request.get('event')
+ zone = self.request.get('zone')
+ ae = AlarmEvent(event=event, zone=zone)
+ ae.put()
+ self.response.set_status(200)
+
+ def post(self):
+ event = self.request.get('event')
+ zone = self.request.get('zone')
+ ae = AlarmEvent(event=event, zone=zone)
+ ae.put()
+ self.response.set_status(200)
app = webapp.WSGIApplication([
-# ('/api/log', LogHandler),
+ ('/api/log', LogHandler),
('/', IndexHandler)],
debug=True)
View
@@ -1,2 +1,13 @@
-<H1>Sensors</H1>
+<h1>Sensors</h1>
+
+
+<table border="1">
+
+ <tr><th>Timestamp</th><th>Event</th><th>Zone</th></tr>
+
+ {% for ae in alarmevents %}
+ <tr><td>{{ae.created}} GMT</td><td>{{ae.event}}</td><td>{{ae.zone}}</td></tr>
+ {% endfor %}
+
+</table>

0 comments on commit af3ffcd

Please sign in to comment.