Commits

Kang-min Wang committed 5feaac2

add init method

Comments (0)

Files changed (1)

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from google.appengine.ext import webapp
+from google.appengine.ext.webapp import util
+from google.appengine.api import users
+from google.appengine.ext.db import BadValueError
+import model
+
+class Init( webapp.RequestHandler ):
+    def get(self):
+        if users.is_current_user_admin():
+            self.response.out.write('admin')
+
+            default_conf_name = "COSCUP2011"
+            default_conf_desc = "It's a conference"
+
+            query = model.Conference.all()
+            query.filter("name =", default_conf_name)
+            query.fetch(1)
+
+            if query.count() == 0 :
+                try:
+                    model.Conference(
+                        name = default_conf_name,
+                        desc = default_conf_desc
+                    ).put()
+                except BadValueError:
+                    self.response.out.write('init fail')
+        else:
+            self.response.out.write('nothing')
+
+def main():
+    application = webapp.WSGIApplication(
+                        [('/init', Init)],
+                        debug=True)
+    util.run_wsgi_app(application)
+
+
+if __name__ == '__main__':
+    main()