def get(self): uastring = self.request.headers.get("user_agent") if is_mobile(uastring): self.redirect("/mobile") template = template_env.get_template("index.html") # check if we have a cached result cache_key = 'ventures_all' template_vars = memcache.get(cache_key) # return result from cache if found if template_vars is not None: self.response.out.write(template.render(template_vars)) return logging.info('CACHE MISS: %s' % cache_key) # cache miss so get from datastore ventures = Venture.all() coords = get_coords(ventures) template_vars = {"coords": coords} # add template_vars to cache so subsequent checks are quicker memcache.set(cache_key, template_vars) self.response.out.write(template.render(template_vars))
def get(self): uniqueid = int(self.request.get("uniqueid")) # check if we have a cached result cache_key = 'venture_%d' % uniqueid venture = memcache.get(cache_key) # return result from cache if found if venture is None: logging.info('CACHE MISS: %s' % cache_key) # cache miss so get from datastore venture = Venture.get_one("uniqueid", uniqueid) if venture: if venture.approved: template = template_env.get_template("venture.html") template_vars = {"venture": venture} else: template = template_env.get_template("unapproved.html") template_vars = {"venture": venture} else: template = template_env.get_template("notfound.html") template_vars = {"uniqueid": uniqueid} # add template_vars to cache so subsequent checks are quicker memcache.set(cache_key, venture) self.response.out.write(template.render(template_vars))
def post(self): uniqueid = int(cgi.escape(self.request.get("uniqueid"))) venture = Venture.get_one("uniqueid", uniqueid) venture.approved = True venture.save() # flush cache as state of venture has changed memcache.flush_all() self.redirect("/admin/venture/?uniqueid=%d" % venture.uniqueid)
def post(self): venture_vals = {} venture = Venture() venture_keys = ["name", "street", "street2", "city", "county", "postcode", "latitude", "longitude", "category", "website", "email", "phone"] for item in venture_keys: venture_vals[item] = cgi.escape(self.request.get(item)) for value in venture_vals: setattr(venture, value, str(venture_vals[value])) try: image = self.request.get('img') venture.logo = db.Blob(image) except: pass if "http://" in venture.website: venture.website = venture.website.replace("http://", "") venture.approved = False venture.save() send_addition_email(venture) # flush on successful save to force cache rebuild memcache.flush_all() template_vars = {"venture" : venture} template = template_env.get_template("unapproved.html") time.sleep(3) #Errors switching from add to unapproved, adding delay to try and fix. self.response.out.write(template.render(template_vars))
def post(self): venture_vals = {} venture = Venture() venture_keys = ["name", "street", "city", "county", "postcode", "latitude", "longitude", "category", "website", "email", "phone"] for item in venture_keys: venture_vals[item] = cgi.escape(self.request.get(item)) for value in venture_vals: setattr(venture, value, str(venture_vals[value])) try: image = self.request.get('img') venture.logo = db.Blob(image) except: pass venture.approved = False venture.save() # flush on successful save to force cache rebuild memcache.flush_all() self.redirect("/venture/?uniqueid=%d" % venture.uniqueid)
def get(self): template = template_env.get_template("index.html") category = self.request.get("category") # check if we have a cached result cache_key = 'ventures_category_%s' % category template_vars = memcache.get(cache_key) # return result from cache if found if template_vars is not None: self.response.out.write(template.render(template_vars)) return # cache miss so get from datastore logging.info('CACHE MISS: %s' % cache_key) ventures = Venture.get_many("category", category) coords = get_coords(ventures) template_vars = {"coords": coords} # add template_vars to cache so subsequent checks are quicker memcache.set(cache_key, template_vars) self.response.out.write(template.render(template_vars))
def get(self): uniqueid = int(self.request.get("uniqueid")) # check if we have a cached result cache_key = 'venture_image_%s' % uniqueid image = memcache.get(cache_key) # return result from cache if found if image is not None: self.response.headers['Content-Type'] = 'image/png' self.response.out.write(image) return logging.info('CACHE MISS: %s' % cache_key) venture = Venture.get_one("uniqueid", uniqueid) image = venture.logo if venture.logo: image = images.resize(image, 96, 96) self.response.headers['Content-Type'] = 'image/png' # add image to cache so subsequent checks are quicker memcache.set(cache_key, image) self.response.out.write(image) else: self.abort(404)
def get(self): uniqueid = int(self.request.get("uniqueid")) venture = Venture.get_one("uniqueid", uniqueid) template = template_env.get_template("venture.html") template_vars = {"venture": venture} self.response.out.write(template.render(template_vars))
def get(self): ventures = Venture.get_many("approved", False) template_vars = {"ventures": ventures} template = template_env.get_template("approvals.html") self.response.out.write(template.render(template_vars))