Esempio n. 1
0
 def post(self):
     cookies = h.get_default_cookies(self)
     current_user = h.get_current_user(cookies)
     
   	if current_user != None and '_pvk' in cookies and cookies['_pvk'] != None and cookies['_pvk'] != '':
         unlinked_result_views = ResultView.gql("WHERE session_id = :1 AND user = NULL", cookies['_pvk']).fetch(5)
         for result_view in unlinked_result_views:
             result_view.user = current_user
             if current_user.fb_user_id != None:
                 result_view.fb_user_id = current_user.fb_user_id
             
             # Create a "backdated" version for this query, because the user probably made the query while 
             # logged out, and it's worthwile knowing that that happened
             if result_view.query_string != None and result_view.query_string != '':
                 query = Query(query_string = result_view.query_string, referrer = self.request.referer, url = "__ARTIFICIALLY_CREATED_FOR_USER__")
                 
                 query.user = current_user
                 if current_user.fb_user_id != None:
                     query.fb_user_id = current_user.fb_user_id
                 if '_pvk' in cookies and cookies['_pvk'] != None and cookies['_pvk'] != '':
                     query.session_id = cookies['_pvk']
                 
                 query.put()
             
                 result_view.query = query
                 result_view.put()
                 fb_post_id = QueryFacebookWallpostHelper.postToWallIfNecessary(current_user, result_view, query, result_view.image_url)
             
             else:
                 result_view.put()
     
     self.response.out.write('{status: \'ok\'}')
Esempio n. 2
0
 def get(self):
     c = h.context()
     c['model'] = 'resultview'
     c['model_properties'] = sorted(ResultView.properties())
     h.render_out(self, 'admin.tplt', c)
Esempio n. 3
0
    def post(self):
        logging.info("***rvlh")
        cookies = h.get_default_cookies(self)
        current_user = h.get_current_user(cookies)
        result_view = ResultView()
      	result_view.source = self.request.get('src')
      	result_view.referrer = self.request.get('referrer')
      	result_view.url = self.request.get('u')
        result_view.ip_address = self.request.remote_addr
        result_view.image_url = self.request.get('image_url')
        result_view.query_string = self.request.get('q')
      	#logging.info(" ".join((result_view.source, result_view.referrer, result_view.url, result_view.ip_address,
        #                       result_view.image_url, result_view.query_string)))
      	if '_pvk' in cookies and cookies['_pvk'] != None and cookies['_pvk'] != '':
            result_view.session_id = cookies['_pvk']
        
        if current_user != None:
            result_view.user = current_user
            if current_user.fb_user_id != None:
                result_view.fb_user_id = current_user.fb_user_id
                
            query = Query.gql(
                "WHERE user = :1 AND query_string = :2 ORDER BY created_at DESC", 
                current_user.key(), 
                self.request.get('q')).get()

            if query != None:
                result_view.query = query

        result_view.put()
        
        # Post to facebook wall for the query if the query hasn't already posted to wall
        if current_user != None and query != None and query.fb_wall_post_id == None:
            logging.info("***Posting")
            image_url = self.request.get('image_url')
            if not image_url:
                from google.appengine.api import urlfetch
                from django.utils import simplejson
                q = 'site:'+result_view.url+" "+result_view.query_string
                ue_query = urllib.quote_plus(q)
                url = 'http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q='\
                      +ue_query+'&key='\
                      +h.cfg['gs_api_key']
                result = urlfetch.fetch(url)
                o = simplejson.loads(result.content)
                image_url = o['responseData']['results'][0]['tbUrl']
            fb_post_id = QueryFacebookWallpostHelper.postToWallIfNecessary(current_user, result_view, query, image_url)
            self.response.out.write('{status: \'ok\', fb_wall_post_id: \'%s\', result_view_key: \'%s\'}' % (fb_post_id, str(result_view.key())))
        else:
            # logging.info("***NoPost : "+current_user+" "+query+" "+query.fb_wall_post_id)
            self.response.out.write('{status: \'ok\', result_view_key: \'%s\', result_view_has_user: \'%s\'}' % (str(result_view.key()), str(current_user != None)))