コード例 #1
0
ファイル: api.py プロジェクト: rczajka/stratakazika
def sum_counter():
    sum_count = store.get('strata_sum_count')
    sum_money = store.get('strata_sum_money')
    if sum_count is None or int(sum_count) < 10000 or sum_money is None or int(sum_money) < 10000000:
        summed = Counter.objects.all().aggregate(count=Sum('count'), money=Sum('money'))
        store.set('strata_sum_count', summed['count'])
        store.set('strata_sum_money', int(summed['money'] * 100))
        return summed
    return {'count': int(sum_count), 'money': float(sum_money)/100}
コード例 #2
0
ファイル: views.py プロジェクト: rczajka/stratakazika
def increase(request):
    name = request.POST.get('counter_name')
    name = re.sub(ur"\s+", " ", name.strip())

    # Flood control.
    ip = request.META.get('HTTP_X_FORWARDED_FOR') or request.META.get('REMOTE_ADDR')
    key = ('inc', ip, name)
    if store.get(key):
        return HttpResponseForbidden(u'Flood')
    store.set(key, 1)
    store.expire(key, 3)

    if name:
        #tasks.inc_counter_by_name.delay(name)
        api.inc_counter_by_name(name)
    if request.is_ajax():
        return  HttpResponse('') #update(request)
    else:
        return  redirect('/')