##// END OF EJS Templates
Moved imageboard settings to the boards settings module. Added setting to disable archive
neko259 -
r716:a6b9dd95 1.8.1 default
parent child Browse files
Show More
@@ -0,0 +1,1 b''
1 import settings No newline at end of file
@@ -1,7 +1,6 b''
1 from boards import utils
1 from boards import utils, settings
2 from boards.models import Post
2 from boards.models import Post
3 from boards.models.post import SETTING_MODERATE
3 from boards.models.post import SETTING_MODERATE
4 import neboard
5
4
6 __author__ = 'neko259'
5 __author__ = 'neko259'
7
6
@@ -25,7 +24,7 b' def user_and_ui_processor(request):'
25 else:
24 else:
26 context['moderator'] = False
25 context['moderator'] = False
27
26
28 context['version'] = neboard.settings.VERSION
27 context['version'] = settings.VERSION
29 context['site_name'] = neboard.settings.SITE_NAME
28 context['site_name'] = settings.SITE_NAME
30
29
31 return context No newline at end of file
30 return context
@@ -9,7 +9,7 b' from django.utils.translation import uge'
9
9
10 from boards.mdx_neboard import formatters
10 from boards.mdx_neboard import formatters
11 from boards.models.post import TITLE_MAX_LENGTH
11 from boards.models.post import TITLE_MAX_LENGTH
12 from boards.models import User, Post, PostImage
12 from boards.models import User, PostImage
13 from neboard import settings
13 from neboard import settings
14 from boards import utils
14 from boards import utils
15 import boards.settings as board_settings
15 import boards.settings as board_settings
@@ -96,7 +96,7 b' class PostManager(models.Manager):'
96 map(thread.add_tag, tags)
96 map(thread.add_tag, tags)
97
97
98 if new_thread:
98 if new_thread:
99 Thread.objects.archive_oldest_threads()
99 Thread.objects.process_oldest_threads()
100 self.connect_replies(post)
100 self.connect_replies(post)
101
101
102 logger.info('Created post #%d' % post.id)
102 logger.info('Created post #%d' % post.id)
@@ -3,7 +3,7 b' from django.db.models import Count'
3 from django.utils import timezone
3 from django.utils import timezone
4 from django.core.cache import cache
4 from django.core.cache import cache
5 from django.db import models
5 from django.db import models
6 from neboard import settings
6 from boards import settings
7
7
8 __author__ = 'neko259'
8 __author__ = 'neko259'
9
9
@@ -15,10 +15,10 b" CACHE_KEY_OPENING_POST = 'opening_post_i"
15
15
16
16
17 class ThreadManager(models.Manager):
17 class ThreadManager(models.Manager):
18 def archive_oldest_threads(self):
18 def process_oldest_threads(self):
19 """
19 """
20 Preserves maximum thread count. If there are too many threads,
20 Preserves maximum thread count. If there are too many threads,
21 archive the old ones.
21 archive or delete the old ones.
22 """
22 """
23
23
24 threads = Thread.objects.filter(archived=False).order_by('-bump_time')
24 threads = Thread.objects.filter(archived=False).order_by('-bump_time')
@@ -29,11 +29,20 b' class ThreadManager(models.Manager):'
29 old_threads = threads[thread_count - num_threads_to_delete:]
29 old_threads = threads[thread_count - num_threads_to_delete:]
30
30
31 for thread in old_threads:
31 for thread in old_threads:
32 thread.archived = True
32 if settings.ARCHIVE_THREADS:
33 thread.last_edit_time = timezone.now()
33 self._archive_thread(thread)
34 thread.save(update_fields=['archived', 'last_edit_time'])
34 else:
35 self._delete_thread(thread)
36
37 logger.info('Processed %d old threads' % num_threads_to_delete)
35
38
36 logger.info('Archived %d old threads' % num_threads_to_delete)
39 def _archive_thread(self, thread):
40 thread.archived = True
41 thread.last_edit_time = timezone.now()
42 thread.save(update_fields=['archived', 'last_edit_time'])
43
44 def _delete_thread(self, thread):
45 thread.delete_with_posts()
37
46
38
47
39 class Thread(models.Model):
48 class Thread(models.Model):
@@ -89,6 +98,7 b' class Thread(models.Model):'
89
98
90 return post_count < settings.MAX_POSTS_PER_THREAD
99 return post_count < settings.MAX_POSTS_PER_THREAD
91
100
101 # TODO Do it in the 'delete' method
92 def delete_with_posts(self):
102 def delete_with_posts(self):
93 """
103 """
94 Completely deletes thread and all its posts
104 Completely deletes thread and all its posts
@@ -2,7 +2,7 b' from django.contrib.syndication.views im'
2 from django.core.urlresolvers import reverse
2 from django.core.urlresolvers import reverse
3 from django.shortcuts import get_object_or_404
3 from django.shortcuts import get_object_or_404
4 from boards.models import Post, Tag, Thread
4 from boards.models import Post, Tag, Thread
5 from neboard import settings
5 from boards import settings
6
6
7 __author__ = 'neko259'
7 __author__ = 'neko259'
8
8
@@ -1,4 +1,18 b''
1 VERSION = '1.8.1 Kara'
2 SITE_NAME = 'Neboard'
3
1 CACHE_TIMEOUT = 600 # Timeout for caching, if cache is used
4 CACHE_TIMEOUT = 600 # Timeout for caching, if cache is used
2 LOGIN_TIMEOUT = 3600 # Timeout between login tries
5 LOGIN_TIMEOUT = 3600 # Timeout between login tries
3 MAX_TEXT_LENGTH = 30000 # Max post length in characters
6 MAX_TEXT_LENGTH = 30000 # Max post length in characters
4 MAX_IMAGE_SIZE = 8 * 1024 * 1024 # Max image size
7 MAX_IMAGE_SIZE = 8 * 1024 * 1024 # Max image size
8
9 # Thread bumplimit
10 MAX_POSTS_PER_THREAD = 10
11 # Old posts will be archived or deleted if this value is reached
12 MAX_THREAD_COUNT = 5
13 THREADS_PER_PAGE = 3
14 DEFAULT_THEME = 'md'
15 LAST_REPLIES_COUNT = 3
16
17 # Enable archiving threads instead of deletion when the thread limit is reached
18 ARCHIVE_THREADS = True No newline at end of file
@@ -9,7 +9,8 b' from django.core.urlresolvers import rev'
9
9
10 from boards.models import Post, Tag, Thread
10 from boards.models import Post, Tag, Thread
11 from boards import urls
11 from boards import urls
12 from neboard import settings
12 from boards import settings
13 import neboard
13
14
14 PAGE_404 = 'boards/404.html'
15 PAGE_404 = 'boards/404.html'
15
16
@@ -187,8 +188,8 b' class PagesTest(TestCase):'
187 class FormTest(TestCase):
188 class FormTest(TestCase):
188 def test_post_validation(self):
189 def test_post_validation(self):
189 # Disable captcha for the test
190 # Disable captcha for the test
190 captcha_enabled = settings.ENABLE_CAPTCHA
191 captcha_enabled = neboard.settings.ENABLE_CAPTCHA
191 settings.ENABLE_CAPTCHA = False
192 neboard.settings.ENABLE_CAPTCHA = False
192
193
193 client = Client()
194 client = Client()
194
195
@@ -211,10 +212,10 b' class FormTest(TestCase):'
211 'where it should fail')
212 'where it should fail')
212
213
213 # Change posting delay so we don't have to wait for 30 seconds or more
214 # Change posting delay so we don't have to wait for 30 seconds or more
214 old_posting_delay = settings.POSTING_DELAY
215 old_posting_delay = neboard.settings.POSTING_DELAY
215 # Wait fot the posting delay or we won't be able to post
216 # Wait fot the posting delay or we won't be able to post
216 settings.POSTING_DELAY = 1
217 settings.POSTING_DELAY = 1
217 time.sleep(settings.POSTING_DELAY + 1)
218 time.sleep(neboard.settings.POSTING_DELAY + 1)
218 response = client.post(THREAD_PAGE_ONE, {'text': TEST_TEXT,
219 response = client.post(THREAD_PAGE_ONE, {'text': TEST_TEXT,
219 'tags': valid_tags})
220 'tags': valid_tags})
220 self.assertEqual(HTTP_CODE_REDIRECT, response.status_code,
221 self.assertEqual(HTTP_CODE_REDIRECT, response.status_code,
@@ -2,14 +2,14 b''
2 This module contains helper functions and helper classes.
2 This module contains helper functions and helper classes.
3 """
3 """
4 import hashlib
4 import hashlib
5 import time
6
5 from django.utils import timezone
7 from django.utils import timezone
8 import boards
6
9
7 from neboard import settings
10 from neboard import settings
8 from boards.models import Post, User
11 from boards.models import User
9 from boards.models.post import SETTING_MODERATE
10 from boards.models.user import RANK_USER
12 from boards.models.user import RANK_USER
11 import time
12 import neboard
13
13
14
14
15 KEY_CAPTCHA_FAILS = 'key_captcha_fails'
15 KEY_CAPTCHA_FAILS = 'key_captcha_fails'
@@ -124,6 +124,6 b' def get_theme(request, user=None):'
124 user = get_user(request)
124 user = get_user(request)
125 theme = user.get_setting('theme')
125 theme = user.get_setting('theme')
126 if not theme:
126 if not theme:
127 theme = neboard.settings.DEFAULT_THEME
127 theme = boards.settings.DEFAULT_THEME
128
128
129 return theme No newline at end of file
129 return theme
@@ -3,7 +3,7 b' import string'
3 from django.db import transaction
3 from django.db import transaction
4 from django.shortcuts import render, redirect
4 from django.shortcuts import render, redirect
5
5
6 from boards import utils
6 from boards import utils, settings
7 from boards.abstracts.paginator import get_paginator
7 from boards.abstracts.paginator import get_paginator
8 from boards.forms import ThreadForm, PlainErrorList
8 from boards.forms import ThreadForm, PlainErrorList
9 from boards.models import Post, Thread, Ban, Tag
9 from boards.models import Post, Thread, Ban, Tag
@@ -35,7 +35,7 b' class AllThreadsView(PostMixin, BaseBoar'
35 form = ThreadForm(error_class=PlainErrorList)
35 form = ThreadForm(error_class=PlainErrorList)
36
36
37 paginator = get_paginator(self.get_threads(),
37 paginator = get_paginator(self.get_threads(),
38 neboard.settings.THREADS_PER_PAGE)
38 settings.THREADS_PER_PAGE)
39 paginator.current_page = int(page)
39 paginator.current_page = int(page)
40
40
41 threads = paginator.page(page).object_list
41 threads = paginator.page(page).object_list
@@ -4,13 +4,12 b' from django.http import Http404'
4 from django.shortcuts import get_object_or_404, render, redirect
4 from django.shortcuts import get_object_or_404, render, redirect
5 from django.views.generic.edit import FormMixin
5 from django.views.generic.edit import FormMixin
6
6
7 from boards import utils
7 from boards import utils, settings
8 from boards.forms import PostForm, PlainErrorList
8 from boards.forms import PostForm, PlainErrorList
9 from boards.models import Post, Ban
9 from boards.models import Post, Ban
10 from boards.views.banned import BannedView
10 from boards.views.banned import BannedView
11 from boards.views.base import BaseBoardView, PARAMETER_FORM
11 from boards.views.base import BaseBoardView, PARAMETER_FORM
12 from boards.views.posting_mixin import PostMixin
12 from boards.views.posting_mixin import PostMixin
13 import neboard
14
13
15
14
16 MODE_GALLERY = 'gallery'
15 MODE_GALLERY = 'gallery'
@@ -44,16 +43,16 b' class ThreadView(BaseBoardView, PostMixi'
44 context["last_update"] = utils.datetime_to_epoch(
43 context["last_update"] = utils.datetime_to_epoch(
45 thread_to_show.last_edit_time)
44 thread_to_show.last_edit_time)
46 context[PARAMETER_THREAD] = thread_to_show
45 context[PARAMETER_THREAD] = thread_to_show
47 context[PARAMETER_MAX_REPLIES] = neboard.settings.MAX_POSTS_PER_THREAD
46 context[PARAMETER_MAX_REPLIES] = settings.MAX_POSTS_PER_THREAD
48
47
49 if MODE_NORMAL == mode:
48 if MODE_NORMAL == mode:
50 context[PARAMETER_BUMPABLE] = thread_to_show.can_bump()
49 context[PARAMETER_BUMPABLE] = thread_to_show.can_bump()
51 if context[PARAMETER_BUMPABLE]:
50 if context[PARAMETER_BUMPABLE]:
52 context['posts_left'] = neboard.settings.MAX_POSTS_PER_THREAD \
51 context['posts_left'] = settings.MAX_POSTS_PER_THREAD \
53 - thread_to_show.get_reply_count()
52 - thread_to_show.get_reply_count()
54 context['bumplimit_progress'] = str(
53 context['bumplimit_progress'] = str(
55 float(context['posts_left']) /
54 float(context['posts_left']) /
56 neboard.settings.MAX_POSTS_PER_THREAD * 100)
55 settings.MAX_POSTS_PER_THREAD * 100)
57
56
58 context['opening_post'] = opening_post
57 context['opening_post'] = opening_post
59
58
@@ -0,0 +1,1 b''
1 import settings No newline at end of file
@@ -221,12 +221,6 b" HAYSTACK_SIGNAL_PROCESSOR = 'haystack.si"
221 MARKUP_FIELD_TYPES = (
221 MARKUP_FIELD_TYPES = (
222 ('markdown', markdown_extended),
222 ('markdown', markdown_extended),
223 )
223 )
224 # Custom imageboard settings
225 # TODO These should me moved to
226 MAX_POSTS_PER_THREAD = 10 # Thread bumplimit
227 MAX_THREAD_COUNT = 5 # Old threads will be deleted to preserve this count
228 THREADS_PER_PAGE = 3
229 SITE_NAME = 'Neboard'
230
224
231 THEMES = [
225 THEMES = [
232 ('md', 'Mystic Dark'),
226 ('md', 'Mystic Dark'),
@@ -235,10 +229,7 b' THEMES = ['
235 ('pg', 'Photon Gray'),
229 ('pg', 'Photon Gray'),
236 ]
230 ]
237
231
238 DEFAULT_THEME = 'md'
239
240 POPULAR_TAGS = 10
232 POPULAR_TAGS = 10
241 LAST_REPLIES_COUNT = 3
242
233
243 ENABLE_CAPTCHA = False
234 ENABLE_CAPTCHA = False
244 # if user tries to post before CAPTCHA_DEFAULT_SAFE_TIME. Captcha will be shown
235 # if user tries to post before CAPTCHA_DEFAULT_SAFE_TIME. Captcha will be shown
@@ -247,13 +238,8 b' POSTING_DELAY = 20 # seconds'
247
238
248 COMPRESS_HTML = True
239 COMPRESS_HTML = True
249
240
250 VERSION = '1.8.0 Kara'
251
252 # Debug mode middlewares
241 # Debug mode middlewares
253 if DEBUG:
242 if DEBUG:
254
255 SITE_NAME += ' DEBUG'
256
257 MIDDLEWARE_CLASSES += (
243 MIDDLEWARE_CLASSES += (
258 'boards.profiler.ProfilerMiddleware',
244 'boards.profiler.ProfilerMiddleware',
259 'debug_toolbar.middleware.DebugToolbarMiddleware',
245 'debug_toolbar.middleware.DebugToolbarMiddleware',
General Comments 0
You need to be logged in to leave comments. Login now