def activity_suppliers(request, request_type): parameters = {} if request.user.is_authenticated(): user_id = request.user.id user_profile_obj = UserProfile() user_profile = user_profile_obj.get_profile_by_id(str(user_id)) default_lon = float(user_profile['latlng']['coordinates'][0]) default_lat = float(user_profile['latlng']['coordinates'][1]) user_info = UserInfo(user_id) parameters['userinfo'] = user_info default_location = user_profile['zip_code'] no_of_results = 10 subscribed = True customer, created = Customer.get_or_create(request.user) if created: subscribed = False if not customer.has_active_subscription(): subscribed = False if subscribed: no_of_results = 30 else: return HttpResponseRedirect("/activity") request_types = ['suppliers', 'stockists', 'favourites'] if request_type not in request_types: return HttpResponseRedirect("/activity") my_lon = default_lon my_lat = default_lat search_global = subscribed keyword = "" if request.user.is_superuser: search_global = True search_handle = Search(lon=my_lon, lat=my_lat) search_results = search_handle.supplier_updates(user_id, request_type) results = search_results['results'][:no_of_results - 1] results = search_results['results'] if request.user.is_superuser: results = search_results['results'] for i in range(len(results)): results[i] = set_time_date(results[i], "") results[i]['mentions'] = "@" + results[i]['user']['username'] user_loc = results[i]['location'] if results[i]["result_type"] == results[i]["user"]["username"]: tweet_id = results[i]["tweetuid"] replies = search_handle.get_all_children(tweet_id) if replies == None: continue replies = sorted(replies, key=lambda k: k['time_stamp']) for j in range(len(replies)): replies[j] = set_time_date(replies[j], keyword) replies[j]['mentions'] = "@" + results[i]['user'][ 'username'] + " " + replies[j]['mentions'] results[i]['replies'] = replies for i in range(len(results)): from mainapp.profilepage import get_banner_url from mainapp.profilepage import get_video_html banner_url = get_banner_url(username=results[i]['user']['username'], logged_useruid=request.user.id) results[i]['user']['banner_url'] = banner_url user_prof = UserProfile() try: video_url = user_prof.get_profile_by_username( results[i]['user']['username'])['video_url'] video_html = get_video_html(video_url) except: video_url = '' video_html = '' results[i]['user']['intro_video'] = video_html parameters['results'] = results # print len(results) parameters['json_data'] = json.dumps(results) parameters['results_business_count'] = search_results["business_counter"] parameters['results_individual_count'] = search_results[ "individual_counter"] parameters['results_organisation_count'] = search_results[ "organisation_counter"] parameters['results_updates_count'] = search_results["update_counter"] parameters['search'] = { 'query': "", 'place': "", 'lon': my_lon, 'lat': my_lat } # For food Filters food_filters = search_results["foods"] food_filters_count = 0 for f in food_filters: if f["uid"] == "": food_filters.remove(f) else: food_filters_count = food_filters_count + f['value'] parameters['foods_filter'] = json.dumps(food_filters) parameters['food_count'] = int(food_filters_count) # For business Filter business_filters = search_results["businesses"] business_filters_count = 0 business_filters_temp = [] for f in business_filters: if f["uid"] == "": continue else: business_filters_count = business_filters_count + f['value'] business_filters_temp.append(f) business_filters = business_filters_temp parameters['business_filter'] = json.dumps(business_filters) parameters['business_count'] = int(business_filters_count) # For organisation Filter organisation_filters = search_results["organisations"] organisation_filters_count = 0 for f in organisation_filters: if f["uid"] == "": organisation_filters.remove(f) else: organisation_filters_count = organisation_filters_count + f['value'] parameters['organisation_filter'] = json.dumps(organisation_filters) parameters['organisation_count'] = int(organisation_filters_count) return render_to_response('supplier_updates.html', parameters, context_instance=RequestContext(request))
def get_search_parameters(request): parameters = {} default_location = "" no_of_results = 5 if request.user.is_authenticated(): user_id = request.user.id user_profile_obj = UserProfile() user_profile = user_profile_obj.get_profile_by_id(str(user_id)) default_lon = float(user_profile['latlng']['coordinates'][0]) default_lat = float(user_profile['latlng']['coordinates'][1]) user_info = UserInfo(user_id) parameters['userinfo'] = user_info default_location = user_profile['zip_code'] no_of_results = 10 subscribed = True customer, created = Customer.get_or_create(request.user) if created: subscribed = False if not customer.has_active_subscription(): subscribed = False if subscribed: no_of_results = 30 else: x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') if x_forwarded_for: ip = x_forwarded_for.split(',')[0] else: ip = request.META.get('REMOTE_ADDR') location_info = get_addr_from_ip(ip) subscribed = False default_lon = float(location_info['longitude']) default_lat = float(location_info['latitude']) keyword = request.GET.get('q', request.POST.get('q', "")) keyword = keyword.strip() sort = request.GET.get('sort', request.POST.get('sort', "time")) my_lon = request.GET.get('lon', request.POST.get('lon', "")) my_lat = request.GET.get('lat', request.POST.get('lat', "")) location = request.GET.get('location', default_location) biz_request = request.GET.get('b', "") food_request = request.GET.get('f', "") organisation_request = request.GET.get('o', "") no_of_results = 30 if len(biz_request) > 0: businesses = [biz_request] else: businesses = json.loads(request.POST.get('businesses', "[]")) if len(food_request) > 0: foods = [food_request] else: foods = json.loads(request.POST.get('foods', "[]")) if len(organisation_request) > 0: organisations = [organisation_request] else: organisations = json.loads(request.POST.get('organisations', "[]")) if my_lon == "" or my_lat == "": my_lon = default_lon my_lat = default_lat else: my_lat = float(my_lat) my_lon = float(my_lon) keyword = keyword.lower() search_global = subscribed if request.user.is_superuser: search_global = False search_handle = Search(keyword=keyword, lon=my_lon, lat=my_lat, place=location, foods=foods, business=businesses, organisation=organisations, sort=sort, search_global=search_global) search_results = search_handle.search_all() results = search_results['results'][:no_of_results - 1] results = search_results['results'] # if request.user.is_superuser: # results =search_results['results'] for i in range(len(results)): results[i] = set_time_date(results[i], keyword) results[i]['mentions'] = "@" + results[i]['user']['username'] user_loc = results[i]['location'] if results[i]["result_type"] == results[i]["user"]["username"]: tweet_id = results[i]["tweetuid"] replies = search_handle.get_all_children(tweet_id) if replies == None: continue replies = sorted(replies, key=lambda k: k['time_stamp']) for j in range(len(replies)): replies[j] = set_time_date(replies[j], keyword) replies[j]['mentions'] = "@" + results[i]['user'][ 'username'] + " " + replies[j]['mentions'] results[i]['replies'] = replies for i in range(len(results)): from mainapp.profilepage import get_banner_url from mainapp.profilepage import get_video_html banner_url = get_banner_url(username=results[i]['user']['username'], logged_useruid=request.user.id) results[i]['user']['banner_url'] = banner_url user_prof = UserProfile() try: video_url = user_prof.get_profile_by_username( results[i]['user']['username'])['video_url'] video_html = get_video_html(video_url) except: video_url = '' video_html = '' results[i]['user']['intro_video'] = video_html parameters['results'] = results # print len(results) parameters['json_data'] = json.dumps(results) parameters['results_business_count'] = search_results["business_counter"] parameters['results_individual_count'] = search_results[ "individual_counter"] parameters['results_organisation_count'] = search_results[ "organisation_counter"] parameters['results_updates_count'] = search_results["update_counter"] parameters['search'] = { 'query': keyword, 'place': location, 'lon': my_lon, 'lat': my_lat } # For food Filters food_filters = search_results["foods"] food_filters_count = 0 for f in food_filters: if (f["uid"] == food_request or f["uid"].lower() == keyword) and f["uid"] != "": f["prev"] = True if f["uid"] == "": food_filters.remove(f) else: food_filters_count = food_filters_count + f['value'] parameters['foods_filter'] = json.dumps(food_filters) parameters['food_count'] = int(food_filters_count) # For business Filter business_filters = search_results["businesses"] business_filters_count = 0 business_filters_temp = [] for f in business_filters: if f["uid"] == "": continue else: business_filters_count = business_filters_count + f['value'] if (f["uid"] == biz_request or f["uid"].lower() == keyword) and f["uid"] != "": f["prev"] = True business_filters_temp.append(f) business_filters = business_filters_temp parameters['business_filter'] = json.dumps(business_filters) parameters['business_count'] = int(business_filters_count) # For organisation Filter organisation_filters = search_results["organisations"] organisation_filters_count = 0 for f in organisation_filters: if (f["uid"] == organisation_request or f["uid"].lower() == keyword) and f["uid"] != "": f["prev"] = True if f["uid"] == "": organisation_filters.remove(f) else: organisation_filters_count = organisation_filters_count + f['value'] parameters['organisation_filter'] = json.dumps(organisation_filters) parameters['organisation_count'] = int(organisation_filters_count) return parameters
def get_post_parameters(request, tweet_id): parameters={} user_profile_obj = UserProfile() parameters.update(csrf(request)) if request.user.is_authenticated(): user_id = request.user.id user_profile = user_profile_obj.get_profile_by_id(str(user_id)) default_lon = float(user_profile['latlng']['coordinates'][0]) default_lat = float(user_profile['latlng']['coordinates'][1]) user_info = UserInfo(user_id) parameters['userinfo'] = user_info else: x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') if x_forwarded_for: ip = x_forwarded_for.split(',')[0] else: ip = request.META.get('REMOTE_ADDR') location_info = get_addr_from_ip(ip) default_lon = float(location_info['longitude']) default_lat = float(location_info['latitude']) search_handle = Search(lon = default_lon, lat =default_lat) try: single_tweet = search_handle.get_single_tweet(str(tweet_id)) a = single_tweet[0] except: raise Http404 keyword = '' single_tweet = set_time_date(single_tweet[0],keyword) results = search_handle.get_direct_children(str(tweet_id)) # send banner url from mainapp.profilepage import get_banner_url parameters['banner_url'] = get_banner_url(username=single_tweet['user']['username'], logged_useruid=request.user.id) if results!= None: for i in range(len(results)): results[i] = set_time_date(results[i],keyword) mentions = "@" + single_tweet['user']['username']+ " " + "@" + results[i]['user']['username'] results[i]['mentions'] = mentions if results[i]["result_type"] == results[i]["user"]["username"]: tweet_id = results[i]["tweetuid"] replies = search_handle.get_all_children([tweet_id]) if replies == None: continue replies = sorted(replies, key=lambda k: k['time_stamp']) for j in range(len(replies)): replies[j] = set_time_date(replies[j],keyword) replies[j]['mentions'] = mentions + " " + replies[j]['mentions'] results[i]['replies'] = replies single_tweet['user']['profile_img'] = single_tweet['user']['profile_img'].replace("normal","bigger") try: single_tweet['user']['business_org_name'] = str(single_tweet['user']['business_org_name']) except: pass parameters['results'] = results parameters['json_data'] = json.dumps(results) parameters['parent_tweet'] = single_tweet addr = single_tweet['user']['address'].split(',') parameters['tweet_country'] = addr[len(addr)-1].strip() parameters['parent_json'] = json.dumps(single_tweet) parameters['s_userinfo'] = UserInfo(single_tweet['useruid']) return parameters