def get(self): page = self.request.get("page") if page: page = int(page) else: page = 1 apiresult = memcache.get("apiresult") if apiresult is None: radars = db.GqlQuery( "select * from Radar order by number desc").fetch( 100, (page - 1) * 100) response = {"result": [r.key().id() for r in radars]} apiresult = simplejson.dumps(response) self.respondWithText(apiresult)
def get(self): user = self.GetCurrentUser() if (not user): self.respondWithDictionaryAsJSON({ "error": "please authenticate by setting the Authorization header to your API key (http://www.openradar.me/apikey)" }) return page = self.request.get("page") if page: page = int(page) else: page = 1 if page > 10: self.respondWithText("") return count = self.request.get("count") if count: count = int(count) else: count = 100 apiresult = memcache.get("apiresult") if apiresult is None: radars = db.GqlQuery( "select * from Radar order by number_intvalue desc").fetch( count, (page - 1) * count) response = { "result": [{ "id": r.key().id(), "classification": r.classification, "created": str(r.created), "description": r.description, "modified": str(r.modified), "number": r.number, "originated": r.originated, "parent": r.parent_number, "product": r.product, "product_version": r.product_version, "reproducible": r.reproducible, "resolved": r.resolved, "status": r.status, "title": r.title, "user": r.user.email() } for r in radars] } apiresult = simplejson.dumps(response) #memcache.add("apiresult", apiresult, 600) # ten minutes, but we also invalidate on edits and adds self.respondWithText(apiresult)
def get(self): user = self.GetCurrentUser() if (not user): self.respondWithDictionaryAsJSON({ "error": "please authenticate by setting the Authorization header to your API key (http://www.openradar.me/apikey)" }) return page = self.request.get("page") if page: page = int(page) else: page = 1 if page > 10: self.respondWithText("") return count = self.request.get("count") if count: count = int(count) else: count = 100 comments = db.GqlQuery( "select * from Comment order by posted_at desc").fetch( count, (page - 1) * count) result = [] for c in comments: try: commentInfo = { "id": c.key().id(), "user": c.user.email(), "subject": c.subject, "body": c.body, "radar": c.radar.number, "created": str(c.posted_at), } if c.is_reply_to: commentInfo["is_reply_to"] = c.is_reply_to.key().id() result.append(commentInfo) except Exception: None # we'll get here if the corresponding radar was deleted response = {"result": result} apiresult = simplejson.dumps(response) self.respondWithText(apiresult)
def get(self): user = self.GetCurrentUser() if (not user): self.respondWithDictionaryAsJSON({ "error": "please authenticate by setting the Authorization header to your API key (http://www.openradar.me/apikey)" }) return cursor = self.request.get("cursor") if cursor: cursor = cursor else: cursor = None comments = db.GqlQuery("select * from Comment order by posted_at desc") if cursor: comments.with_cursor(start_cursor=cursor) results = [] for c in comments: try: results.append({ "id": c.key().id(), "user": c.user.email(), "subject": c.subject, "body": c.body, "radar": c.radar.number, "posted_at": str(c.posted_at), "is_reply_to": c.is_reply_to and c.is_reply_to.key().id() or None }) except Exception: None if len(results) == 100: break response = {"result": results, "cursor": comments.cursor()} apiresult = simplejson.dumps(response) self.respondWithText(apiresult)
def get(self): user = self.GetCurrentUser() if (not user): self.respondWithDictionaryAsJSON({ "error": "please authenticate by setting the Authorization header to your API key (http://www.openradar.me/apikey)" }) return cursor = self.request.get("cursor") if cursor: cursor = cursor else: cursor = None radars = db.GqlQuery("select * from Radar order by modified desc") if cursor: radars.with_cursor(start_cursor=cursor) results = [] for r in radars: results.append({ "id": r.key().id(), "title": r.title, "number": r.number, "user": r.user.email(), "status": r.status, "description": r.description, "resolved": r.resolved, "product": r.product, "classification": r.classification, "reproducible": r.reproducible, "product_version": r.product_version, "created": str(r.created), "modified": str(r.modified), "originated": r.originated }) if len(results) == 100: break response = {"result": results, "cursor": radars.cursor()} apiresult = simplejson.dumps(response) self.respondWithText(apiresult)
def render_front(self, title="", art="", error=""): arts = db.GqlQuery("select * from Art" "ORDER BY created DESC") self.render('front.html', title=title, art=art, error=error, arts=arts)
class Hello(Handler): @@ -16,3 +17,30 @@ class ShoppingList(Handler): def get(self): items = self.request.get_all("food") self.render("shopping_list.html", title="Shopping List", items=items) + +class Art(db.Model): + title = db.StringProperty(required = True) + art = db.TextProperty(required = True) + created = db.DateTimeProperty(auto_now_add = True) + +class AsciiChan(Handler): + + def render_front(self, title="", art="", error=""): + arts = db.GqlQuery("SELECT * FROM Art ORDER BY created DESC") + self.render("asciichan.html", title=title, art=art, error=error, arts=arts) + + def get(self): + self.render_front() + + @db.transactional + def post(self): + title = self.request.get("title") + art = self.request.get("art") + + if title and art: + a = Art(title=title, art=art) + a.put() + self.redirect("/asciichan") + else:
class Blog(BaseHandler): def get(self): posts = db.GqlQuery("SELECT * FROM Post LIMIT 10")