1. Constantin Veretennicov
  2. tracko

Source

tracko / app / admin.py

from __future__ import with_statement

import os, cgi, urllib, pprint, logging

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
import wsgiref.handlers

import settings


class AdminHandler(webapp.RequestHandler):
  def get(self):
    template_values = {
      'settings': [
        dict(name=name, label=description, value=settings.get_value(name))
        for (name, (description, _, _))
        in sorted(settings.meta.iteritems(), key=lambda x: x[1][0])]}
    path = os.path.join(os.path.dirname(__file__), 'templates', 'admin.html')
    self.response.out.write(template.render(path, template_values))

class SaveSettingsHandler(webapp.RequestHandler):
  def post(self):
    settings.set_values(
      **dict(
        (name, parse(self.request.get(name)))
        for (name, (_, _, parse)) in settings.meta.iteritems()))
    self.redirect('/admin')


def create_application():
  return webapp.WSGIApplication(
    [('/admin', AdminHandler),
     ('/admin/save', SaveSettingsHandler)],
    debug=True)

def main():
  wsgiref.handlers.CGIHandler().run(create_application())

if __name__ == '__main__':
  main()