# HG changeset patch # User neko259 # Date 2017-12-11 19:30:56 # Node ID d0cc47569a5d392701b3a0bb3222546cbfc186bb # Parent 3c9f075c0b687cb397ffb7cc0d1726f50b83b2c3 Continue to extract section strings diff --git a/boards/context_processors.py b/boards/context_processors.py --- a/boards/context_processors.py +++ b/boards/context_processors.py @@ -4,6 +4,7 @@ from boards.models import Banner from boards.models.user import Notification from boards import settings from boards.models import Post, Tag, Thread +from boards.settings import SECTION_FORMS CONTEXT_SITE_NAME = 'site_name' CONTEXT_VERSION = 'version' @@ -66,7 +67,7 @@ def user_and_ui_processor(request): if (settings.get_bool('Forms', 'LimitFirstPosting') and not settings_manager.get_setting('confirmed_user'))\ or settings.get_bool('Forms', 'LimitPostingSpeed'): - context[CONTEXT_POW_DIFFICULTY] = settings.get_int('Forms', 'PowDifficulty') + context[CONTEXT_POW_DIFFICULTY] = settings.get_int(SECTION_FORMS, 'PowDifficulty') context[CONTEXT_IMAGE_VIEWER] = settings_manager.get_setting( SETTING_IMAGE_VIEWER, diff --git a/boards/models/thread.py b/boards/models/thread.py --- a/boards/models/thread.py +++ b/boards/models/thread.py @@ -10,7 +10,8 @@ from boards import settings from boards.models import STATUS_BUMPLIMIT, STATUS_ACTIVE, STATUS_ARCHIVE from boards.models.attachment import FILE_TYPES_IMAGE from boards.models.post import Post -from boards.models.tag import Tag, DEFAULT_LOCALE, TagAlias +from boards.models.tag import Tag, TagAlias +from boards.settings import SECTION_VIEW from boards.utils import cached_result, datetime_to_epoch FAV_THREAD_NO_UPDATES = -1 @@ -157,7 +158,7 @@ class Thread(models.Model): Gets several last replies, not including opening post """ - last_replies_count = settings.get_int('View', 'LastRepliesCount') + last_replies_count = settings.get_int(SECTION_VIEW, 'LastRepliesCount') if last_replies_count > 0: reply_count = self.get_reply_count() @@ -175,7 +176,7 @@ class Thread(models.Model): Gets number of posts between opening post and last replies. """ reply_count = self.get_reply_count() - last_replies_count = min(settings.get_int('View', 'LastRepliesCount'), + last_replies_count = min(settings.get_int(SECTION_VIEW, 'LastRepliesCount'), reply_count - 1) return reply_count - last_replies_count - 1 diff --git a/boards/tests/test_post.py b/boards/tests/test_post.py --- a/boards/tests/test_post.py +++ b/boards/tests/test_post.py @@ -4,6 +4,7 @@ from django.test import TestCase from boards import settings from boards.models import Tag, Post, Thread, KeyPair from boards.models.thread import STATUS_ARCHIVE +from boards.settings import SECTION_VIEW class PostTests(TestCase): @@ -93,17 +94,18 @@ class PostTests(TestCase): def test_pages(self): """Test that the thread list is properly split into pages""" - for i in range(settings.get_int('View', 'ThreadsPerPage') * 2): + threads_per_page = settings.get_int(SECTION_VIEW, 'ThreadsPerPage') + for i in range(threads_per_page * 2): self._create_post() all_threads = Thread.objects.exclude(status=STATUS_ARCHIVE) paginator = Paginator(Thread.objects.exclude(status=STATUS_ARCHIVE), - settings.get_int('View', 'ThreadsPerPage')) + threads_per_page) posts_in_second_page = paginator.page(2).object_list first_post = posts_in_second_page[0] - self.assertEqual(all_threads[settings.get_int('View', 'ThreadsPerPage')].id, + self.assertEqual(all_threads[threads_per_page].id, first_post.id) def test_reflinks(self): diff --git a/boards/views/feed.py b/boards/views/feed.py --- a/boards/views/feed.py +++ b/boards/views/feed.py @@ -5,10 +5,11 @@ from boards import settings from boards.abstracts.paginator import get_paginator from boards.abstracts.settingsmanager import get_settings_manager from boards.models import Post +from boards.settings import SECTION_VIEW from boards.views.base import BaseBoardView from boards.views.mixins import PaginatedMixin -POSTS_PER_PAGE = settings.get_int('View', 'PostsPerPage') +POSTS_PER_PAGE = settings.get_int(SECTION_VIEW, 'PostsPerPage') PARAMETER_POSTS = 'posts' PARAMETER_QUERIES = 'queries' diff --git a/boards/views/landing.py b/boards/views/landing.py --- a/boards/views/landing.py +++ b/boards/views/landing.py @@ -7,8 +7,8 @@ from django.utils.decorators import meth from django.views.decorators.csrf import csrf_protect from boards import settings -from boards.models import Post, Tag, Attachment, STATUS_ACTIVE, TagAlias -from boards.models.tag import DEFAULT_LOCALE +from boards.models import Post, Tag, STATUS_ACTIVE, TagAlias +from boards.settings import SECTION_VIEW from boards.views.base import BaseBoardView PARAM_SECTION_STR = 'section_str' @@ -31,7 +31,7 @@ class LandingView(BaseBoardView): .annotate(today_post_count=Count('thread__replies'))\ .order_by('-pub_time') - max_landing_threads = settings.get_int('View', 'MaxLandingThreads') + max_landing_threads = settings.get_int(SECTION_VIEW, 'MaxLandingThreads') if max_landing_threads > 0: ops = ops[:max_landing_threads] diff --git a/boards/views/tag_gallery.py b/boards/views/tag_gallery.py --- a/boards/views/tag_gallery.py +++ b/boards/views/tag_gallery.py @@ -4,10 +4,11 @@ from django.urls import reverse from boards import settings from boards.abstracts.paginator import get_paginator from boards.models import TagAlias +from boards.settings import SECTION_VIEW from boards.views.base import BaseBoardView from boards.views.mixins import PaginatedMixin -IMAGES_PER_PAGE = settings.get_int('View', 'ImagesPerPageGallery') +IMAGES_PER_PAGE = settings.get_int(SECTION_VIEW, 'ImagesPerPageGallery') TEMPLATE = 'boards/tag_gallery.html' diff --git a/boards/views/thread/normal.py b/boards/views/thread/normal.py --- a/boards/views/thread/normal.py +++ b/boards/views/thread/normal.py @@ -1,4 +1,5 @@ from boards import settings +from boards.settings import SECTION_FORMS from boards.views.thread import ThreadView from boards.views.mixins import FileUploadMixin @@ -31,6 +32,6 @@ class NormalThreadView(ThreadView, FileU params[CONTEXT_BUMPLIMIT_PRG] = str( float(left_posts) / max_posts * 100) params[PARAM_MAX_FILE_SIZE] = self.get_max_upload_size() - params[PARAM_MAX_FILES] = settings.get_int('Forms', 'MaxFileCount') + params[PARAM_MAX_FILES] = settings.get_int(SECTION_FORMS, 'MaxFileCount') return params