diff --git a/boards/abstracts/paginator.py b/boards/abstracts/paginator.py --- a/boards/abstracts/paginator.py +++ b/boards/abstracts/paginator.py @@ -12,7 +12,14 @@ def get_paginator(*args, **kwargs): class DividedPaginator(Paginator): lookaround_size = PAGINATOR_LOOKAROUND_SIZE - current_page = 0 + + def __init__(self, object_list, per_page, orphans=0, + allow_empty_first_page=True, current_page=1): + super().__init__(object_list, per_page, orphans, allow_empty_first_page) + + self.link = None + self.params = None + self.current_page = current_page def _left_range(self): return self.page_range[:self.lookaround_size] @@ -67,8 +74,18 @@ class DividedPaginator(Paginator): def get_page_url(self, page): self.params['page'] = page url_params = '?' + '&'.join(['{}={}'.format(key, self.params[key]) - for key in self.params.keys()]) + for key in self.params.keys()]) return self.link + url_params def supports_urls(self): return self.link is not None and self.params is not None + + def get_next_page_url(self): + current = self.page(self.current_page) + if current.has_next(): + return self.get_page_url(current.next_page_number()) + + def get_prev_page_url(self): + current = self.page(self.current_page) + if current.has_previous(): + return self.get_page_url(current.previous_page_number()) \ No newline at end of file diff --git a/boards/config/default_settings.ini b/boards/config/default_settings.ini --- a/boards/config/default_settings.ini +++ b/boards/config/default_settings.ini @@ -24,6 +24,7 @@ DefaultTheme = md DefaultImageViewer = simple LastRepliesCount = 3 ThreadsPerPage = 3 +ImagesPerPageGallery = 20 [Storage] # Enable archiving threads instead of deletion when the thread limit is reached diff --git a/boards/models/tag.py b/boards/models/tag.py --- a/boards/models/tag.py +++ b/boards/models/tag.py @@ -4,6 +4,7 @@ from django.db import models from django.db.models import Count from django.core.urlresolvers import reverse +from boards.models import PostImage from boards.models.base import Viewable from boards.models.thread import STATUS_ACTIVE, STATUS_BUMPLIMIT, STATUS_ARCHIVE from boards.utils import cached_result @@ -140,3 +141,7 @@ class Tag(models.Model, Viewable): def get_children(self): return self.children + + def get_images(self): + return PostImage.objects.filter(post_images__thread__tags__in=[self])\ + .order_by('-post_images__pub_time') \ No newline at end of file diff --git a/boards/templates/boards/all_threads.html b/boards/templates/boards/all_threads.html --- a/boards/templates/boards/all_threads.html +++ b/boards/templates/boards/all_threads.html @@ -71,6 +71,7 @@ {% endif %} + {% trans 'Gallery' %}

{% if tag.get_description %}

{{ tag.get_description|safe }}

diff --git a/boards/templates/boards/all_threads.html b/boards/templates/boards/tag_gallery.html copy from boards/templates/boards/all_threads.html copy to boards/templates/boards/tag_gallery.html --- a/boards/templates/boards/all_threads.html +++ b/boards/templates/boards/tag_gallery.html @@ -8,11 +8,7 @@ {% block head %} - {% if tag %} - {{ tag.name }} - {{ site_name }} - {% else %} - {{ site_name }} - {% endif %} + {{ tag.name }} - {% trans 'Gallery' %} - {{ site_name }} {% if prev_page_link %} @@ -36,7 +32,6 @@ {% endfor %} -{% if tag %}
{% if random_image_post %}
@@ -56,22 +51,6 @@ | {% trans 'Edit tag' %} {% endif %} -

-

- {% if is_favorite %} - - {% else %} - - {% endif %} -
-
- {% if is_hidden %} - - {% else %} - - {% endif %} -
-

{% if tag.get_description %}

{{ tag.get_description|safe }}

