예제 #1
0
 def test_advert_pid_one_empty(self):
     distr_percent_advs_list = [('b', 10, [1, 5, 8]),
                                ('a', 70, []),
                                ('c', 20, [9, 10, 11, 12])]
     persistent = {}
     stat = collections.defaultdict(int)
     for i in range(0, 1000):
         aa = advert_choice_pid(distr_percent_advs_list, persistent)
         stat[aa[0]] += 1
     self.assertEquals({'b': 333, 'c': 667}, dict(stat))
예제 #2
0
def advert_select_pid(request):
    """view for lookup adverts"""
    if request.method == 'POST':
        distr_percent_advs_list = make_dist_adv_list()
        aa = advert_choice_pid(distr_percent_advs_list, persistent)
        a = Advertisement.objects.get(id=aa[1])
        Distributor.objects.filter(pk=aa[0]).update(shown_adverts=F('shown_adverts')+1)
        response = JsonResponse({'banner': a.banner.url,
                                 'banner_link': a.banner_link})
    else:
        return HttpResponseNotFound('<h1>use Post instead of GET method</h1>')
    return response
예제 #3
0
def advert_select_pid(request):
    """view for lookup adverts"""
    if request.method == 'POST':
        distr_percent_advs_list = make_dist_adv_list()
        aa = advert_choice_pid(distr_percent_advs_list, persistent)
        a = Advertisement.objects.get(id=aa[1])
        Distributor.objects.filter(pk=aa[0]).update(
            shown_adverts=F('shown_adverts') + 1)
        response = JsonResponse({
            'banner': a.banner.url,
            'banner_link': a.banner_link
        })
    else:
        return HttpResponseNotFound('<h1>use Post instead of GET method</h1>')
    return response