tag_gallery.py
32 lines
| 1.1 KiB
| text/x-python
|
PythonLexer
|
r1419 | from django.shortcuts import get_object_or_404, render | ||
|
r1986 | from django.urls import reverse | ||
|
r1419 | |||
from boards import settings | ||||
from boards.abstracts.paginator import get_paginator | ||||
|
r1986 | from boards.models import TagAlias | ||
|
r1419 | from boards.views.base import BaseBoardView | ||
from boards.views.mixins import PaginatedMixin | ||||
IMAGES_PER_PAGE = settings.get_int('View', 'ImagesPerPageGallery') | ||||
TEMPLATE = 'boards/tag_gallery.html' | ||||
class TagGalleryView(BaseBoardView, PaginatedMixin): | ||||
def get(self, request, tag_name): | ||||
page = int(request.GET.get('page', 1)) | ||||
params = dict() | ||||
|
r1879 | tag_alias = get_object_or_404(TagAlias, name=tag_name) | ||
tag = tag_alias.parent | ||||
|
r1419 | params['tag'] = tag | ||
paginator = get_paginator(tag.get_images(), IMAGES_PER_PAGE, | ||||
current_page=page) | ||||
params['paginator'] = paginator | ||||
params['images'] = paginator.page(page).object_list | ||||
paginator.set_url(reverse('tag_gallery', kwargs={'tag_name': tag_name}), | ||||
request.GET.dict()) | ||||
|
r1863 | params.update(self.get_page_context(paginator, page)) | ||
|
r1419 | |||
|
r1863 | return render(request, TEMPLATE, params) | ||