Commits

daehee han committed 23ce2a1

add entity handling

  • Participants
  • Parent commits afd6e18

Comments (0)

Files changed (3)

+<html>
+  <head>
+    <link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
+  </head>
+  <body>
+    {% for entity in entities %}
+        <div>{{ entity.eid }}</div>  
+		<div>{{ entity.word|escape }}</div>  
+        <div>{{ entity.ehtype }}</div>  
+        <div>{{ entity.parent }}</div>  
+    {% endfor %}
+
+    <form action="/add" method="post">
+      <div><input type="text" name="eid"></div>
+      <div><input type="text" name="word"></div>
+      <div><input type="text" name="ehtype"></div>
+      <div><input type="text" name="parent"></div>
+      <div><input type="submit" value="Commit"></div>
+    </form>
+
+    <a href="{{ url }}">{{ url_linktext }}</a>
+
+  </body>
+</html>

File index.yaml

-indexes:
-
-# AUTOGENERATED
-
-# This index.yaml is automatically updated whenever the dev_appserver
-# detects that a new type of query is run.  If you want to manage the
-# index.yaml file manually, remove the above marker line (the line
-# saying "# AUTOGENERATED").  If you want to manage some indexes
-# manually, move them above the marker line.  The index.yaml file is
-# automatically uploaded to the admin console when you next deploy
-# your application using appcfg.py.
-
-- kind: Greeting
-  properties:
-  - name: date
-    direction: desc

File ktmt_insert.py

+import cgi
+import os
+
+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
+from google.appengine.ext import ndb
+from google.appengine.ext.webapp import template
+
+class EntityDict(ndb.Model):
+  eid = ndb.IntegerProperty()
+  word = ndb.StringProperty()
+  ehtype = ndb.StringProperty() 
+  parent = ndb.IntegerProperty()
+  date = ndb.DateTimeProperty(auto_now_add=True)
+
+class MainPage(webapp.RequestHandler):
+  def get(self):
+    myquery = EntityDict.all().order('-date')
+    entities = myquery.fetch(10)
+
+    if users.get_current_user():
+      url = users.create_logout_url(self.request.uri)
+      url_linktext = 'Logout'
+    else:
+      url = users.create_login_url(self.request.uri)
+      url_linktext = 'Login'
+
+    template_values = {
+      'entities': entities,
+      'url': url,
+      'url_linktext': url_linktext,
+      }
+
+    path = os.path.join(os.path.dirname(__file__), 'entity.html')
+    self.response.out.write(template.render(path, template_values))
+    
+class AddEntity(webapp.RequestHandler):
+  def post(self):
+    entity = EntityDict()
+
+    if not users.get_current_user():
+      self.response.out.write('<html>NOT OK</html>')
+      return
+		
+    entity.eid = self.request.get('eid')
+    entity.word = self.request.get('word')
+    entity.ehtype = self.request.get('ehtype')
+    entity.parent = self.request.get('parent')
+    entity.put()
+    self.response.out.write('<html>OK</html>')
+    #self.redirect('/')
+
+
+application = webapp.WSGIApplication(
+                                     [
+									('/', MainPage),
+									('/add', AddEntity),
+									  ],
+                                     debug=True)
+
+def main():
+  run_wsgi_app(application)
+
+if __name__ == "__main__":
+  main()