You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.7 KiB
51 lines
1.7 KiB
# -*- coding: utf-8 -*-
|
|
from django.shortcuts import get_object_or_404, redirect
|
|
from django.http import HttpResponseForbidden, HttpResponse
|
|
from django.views.decorators.http import require_GET, require_POST
|
|
|
|
from .models import Teaser, update_views_count, update_views_count_many, update_clicks_count
|
|
|
|
|
|
@require_POST
|
|
def show_many(request):
|
|
"""Обновляет статистику просмотров сразу для нескольких тизеров."""
|
|
if not request.is_ajax():
|
|
return HttpResponseForbidden('ajax only')
|
|
|
|
ids = set()
|
|
for _id in request.POST.getlist('ids[]'):
|
|
try:
|
|
ids.add(int(_id))
|
|
except ValueError as e:
|
|
pass
|
|
|
|
if ids:
|
|
update_views_count_many(list(sorted(ids))[:100])
|
|
|
|
return HttpResponse()
|
|
|
|
|
|
@require_POST
|
|
def show(request, teaser_id):
|
|
"""Обновляет статистику просмотров."""
|
|
if not request.is_ajax():
|
|
return HttpResponseForbidden('ajax only')
|
|
|
|
update_views_count(teaser_id)
|
|
|
|
return HttpResponse()
|
|
|
|
|
|
@require_GET
|
|
def click(request, teaser_id):
|
|
"""Теперь просто перманентно (http 301) редиректит на основной url.
|
|
Счётчик кликов не увеличивает.
|
|
Оставлено на случай, если кто-то придёт по старой прокси ссылке.
|
|
|
|
Раньше: Редиректит на url перехода и обновляет статистику переходов.
|
|
"""
|
|
teaser = get_object_or_404(Teaser, pk=teaser_id)
|
|
|
|
#update_clicks_count(teaser_id)
|
|
|
|
return redirect(teaser.get_url(), permanent=True)
|
|
|