arrowcounter/counter/views.py

30 lines
935 B
Python
Raw Normal View History

from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from .models import ArrowCount
from django.contrib.auth.decorators import login_required
from django.conf import settings
from django.core.exceptions import SuspiciousOperation
def index(request):
template = loader.get_template('index.html')
return HttpResponse(template.render({}, request))
@login_required
def arrow_count_list(request):
page = request.GET.get('page')
if not page:
page = 1
else:
page = int(page)
if page <= 0:
raise SuspiciousOperation("page is negative or 0")
start = settings.ITEMS_PER_PAGE * (page - 1)
finish = settings.ITEMS_PER_PAGE + start
counts = ArrowCount.objects.filter(user = request.user)[start:finish]
template = loader.get_template('counter/list.html')
return HttpResponse(template.render({'counts': counts}, request))