Commits

Kang-min Wang  committed 653a287

base GetData done , need to add memcache

  • Participants
  • Parent commits 201f39d
  • Branches testing

Comments (0)

Files changed (1)

 from django.utils import simplejson
 
 
-class MainPage(webapp.RequestHandler):
-
-    def get(self):
-        dbJoke = model.Joke.all()
-        self.response.out.write(template.render('templates/main.html',
-                                    {'jResult': dbJoke}))
-
-class SaveData(webapp.RequestHandler):
-
-    def get(self):
-        self.redirect('/')
-
-    def post(self):
-        jWhen = self.request.get('txtWhen')
-        jWhere = self.request.get('txtWhere')
-        jWho = self.request.get('txtWho')
-        jWhat = self.request.get('txtWhat')
-        try:
-            dbJoke = model.Joke(
-                            jWhen = cgi.escape(jWhen),
-                            jWhere = cgi.escape(jWhere),
-                            jWho = cgi.escape(jWho),
-                            jWhat = cgi.escape(jWhat)
-                        ).put()
-            self.redirect('/')
-            dd = GetJoke()
-            memcache.set('Joke',dd)
-        except BadValueError:
-            self.response.out.write('<center><p align="center">You should input some data! chu~mi~  ^.< </p><p align="center"><a href="/">&laquo; 返回</a></p>')
-
-class GetData(webapp.RequestHandler):
-    """
-    Get JW
-    """
-    def get(self):
-        MyData = memcache.get('Joke')
-
-        if MyData is None:
-            MyData = GetJoke()
-        self.response.out.write(simplejson.dumps(MyData))
-
-def GetJoke():
-    """
-    Get Joke data
-    """
-    query = model.Joke.all()
-    #query.order('-date')
-    data = query.fetch(5000)
-
-    if len(data) > 0:
-        dd = []
-        for d in data:
-            tmp = {}
-            tmp['jWhen'] = d.jWhen
-            tmp['jWhere'] = d.jWhere
-            tmp['jWho'] = d.jWho
-            tmp['jWhat'] = d.jWhat
-
-            dd.append(tmp)
-    return dd
-
-
 class GetConfInfo(  webapp.RequestHandler ):
     """
     Get conference joke information
         conf_data = conf_query.fetch(1)
 
         #get confjoke
-        #joke_query = model.Joke.all()
-        #joke_query.filter("conf =". conf_data)
-        print conf_data
+        #FIXME:need use memcache
+        joke_query = model.Joke.all()
+        joke_query.filter("conf =", conf_data[0])
+        joke_query.fetch(1000)
 
+        output = []
+        for d in joke_query:
+            output.append(
+                {'what':d.what,
+                 'when':d.when,
+                 'who':d.who,
+                 'where':d.where,
+                 #FIXME:need define output format
+                 'time':d.time.isoformat()}
+            )
 
-
-
+        self.response.out.write(simplejson.dumps(output))
 
 def main():
     application = webapp.WSGIApplication([