def get(self): logging.info('category list handler ') self.redirect_perm() self.get_user() logging.info('category screen_name %s' %self.screen_name) if self.avatar is None: self.avatar='/static/images/noavatar.png' memcache_key='category_list' cached_category=memcache.get(memcache_key) categories={} if cached_category is not None: logging.info('picking up cats from cache') categories=cached_category else: logging.info('fetching trending cats' ) categories = LinkCategory.get_trending() next_hour = datetime.datetime.now() + datetime.timedelta(hours=1) next_hour_ts = time.mktime(next_hour.timetuple()) if categories is not None and len(categories) > 0: memcache.set(memcache_key, categories, time = next_hour_ts) template_variables = [] if categories is None: categories = LinkCategory.get_trending(24) else: logging.info("got %s categories" % len(categories)) template_variables = {'page_footer': PageUtils.get_footer(), 'user':self.screen_name, 'logout_url':'/account/logout', 'avatar':self.avatar,'categories':LinkUtils.getCategoryListHTML(categories)} path= os.path.join(os.path.dirname(__file__), 'templates/category_list.html') self.response.headers["Content-Type"] = "text/html; charset=utf-8" self.response.out.write(template.render(path,template_variables))