def get(self): c = h.context() query = Question.all() results = query.fetch(1000) for q in results: q.i = str(q.img.key()) q.k = q.key() c['questions'] = results h.render_out(self, 'question_admin.tplt', c)
def get(self): c = h.context() s = self.request.get("s") c["s"] = s c["data"] = xrange(6) r = list() r += [[0, 0]] r += [[253, 0]] r += [[506, 0]] r += [[0, 253]] r += [[253, 253]] r += [[506, 253]] c["rects"] = r c["stash_items"] = xrange(7) cookies = h.get_default_cookies(self) u = h.get_current_user(cookies) if u: c["uid"] = u.fb_user_id # get some appropriate questions query = Question.all() query.filter("qtype =", 1).filter("status =", 1) questions = query.fetch(1000) building = list() for o in questions: d = dict() # d['qtype'] = o.qtype d["key"] = str(o.key()) d["qtext"] = o.qtext d["hint"] = o.hint d["img"] = str(o.img.key()) # d['status'] = o.status # d['created_at'] = str(o.created_at) building += [d] c["questions"] = simplejson.dumps(building) answers = self.get_answers() building = list() for o in answers: d = dict() d["key"] = str(o.key()) d["atext"] = o.atext d["qkey"] = str(o.qkey) building += [d] c["answers"] = simplejson.dumps(building) h.render_out(self, "questions.tplt", c)
def get(self): c = h.context() if self.request.get("auth") == "1": c["current_user"] = h.login_required(self) if c["current_user"] == None: return None else: c["current_user"] = h.login_optional(self) c["url"] = self.request.get("u") c["query"] = self.request.get("q") c["start"] = self.request.get("start") in_fb = self.request.get("infb").lower() == "true" c["was_in_facebook"] = in_fb c["this_result_url"] = self.request.url c["next_href_root"] = "http://next_href_root" curr_base_url = (h.cfg["direct_url"], h.cfg["fb_url"])[in_fb] c["back_to_results_href"] = curr_base_url + "/results?q=" + c["query"] + "&start=" + c["start"] c["next_step_href"] = c["back_to_results_href"] # curr_base_url h.render_out(self, "framed_result.tplt", c)
def get(self): c = h.context() h.render_out(self, 'stash.tplt', c)
def get(self): c = h.context() c['model'] = 'user' c['model_properties'] = sorted(User.properties()) h.render_out(self, 'admin.tplt', c)
def get(self): c = h.context() c['model'] = 'pageview' c['model_properties'] = sorted(PageView.properties()) h.render_out(self, 'admin.tplt', c)
def get(self): c = h.context() c['model'] = 'kvaluemetric' c['model_properties'] = sorted(KValueMetric.properties()) h.render_out(self, 'admin.tplt', c)
def get(self): c = h.context() c['model'] = 'postinstallactivitymetric' c['model_properties'] = sorted(PostInstallActivityMetric.properties()) h.render_out(self, 'admin.tplt', c)
def get(self): c = h.context() c['model'] = 'organicsearchmetric' c['model_properties'] = sorted(OrganicSearchMetric.properties()) h.render_out(self, 'admin.tplt', c)
def get(self): c = h.context() c['model'] = 'installmetric' c['model_properties'] = sorted(InstallMetric.properties()) h.render_out(self, 'admin.tplt', c)
def get(self): c = h.context() c['model'] = 'query' c['model_properties'] = sorted(Query.properties()) h.render_out(self, 'admin.tplt', c)
def get(self): c = h.context() c['current_user'] = h.login_optional(self) h.render_out(self, 'main.html', c)
def get(self): c = h.context() h.render_out(self, 'cookie_test.tplt', c)
# Reparse user graph on login graph_task_url = 'http://'+self.request.host+'/users/tasks/fetchgraph?key='+str(c['current_user'].key()) rpc = urlfetch.create_rpc(deadline=1) urlfetch.make_fetch_call(rpc,graph_task_url) try: result_body = rpc.get_result() except urlfetch.DownloadError, e: logging.error("User Auth couldn't contact graph task url %s, got error:%s" % (graph_task_url, str(e))) else: logging.info("***Sent home due to lack of post_auth or current_user") c['top_redirect_url'] = h.cfg['fb_url'] # self.redirect('/') h.render_out(self, "redirector.tplt", c) # *** Globals - Need to fix this to find handlers by string routing =[ ('/',ResultsHandler), ('/test',MainHandler), ('/auth2',Auth2Handler), ('/admin',AdminHandler), ('/admin/pageviews',AdminPageViewsHandler), ('/admin/pageviews/data.json',AdminPageViewsDataHandler), ('/admin/pageviews/normalizer', AdminPageViewNormalizerHandler), ('/admin/users',AdminUsersHandler), ('/admin/users/data.json',AdminUsersDataHandler), ('/admin/usergraphs',AdminUserGraphsHandler), ('/admin/usergraphs/data.json',AdminUserGraphsDataHandler),
def get(self): img_rows = 3 c = h.context() query = self.request.get('q') force_quest = self.request.get('force_quest') if not query: query = "red" c['query'] = query # fetch the google image results ue_query = urllib.quote_plus(query) c['ue_query'] = ue_query url = 'http://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=large&q='\ +ue_query+'&key='\ +h.cfg['gs_api_key'] url2 = 'http://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=large&start=8&q='\ +ue_query+'&key='\ +h.cfg['gs_api_key'] url3 = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q='\ +ue_query+'&key='\ +h.cfg['gs_api_key'] rpcs = [] rpc = urlfetch.create_rpc(10) urlfetch.make_fetch_call(rpc,url) rpcs.append(rpc) rpc = urlfetch.create_rpc(10) urlfetch.make_fetch_call(rpc,url2) rpcs.append(rpc) rpc = urlfetch.create_rpc(10) urlfetch.make_fetch_call(rpc,url3) rpcs.append(rpc) for rpc in rpcs: rpc.wait() result = rpcs[0].get_result() result2 = rpcs[1].get_result() result_web = rpcs[2].get_result() o = simplejson.loads(result.content) o2 = simplejson.loads(result2.content) o_web = simplejson.loads(result_web.content) from print_r import print_r #c['content'] = print_r(o_web, False) c['ad'] = "" all_imgs = o['responseData']['results']+o2['responseData']['results'] c['web_data'] = o_web['responseData']['results'] # calculate appropriate sizes for image placement c['max_height'] = int(max(all_imgs, key=lambda x: int(x['tbHeight']))['tbHeight']) c['row_height'] = c['max_height']+20 # borders to make all the img divs the same size for i in all_imgs: i['bot_border'] = (c['row_height']-int(i['tbHeight']))/2 i['top_border'] = c['row_height']-int(i['tbHeight'])-i['bot_border'] i['right_margin'] = 5 # init loop variables c['mini_imgs'] = list() start_img = 0 curr_img = 0 done = False # begin the super ugly loop to generate rows while not done: taken_px = 0 row_done = False num_imgs = 0 # figure out how many images we can place in the row given the normal size while not row_done: additional_px = 0 additional_px += 20 # min right & left border additional_px += int(all_imgs[curr_img]['tbWidth']) # image itself if taken_px+additional_px > 758: row_done = True #done = True num_imgs = curr_img - start_img else: additional_px += 5 # white margin between images (the last one doesn't have it) taken_px += additional_px curr_img += 1 if curr_img >= len(all_imgs): num_imgs = curr_img - start_img row_done = True done = True # now take all the remaining space and distribute it to the borders of the images remaining_space = 758-taken_px border_px = int(remaining_space/(num_imgs*2)+10) remainder = remaining_space-(border_px-10)*2*num_imgs row_imgs = all_imgs[start_img:start_img+num_imgs] # hand out the border px to the images and get rid of the remainder (also add the index) for i in row_imgs: i['left_border'] = border_px if(remainder > 0): i['left_border'] += 1 remainder -= 1 i['right_border'] = border_px if(remainder > 0): i['right_border'] += 1 remainder -= 1 c['num_imgs'] = num_imgs # set the last img in a row to have no 5px margin row_imgs[len(row_imgs)-1]['right_margin'] = 0 c['mini_imgs'].append(row_imgs) if len(c['mini_imgs']) >= img_rows: done = True start_img += num_imgs # pick up the questions and images for the q = None if not force_quest: query = Question.all() results = query.fetch(1000) if len(results) > 0: import random q = random.choice(results) else: # Added this to prevent IndexError: list index out of range in development q = Question() else: k = db.Key(force_quest) q = db.get(k) image_key = q.img.key() if q.img is not None else '' # Added to make development safe c['header_img'] = h.cfg['direct_url']+'/public/srp_top_channel_2.png' #+'/serve/'+str(image_key) c['header_txt'] = 'Find something you like!' #q.qtext c['hint'] = 'type something.' #q.hint c['header_repeat'] = 'repeat-x' c['header_height'] = '80px' if not c['hint']: c['hint'] = "type something." c['search_form_display'] = "block" c['translucent_overlay_display'] = "none" c['little_arrow_display'] = "none" h.render_out(self, 'results.tplt', c)
def get(self): c = h.context() c['upload_url'] = blobstore.create_upload_url('/qup') h.render_out(self, 'question_uploader.tplt', c)