|
|
from django.shortcuts import get_object_or_404, render
|
|
|
from django.urls import reverse
|
|
|
|
|
|
from boards import settings
|
|
|
from boards.abstracts.paginator import get_paginator
|
|
|
from boards.models import TagAlias
|
|
|
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()
|
|
|
tag_alias = get_object_or_404(TagAlias, name=tag_name)
|
|
|
tag = tag_alias.parent
|
|
|
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())
|
|
|
params.update(self.get_page_context(paginator, page))
|
|
|
|
|
|
return render(request, TEMPLATE, params)
|
|
|
|