def get(self): device = self.determine_device() search_term = self.request.get('searchbox') access_token, fb_user, fb_name = self.pull_data_from_session() audit.add_audit_record(fb_user,fb_name,'search_page', self.request.remote_addr, device) long_lived_token = fbtokenutil.genLongLivedAccessToken(fb_user,access_token) posts_matching_search = fbmessages.find_search_term(search_term ,fb_user, self.is_mobile_request()) results = fbmessages.to_serializable_list(posts_matching_search) min_date, max_date = fbmessages.find_min_max_post_dates(fb_user) template_values = {'last_search_term': search_term, 'results': self.handle_no_results_found(results), 'minDate': min_date.strftime("%d-%m-%Y"), 'maxDate': max_date.strftime("%d-%m-%Y") } template = jinja_environment.get_template('app.html') self.response.out.write(template.render(template_values))
def post(self): session = get_current_session() signed_request = self.request.get('signed_request') logging.info('Signed Request ' + signed_request) if (signed_request is not None and signed_request is not ''): logging.info('Signed request populated. About to base64 decode it') base_encoded_data = base64.b64decode(signed_request) logging.info(base_encoded_data) self.response.out.write('Base 64 decoded ' + base_encoded_data) else: session['last_search_results'] = '' search_terms = self.request.get('search_terms') session['last_search_term'] = search_terms logging.info(search_terms) max_posts = self.request.get('max_posts') logging.info(max_posts) token = self.request.get('token') logging.info(token) accessToken = memcache.get(token) fbUser, fbName = self.getUsersIdAndFullNameByAccessToken(accessToken) device = self.determine_device() audit.add_audit_record(fbUser,fbName,'search_page', self.request.remote_addr, device) long_lived_token = fbtokenutil.genLongLivedAccessToken(fbUser,accessToken) logging.info("about to call a search ") #delete_results_of_last_search(gen_search_results_key(fbUser)) posts_matching_search = fbmessages.find_search_term(search_terms ,fbUser, self.is_mobile_request()) jsonResults = {} lst = fbmessages.to_serializable_list(posts_matching_search) if (len(lst) < 1): session['last_search_term'] = '' #cache_results_of_last_search(gen_search_results_key(fbUser),lst) jsonResults['matchingResults'] = lst listToJson = json.dumps(jsonResults); session['last_search_results'] = listToJson logging.info("Last search entry added to session") self.response.out.write(listToJson)