~cofob/AlfisViewer

41a5349f9185031a6b7619b41c69f721b0ba312e — cofob 2 years ago 9c196f7
Fixed page redirect
3 files changed, 13 insertions(+), 2 deletions(-)

M alfisviewer/utils.py
M block/views.py
M domain/views.py
M alfisviewer/utils.py => alfisviewer/utils.py +7 -0
@@ 22,3 22,10 @@ def serve_file(file, content_type):
        return serve(request, os.path.basename(file), os.path.dirname(file))

    return serve_file_middle


def get_page(curr, max_val):
    out = curr / max_val
    if curr % max_val == 0 and curr > 0:
        out -= 1
    return out

M block/views.py => block/views.py +3 -1
@@ 6,6 6,7 @@ from .models import Block
from django.shortcuts import render
from django.http.response import Http404, HttpResponseRedirect
import alfis_connector as alfis
import alfisviewer.utils


def block_list(request):


@@ 15,7 16,8 @@ def block_list(request):
        return HttpResponseRedirect(reverse("block_list"))
    if page < 0:
        return HttpResponseRedirect(
            reverse("block_list") + "?p=%s" % str(int(alfis.get_block_count() / 20))
            reverse("block_list")
            + "?p=%s" % str(alfisviewer.utils.get_page(alfis.get_block_count(), 20))
        )
    if page > int(alfis.get_block_count() / 20):
        return HttpResponseRedirect(reverse("block_list") + "?p=%s" % "0")

M domain/views.py => domain/views.py +3 -1
@@ 2,6 2,7 @@ import json
import re
from django.urls import reverse
import alfis_connector
import alfisviewer.utils
from domain.models import Domain
from block.models import Block
from django.http.response import Http404, HttpResponseRedirect


@@ 117,7 118,8 @@ def domain_list(request):
    if page < 0:
        return HttpResponseRedirect(
            reverse("domain_list")
            + "?p=%s" % str(int(alfis_connector.get_domain_count() / 20))
            + "?p=%s"
            % str(alfisviewer.utils.get_page(alfis_connector.get_domain_count(), 20))
        )
    if page > int(alfis_connector.get_domain_count() / 20):
        return HttpResponseRedirect(reverse("domain_list") + "?p=%s" % "0")