Esempio n. 1
0
    def get(self):
        c = h.context()
        logging.info("***Auth2")
        cookies = h.get_default_cookies(self)
        c['cookies'] = cookies
        logging.info("***cookies: "+str(cookies))
        c['access_token'] = self.request.get("access_token")
        
        if self.request.get("access_token") == '':
            logging.error("No access token set, but we expected on %s" % str(self.request.url))
        else:
            logging.warning("Got access token %s" % self.request.get("access_token"))
        
        user = User.gql("WHERE fb_oauth_access_token = :1", self.request.get("access_token")).get()
        if user != None:
            # If the user currently exists in the DB
            logging.info("***SCU1")
            h.set_current_user(cookies, user)
            logging.info("***cookies: "+str(cookies))
            c['current_user'] = user
        else: 
            # Look user up in graph, and either find them in the DB or create them if they don't exist
            try:
                graph = facebook.GraphAPI(self.request.get("access_token"))
                me = graph.get_object('me')
            except Exception, e:
                logging.error(
                    "ERROR!  Failed to access Facebook Graph for access_token=" + 
                    self.request.get("access_token") +
                    "::" + str(e)) 
                me = None
                c['error'] = e

            if me != None:
                og_user = User.gql("WHERE fb_user_id = :1", str(me['id'])).get()
                
                if og_user == None:
                    new_user = User(
                        fb_user_id = str(me['id']),
                        fb_oauth_access_token = self.request.get("access_token"),
                        fb_oauth_access_token_stored_at = datetime.datetime.utcnow(),
                        first_name = me['first_name'], 
                        last_name = me['last_name'])
                    if 'email' in me:
                        new_user.email = me['email']
                    new_user.put()
                    logging.info("***SCU2")
                    h.set_current_user(cookies, new_user)
                    logging.info("***cookies: "+str(cookies))
                    c['current_user'] = new_user
                    
                else: # Update auth token for user because it's out of date
                    og_user.fb_oauth_access_token = self.request.get("access_token")
                    og_user.fb_oauth_access_token_stored_at = datetime.datetime.utcnow()
                    og_user.put()
                    logging.info("***SCU3")
                    h.set_current_user(cookies, og_user)
                    logging.info("***cookies: "+str(cookies))
                    c['current_user'] = og_user
Esempio n. 2
0
 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)
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)
Esempio n. 5
0
 def get(self):
     c = h.context()
     c['model'] = 'user'
     c['model_properties'] = sorted(User.properties())
     h.render_out(self, 'admin.tplt', c)
Esempio n. 6
0
 def get(self):
     c = h.context()
     h.render_out(self, 'stash.tplt', c)
Esempio n. 7
0
 def get(self):
     c = h.context()
     c['model'] = 'kvaluemetric'
     c['model_properties'] = sorted(KValueMetric.properties())
     h.render_out(self, 'admin.tplt', c)
Esempio n. 8
0
 def get(self):
     c = h.context()
     c['model'] = 'pageview'
     c['model_properties'] = sorted(PageView.properties())
     h.render_out(self, 'admin.tplt', c)
Esempio n. 9
0
 def get(self):
     c = h.context()
     c['model'] = 'organicsearchmetric'
     c['model_properties'] = sorted(OrganicSearchMetric.properties())
     h.render_out(self, 'admin.tplt', c)
Esempio n. 10
0
 def get(self):
     c = h.context()
     c['model'] = 'postinstallactivitymetric'
     c['model_properties'] = sorted(PostInstallActivityMetric.properties())
     h.render_out(self, 'admin.tplt', c)
Esempio n. 11
0
 def get(self):
     c = h.context()
     c['model'] = 'query'
     c['model_properties'] = sorted(Query.properties())
     h.render_out(self, 'admin.tplt', c)
Esempio n. 12
0
 def get(self):
     c = h.context()
     c['model'] = 'installmetric'
     c['model_properties'] = sorted(InstallMetric.properties())
     h.render_out(self, 'admin.tplt', c)
Esempio n. 13
0
 def get(self):
     c = h.context()
     c['upload_url'] = blobstore.create_upload_url('/qup')
     h.render_out(self, 'question_uploader.tplt', c)
Esempio n. 14
0
 def get(self):
     c = h.context()
     c['current_user'] = h.login_optional(self)
     h.render_out(self, 'main.html', c)
Esempio n. 15
0
 def get(self):
     c = h.context()
     h.render_out(self, 'cookie_test.tplt', c)
Esempio n. 16
0
 def get(self):
     c = h.context()
     a = self.request.get("a")
     qk = self.request.get("qk")
     self.add_answer(a, qk)
     h.output(self, "ok")
Esempio n. 17
0
    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)