{% endif %} @@ -99,79 +78,29 @@ {% endif %}
-{% endif %} - {% if threads %} - {% if prev_page_link %} - - {% endif %} - - {% for thread in threads %} -
- {% post_view thread.get_opening_post thread=thread truncated=True need_open_link=True %} - {% if not thread.archived %} - {% with last_replies=thread.get_last_replies %} - {% if last_replies %} - {% with skipped_replies_count=thread.get_skipped_replies_count %} - {% if skipped_replies_count %} -
- - {% blocktrans count count=skipped_replies_count %}Skipped {{ count }} reply. Open thread to see all replies.{% plural %}Skipped {{ count }} replies. Open thread to see all replies.{% endblocktrans %} - -
- {% endif %} - {% endwith %} -
- {% for post in last_replies %} - {% post_view post truncated=True %} - {% endfor %} -
- {% endif %} - {% endwith %} - {% endif %} -
- {% endfor %} - - {% if next_page_link %} - - {% endif %} - {% else %} -
- {% trans 'No threads exist. Create the first one!' %}
+ {% if prev_page_link %} + {% endif %} -
- -
-
{% trans "Create new thread" %}
-
-
{% csrf_token %} - {{ form.as_div }} -
- - -
-
+ {% for image in images %} + -
+ {% endfor %} - - - + {% if next_page_link %} + + {% endif %} {% endblock %} {% block metapanel %} @@ -186,7 +115,7 @@ …, {% endif %} {{ page }} diff --git a/boards/urls.py b/boards/urls.py --- a/boards/urls.py +++ b/boards/urls.py @@ -11,6 +11,7 @@ from boards.views.search import BoardSea from boards.views.static import StaticPageView from boards.views.preview import PostPreviewView from boards.views.random import RandomImageView +from boards.views.tag_gallery import TagGalleryView from boards.views.translation import cached_javascript_catalog @@ -45,6 +46,7 @@ urlpatterns = patterns('', name='staticpage'), url(r'^random/$', RandomImageView.as_view(), name='random'), + url(r'^tag/(?P\w+)/gallery/$', TagGalleryView.as_view(), name='tag_gallery'), # RSS feeds url(r'^rss/$', AllThreadsFeed()), diff --git a/boards/views/all_threads.py b/boards/views/all_threads.py --- a/boards/views/all_threads.py +++ b/boards/views/all_threads.py @@ -15,8 +15,7 @@ from boards.models import Post, Thread, from boards.views.banned import BannedView from boards.views.base import BaseBoardView, CONTEXT_FORM from boards.views.posting_mixin import PostMixin -from boards.views.mixins import FileUploadMixin - +from boards.views.mixins import FileUploadMixin, PaginatedMixin FORM_TAGS = 'tags' FORM_TEXT = 'text' @@ -34,14 +33,11 @@ PARAMETER_ADDITIONAL = 'additional_param PARAMETER_MAX_FILE_SIZE = 'max_file_size' PARAMETER_RSS_URL = 'rss_url' -PARAMETER_PREV_LINK = 'prev_page_link' -PARAMETER_NEXT_LINK = 'next_page_link' - TEMPLATE = 'boards/all_threads.html' DEFAULT_PAGE = 1 -class AllThreadsView(PostMixin, FileUploadMixin, BaseBoardView): +class AllThreadsView(PostMixin, FileUploadMixin, BaseBoardView, PaginatedMixin): def __init__(self): self.settings_manager = None @@ -106,12 +102,7 @@ class AllThreadsView(PostMixin, FileUplo params[PARAMETER_PAGINATOR] = paginator current_page = paginator.page(int(page)) params[PARAMETER_CURRENT_PAGE] = current_page - if current_page.has_previous(): - params[PARAMETER_PREV_LINK] = paginator.get_page_url( - current_page.previous_page_number()) - if current_page.has_next(): - params[PARAMETER_NEXT_LINK] = paginator.get_page_url( - current_page.next_page_number()) + self.set_page_urls(paginator, params) def get_reverse_url(self): return reverse('index') diff --git a/boards/views/mixins.py b/boards/views/mixins.py --- a/boards/views/mixins.py +++ b/boards/views/mixins.py @@ -32,3 +32,9 @@ class DispatcherMixin: class FileUploadMixin: def get_max_upload_size(self): return boards.settings.get_int('Forms', 'MaxFileSize') + + +class PaginatedMixin: + def set_page_urls(self, paginator, params): + params['prev_page_link'] = paginator.get_prev_page_url() + params['next_page_link'] = paginator.get_next_page_url() diff --git a/boards/views/tag_gallery.py b/boards/views/tag_gallery.py new file mode 100644 --- /dev/null +++ b/boards/views/tag_gallery.py @@ -0,0 +1,31 @@ +from django.core.urlresolvers import reverse +from django.shortcuts import get_object_or_404, render + +from boards import settings +from boards.abstracts.paginator import get_paginator +from boards.models import Tag +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 = get_object_or_404(Tag, name=tag_name) + 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()) + self.set_page_urls(paginator, params) + + return render(request, TEMPLATE, params) \ No newline at end of file