Created
January 7, 2010 19:55
-
-
Save franckverrot/271504 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cgi | |
from django.utils import simplejson | |
from google.appengine.api import users | |
from google.appengine.ext import webapp | |
from google.appengine.ext.webapp.util import run_wsgi_app | |
from google.appengine.ext import db | |
class Hook(db.Model): | |
name = db.TextProperty() | |
info = db.TextProperty() | |
version = db.TextProperty() | |
authors = db.TextProperty() | |
downloads = db.IntegerProperty() | |
project_uri = db.TextProperty() | |
gem_uri = db.TextProperty() | |
version = db.TextProperty() | |
received_at = db.DateTimeProperty(auto_now_add=True) | |
class MainPage(webapp.RequestHandler): | |
def get(self): | |
self.response.out.write(""" | |
<html> | |
<body> | |
<ul>""") | |
hooks = db.GqlQuery("SELECT * FROM Hook ORDER BY received_at DESC LIMIT 10") | |
for hook in hooks: | |
self.response.out.write('<li>%(name)s(%(version)s / %(project_uri)s) %(received_at)s %(info)s</li>' % { 'name' : cgi.escape(hook.name), 'version' : cgi.escape(hook.version), 'received_at': cgi.escape(str(hook.received_at)), 'info' : cgi.escape(hook.info), 'project_uri' : cgi.escape(hook.project_uri)}) | |
self.response.out.write("""</ul></body><html>""") | |
class GemcutterHooks(webapp.RequestHandler): | |
def post(self): | |
hook = Hook() | |
data = simplejson.loads(self.request.body) | |
hook.name = cgi.escape(data['name']) | |
hook.info = cgi.escape(data['info']) | |
hook.version = cgi.escape(data['version']) | |
hook.authors = cgi.escape(data['authors']) | |
hook.downloads = data['downloads'] | |
hook.project_uri = cgi.escape(data['project_uri']) | |
hook.gem_uri = cgi.escape(data['gem_uri']) | |
hook.put() | |
self.redirect('/') | |
application = webapp.WSGIApplication( | |
[('/', MainPage), | |
('/hooks', GemcutterHooks)], | |
debug=True) | |
def main(): | |
run_wsgi_app(application) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment