def visit(request, landing_hash): redirection = Redirection.all().filter('landing_hash =', landing_hash).get() if redirection: # check if the person has already visited previous_visit = Visit.all().filter( 'ip =', request.META["REMOTE_ADDR"]).filter('redirection =', redirection).get() if previous_visit and ip_checking: # they're going to the place they went last time target = previous_visit.target else: if isinstance(redirection, StratifiedRedirection): # find the last visited URL this_target_index = (redirection.last_target_index + 1) % len( list(redirection.target_set)) target = list( redirection.target_set )[this_target_index] # TODO: is order preserved? also, is there a more efficient way? redirection.last_target_index = this_target_index redirection.put() else: target = random.choice(list(redirection.target_set)) # append any URL parameters to the URL reconstructed_url = combine_queries(str(target.url), request.GET) # record visit visit = Visit(redirection=redirection, target=target, ip=request.META["REMOTE_ADDR"]) visit.put() return HttpResponseRedirect(reconstructed_url)
def visit(request, landing_hash): redirection = Redirection.objects.get(landing_hash=landing_hash) if redirection: # check if the person has already visited previous_visits = Visit.objects.filter(ip=request.META["REMOTE_ADDR"], redirection=redirection) if previous_visits and ip_checking: # they're going to the place they went last time target = previous_visits[0].target else: if redirection.is_stratified: # find the last visited URL this_target_index = (redirection.last_target_index + 1) % redirection.target_set.count() target = redirection.target_set.order_by("date")[this_target_index] # TODO: is order preserved? also, is there a more efficient way? redirection.last_target_index = this_target_index redirection.save() else: target = random.choice(redirection.target_set.all()) # append any URL parameters to the URL reconstructed_url = combine_queries(str(target.url), request.GET) # record visit visit = Visit(redirection = redirection, target = target, ip = request.META["REMOTE_ADDR"]) visit.save() return HttpResponseRedirect(reconstructed_url)
def visit(request, landing_hash): redirection = Redirection.all().filter('landing_hash =', landing_hash).get() if redirection: # check if the person has already visited previous_visit = Visit.all().filter('ip =', request.META["REMOTE_ADDR"]).filter('redirection =', redirection).get() if previous_visit and ip_checking: # they're going to the place they went last time target = previous_visit.target else: if isinstance(redirection, StratifiedRedirection): # find the last visited URL this_target_index = (redirection.last_target_index + 1) % len(list(redirection.target_set)) target = list(redirection.target_set)[this_target_index] # TODO: is order preserved? also, is there a more efficient way? redirection.last_target_index = this_target_index redirection.put() else: target = random.choice(list(redirection.target_set)) # append any URL parameters to the URL reconstructed_url = combine_queries(str(target.url), request.GET) # record visit visit = Visit(redirection = redirection, target = target, ip = request.META["REMOTE_ADDR"]) visit.put() return HttpResponseRedirect(reconstructed_url)
def admin(request, admin_hash): redirection = Redirection.all().filter('admin_hash =', admin_hash).get() if redirection: # targets should be a list of dicts with stats on the different targets. if isinstance(redirection, StratifiedRedirection): method = 'Stratify' else: method = 'Randomize' targets = [] for target in list(redirection.target_set): num_visits = Visit.all().filter('redirection =', redirection).filter('target =', target).count() targets.append({'url': target.url, 'num_visits': num_visits}) return render_to_response('admin.html', {'method': method, 'targets': targets, 'landing_url': make_landing_url(redirection.landing_hash)})
def admin(request, admin_hash): redirection = Redirection.all().filter('admin_hash =', admin_hash).get() if redirection: # targets should be a list of dicts with stats on the different targets. if isinstance(redirection, StratifiedRedirection): method = 'Stratify' else: method = 'Randomize' targets = [] for target in list(redirection.target_set): num_visits = Visit.all().filter('redirection =', redirection).filter( 'target =', target).count() targets.append({'url': target.url, 'num_visits': num_visits}) return render_to_response( 'admin.html', { 'method': method, 'targets': targets, 'landing_url': make_landing_url(redirection.landing_hash) })