diff --git a/boards/admin.py b/boards/admin.py --- a/boards/admin.py +++ b/boards/admin.py @@ -1,11 +1,11 @@ -from boards.abstracts.sticker_factory import StickerFactory +from django.contrib import admin +from django.urls import reverse +from django.utils.translation import ugettext_lazy as _ + +from boards.models import Post, Tag, Ban, Thread, Banner, Attachment, \ + KeyPair, GlobalId, TagAlias, STATUS_ACTIVE from boards.models.attachment import FILE_TYPES_IMAGE, AttachmentSticker, \ StickerPack -from django.contrib import admin -from django.utils.translation import ugettext_lazy as _ -from django.core.urlresolvers import reverse -from boards.models import Post, Tag, Ban, Thread, Banner, Attachment, \ - KeyPair, GlobalId, TagAlias, STATUS_ACTIVE from boards.models.source import ThreadSource diff --git a/boards/mdx_neboard.py b/boards/mdx_neboard.py --- a/boards/mdx_neboard.py +++ b/boards/mdx_neboard.py @@ -1,4 +1,5 @@ # coding=utf-8 +from xml import etree import re import random @@ -7,7 +8,7 @@ import bbcode from urllib.parse import unquote from django.core.exceptions import ObjectDoesNotExist -from django.core.urlresolvers import reverse +from django.urls import reverse import boards from boards import settings diff --git a/boards/middlewares.py b/boards/middlewares.py --- a/boards/middlewares.py +++ b/boards/middlewares.py @@ -19,10 +19,11 @@ class BanMiddleware: anything """ - def __init__(self): - pass + def __init__(self, get_response): + self.get_response = get_response - def process_view(self, request, view_func, view_args, view_kwargs): + def __call__(self, request): + response = self.get_response(request) if request.path != '/banned/': ip = utils.get_client_ip(request) @@ -33,12 +34,21 @@ class BanMiddleware: if not ban.can_read: return redirect('banned') + return response + class TimezoneMiddleware(object): - def process_request(self, request): + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + response = self.get_response(request) + tzname = request.session.get(SESSION_TIMEZONE) if tzname: timezone.activate(pytz.timezone(tzname)) else: timezone.deactivate() + return response + diff --git a/boards/migrations/0001_initial.py b/boards/migrations/0001_initial.py --- a/boards/migrations/0001_initial.py +++ b/boards/migrations/0001_initial.py @@ -106,7 +106,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='post', name='thread_new', - field=models.ForeignKey(null=True, default=None, to='boards.Thread'), + field=models.ForeignKey(on_delete=models.CASCADE, null=True, default=None, to='boards.Thread'), preserve_default=True, ), ] diff --git a/boards/migrations/0009_post_thread.py b/boards/migrations/0009_post_thread.py --- a/boards/migrations/0009_post_thread.py +++ b/boards/migrations/0009_post_thread.py @@ -21,7 +21,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='post', name='thread', - field=models.ForeignKey(related_name='pt+', to='boards.Thread', default=None, null=True), + field=models.ForeignKey(on_delete=models.CASCADE, related_name='pt+', to='boards.Thread', default=None, null=True), preserve_default=False, ), migrations.RunPython(first_thread_to_thread), diff --git a/boards/migrations/0010_auto_20150208_1451.py b/boards/migrations/0010_auto_20150208_1451.py --- a/boards/migrations/0010_auto_20150208_1451.py +++ b/boards/migrations/0010_auto_20150208_1451.py @@ -25,7 +25,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='post', name='thread', - field=models.ForeignKey(to='boards.Thread', related_name='pt+'), + field=models.ForeignKey(on_delete=models.CASCADE, to='boards.Thread', related_name='pt+'), preserve_default=True, ), migrations.RunPython(clean_duplicate_tags), diff --git a/boards/migrations/0011_notification.py b/boards/migrations/0011_notification.py --- a/boards/migrations/0011_notification.py +++ b/boards/migrations/0011_notification.py @@ -16,7 +16,7 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(serialize=False, verbose_name='ID', auto_created=True, primary_key=True)), ('name', models.TextField()), - ('post', models.ForeignKey(to='boards.Post')), + ('post', models.ForeignKey(on_delete=models.CASCADE, to='boards.Post')), ], options={ }, diff --git a/boards/migrations/0014_auto_20150418_1749.py b/boards/migrations/0014_auto_20150418_1749.py --- a/boards/migrations/0014_auto_20150418_1749.py +++ b/boards/migrations/0014_auto_20150418_1749.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.core.urlresolvers import reverse +from django.urls import reverse from django.db import models, migrations diff --git a/boards/migrations/0018_banner.py b/boards/migrations/0018_banner.py --- a/boards/migrations/0018_banner.py +++ b/boards/migrations/0018_banner.py @@ -17,7 +17,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(serialize=False, primary_key=True, verbose_name='ID', auto_created=True)), ('title', models.TextField()), ('text', models.TextField()), - ('post', models.ForeignKey(to='boards.Post')), + ('post', models.ForeignKey(on_delete=models.CASCADE, to='boards.Post')), ], ), ] diff --git a/boards/migrations/0026_auto_20150830_2006.py b/boards/migrations/0026_auto_20150830_2006.py --- a/boards/migrations/0026_auto_20150830_2006.py +++ b/boards/migrations/0026_auto_20150830_2006.py @@ -37,12 +37,12 @@ class Migration(migrations.Migration): ('key_type', models.TextField()), ('key', models.TextField()), ('signature', models.TextField()), - ('global_id', models.ForeignKey(to='boards.GlobalId')), + ('global_id', models.ForeignKey(on_delete=models.CASCADE, to='boards.GlobalId')), ], ), migrations.AddField( model_name='post', name='global_id', - field=models.OneToOneField(to='boards.GlobalId', null=True, blank=True), + field=models.OneToOneField(on_delete=models.CASCADE, to='boards.GlobalId', null=True, blank=True), ), ] diff --git a/boards/migrations/0029_tag_parent.py b/boards/migrations/0029_tag_parent.py --- a/boards/migrations/0029_tag_parent.py +++ b/boards/migrations/0029_tag_parent.py @@ -14,6 +14,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='tag', name='parent', - field=models.ForeignKey(to='boards.Tag', null=True), + field=models.ForeignKey(on_delete=models.CASCADE, to='boards.Tag', null=True), ), ] diff --git a/boards/migrations/0030_auto_20150929_1816.py b/boards/migrations/0030_auto_20150929_1816.py --- a/boards/migrations/0030_auto_20150929_1816.py +++ b/boards/migrations/0030_auto_20150929_1816.py @@ -14,6 +14,6 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='tag', name='parent', - field=models.ForeignKey(related_name='children', null=True, to='boards.Tag'), + field=models.ForeignKey(on_delete=models.CASCADE, related_name='children', null=True, to='boards.Tag'), ), ] diff --git a/boards/migrations/0033_auto_20151014_2224.py b/boards/migrations/0033_auto_20151014_2224.py --- a/boards/migrations/0033_auto_20151014_2224.py +++ b/boards/migrations/0033_auto_20151014_2224.py @@ -14,6 +14,6 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='tag', name='parent', - field=models.ForeignKey(blank=True, related_name='children', to='boards.Tag', null=True), + field=models.ForeignKey(on_delete=models.CASCADE, blank=True, related_name='children', to='boards.Tag', null=True), ), ] diff --git a/boards/models/attachment/__init__.py b/boards/models/attachment/__init__.py --- a/boards/models/attachment/__init__.py +++ b/boards/models/attachment/__init__.py @@ -173,9 +173,9 @@ class StickerPack(models.Model): class AttachmentSticker(models.Model): - attachment = models.ForeignKey('Attachment') + attachment = models.ForeignKey('Attachment', on_delete=models.CASCADE) name = models.TextField(unique=True) - stickerpack = models.ForeignKey('StickerPack') + stickerpack = models.ForeignKey('StickerPack', on_delete=models.CASCADE) def __str__(self): # Local stickers do not have a sticker pack diff --git a/boards/models/attachment/viewers.py b/boards/models/attachment/viewers.py --- a/boards/models/attachment/viewers.py +++ b/boards/models/attachment/viewers.py @@ -1,17 +1,10 @@ -import re - -from PIL import Image - from django.contrib.staticfiles import finders from django.contrib.staticfiles.templatetags.staticfiles import static from django.core.files.images import get_image_dimensions from django.template.defaultfilters import filesizeformat -from django.core.urlresolvers import reverse -from django.utils.translation import ugettext_lazy as _, ungettext_lazy +from boards import settings from boards.utils import get_domain, cached_result, get_extension -from boards import settings - FILE_STUB_IMAGE = 'images/file.png' FILE_STUB_URL = 'url' diff --git a/boards/models/banner.py b/boards/models/banner.py --- a/boards/models/banner.py +++ b/boards/models/banner.py @@ -4,7 +4,7 @@ from django.db import models class Banner(models.Model): title = models.TextField() text = models.TextField(blank=True, null=True) - post = models.ForeignKey('Post') + post = models.ForeignKey('Post', on_delete=models.CASCADE) def __str__(self): return self.title diff --git a/boards/models/post/__init__.py b/boards/models/post/__init__.py --- a/boards/models/post/__init__.py +++ b/boards/models/post/__init__.py @@ -1,8 +1,13 @@ import uuid + import hashlib import re +from django.db import models +from django.db.models import TextField +from django.template.defaultfilters import truncatewords, striptags +from django.template.loader import render_to_string +from django.urls import reverse -from boards import settings from boards.abstracts.tripcode import Tripcode from boards.models import Attachment, KeyPair, GlobalId from boards.models.attachment import FILE_TYPES_IMAGE @@ -10,12 +15,6 @@ from boards.models.base import Viewable from boards.models.post.export import get_exporter, DIFF_TYPE_JSON from boards.models.post.manager import PostManager, NO_IP from boards.utils import datetime_to_epoch -from django.core.exceptions import ObjectDoesNotExist -from django.core.urlresolvers import reverse -from django.db import models -from django.db.models import TextField, QuerySet, F -from django.template.defaultfilters import truncatewords, striptags -from django.template.loader import render_to_string CSS_CLS_HIDDEN_POST = 'hidden_post' CSS_CLS_DEAD_POST = 'dead_post' @@ -87,7 +86,8 @@ class Post(models.Model, Viewable): blank=True, related_name='refposts', db_index=True) refmap = models.TextField(null=True, blank=True) - thread = models.ForeignKey('Thread', db_index=True, related_name='replies') + thread = models.ForeignKey('Thread', on_delete=models.CASCADE, + db_index=True, related_name='replies') url = models.TextField() uid = models.TextField() diff --git a/boards/models/signature.py b/boards/models/signature.py --- a/boards/models/signature.py +++ b/boards/models/signature.py @@ -122,4 +122,4 @@ class Signature(models.Model): key = models.TextField() signature = models.TextField() - global_id = models.ForeignKey('GlobalId') + global_id = models.ForeignKey('GlobalId', on_delete=models.CASCADE) diff --git a/boards/models/source.py b/boards/models/source.py --- a/boards/models/source.py +++ b/boards/models/source.py @@ -29,7 +29,7 @@ class ThreadSource(models.Model): app_label = 'boards' name = models.TextField() - thread = models.ForeignKey('Thread') + thread = models.ForeignKey('Thread', on_delete=models.CASCADE) timestamp = models.DateTimeField() source = models.TextField() source_type = models.CharField(max_length=SOURCE_TYPE_MAX_LENGTH, diff --git a/boards/models/tag.py b/boards/models/tag.py --- a/boards/models/tag.py +++ b/boards/models/tag.py @@ -1,5 +1,5 @@ import hashlib -from django.core.urlresolvers import reverse +from django.urls import reverse from django.db import models from django.db.models import Count, Q from django.utils.translation import get_language @@ -37,8 +37,8 @@ class TagAlias(models.Model, Viewable): name = models.CharField(max_length=100, db_index=True) locale = models.CharField(max_length=10, db_index=True) - parent = models.ForeignKey('Tag', null=True, blank=True, - related_name='aliases') + parent = models.ForeignKey('Tag', on_delete=models.CASCADE, null=True, + blank=True, related_name='aliases') class TagManager(models.Manager): @@ -91,8 +91,8 @@ class Tag(models.Model, Viewable): required = models.BooleanField(default=False, db_index=True) description = models.TextField(blank=True) - parent = models.ForeignKey('Tag', null=True, blank=True, - related_name='children') + parent = models.ForeignKey('Tag', on_delete=models.CASCADE, null=True, + blank=True, related_name='children') def get_name(self): return self.aliases.get(locale=DEFAULT_LOCALE).name diff --git a/boards/models/user.py b/boards/models/user.py --- a/boards/models/user.py +++ b/boards/models/user.py @@ -40,6 +40,6 @@ class Notification(models.Model): objects = NotificationManager() - post = models.ForeignKey('Post') + post = models.ForeignKey('Post', on_delete=models.CASCADE) name = models.TextField() diff --git a/boards/templatetags/board.py b/boards/templatetags/board.py --- a/boards/templatetags/board.py +++ b/boards/templatetags/board.py @@ -1,13 +1,9 @@ import re - +from django import template from django.shortcuts import get_object_or_404 -from django import template from django.utils.text import re_tag -from django.core.urlresolvers import reverse from boards.mdx_neboard import LINE_BREAK_HTML -from boards import settings - IMG_ACTION_URL = '[{}]' REGEX_NEWLINE = re.compile(LINE_BREAK_HTML) diff --git a/boards/urls.py b/boards/urls.py --- a/boards/urls.py +++ b/boards/urls.py @@ -1,4 +1,6 @@ from django.conf.urls import url +from django.urls import path +from django.views.i18n import JavaScriptCatalog from boards import views from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed @@ -12,12 +14,8 @@ from boards.views.search import BoardSea from boards.views.static import StaticPageView from boards.views.sync import get_post_sync_data, response_get, response_list from boards.views.tag_gallery import TagGalleryView -from boards.views.translation import cached_javascript_catalog from boards.views.utils import UtilsView -js_info_dict = { - 'packages': ('boards',), -} urlpatterns = [ # /boards/ @@ -61,8 +59,7 @@ urlpatterns = [ url(r'^thread/(?P\d+)/rss/$', ThreadPostsFeed()), # i18n - url(r'^jsi18n/$', cached_javascript_catalog, js_info_dict, - name='js_info_dict'), + path('jsi18n/', JavaScriptCatalog.as_view(packages=['boards']), name='js_info_dict'), # API url(r'^api/post/(?P\d+)/$', api.get_post, name="get_post"), diff --git a/boards/views/__init__.py b/boards/views/__init__.py --- a/boards/views/__init__.py +++ b/boards/views/__init__.py @@ -1,9 +0,0 @@ -__author__ = 'neko259' - -from django.views.decorators.cache import cache_page -from django.views.i18n import javascript_catalog - - -@cache_page(86400) -def cached_js_catalog(request, domain='djangojs', packages=None): - return javascript_catalog(request, domain, packages) 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 @@ -1,24 +1,22 @@ -from django.core.urlresolvers import reverse -from django.core.files import File -from django.core.files.temp import NamedTemporaryFile from django.core.paginator import EmptyPage from django.db import transaction from django.http import Http404 from django.shortcuts import render, redirect +from django.urls import reverse from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_protect from boards import utils, settings from boards.abstracts.paginator import get_paginator -from boards.abstracts.settingsmanager import get_settings_manager,\ - SETTING_ONLY_FAVORITES +from boards.abstracts.settingsmanager import get_settings_manager, \ + SETTING_ONLY_FAVORITES from boards.forms import ThreadForm, PlainErrorList from boards.models import Post, Thread, Ban from boards.views.banned import BannedView from boards.views.base import BaseBoardView, CONTEXT_FORM +from boards.views.mixins import FileUploadMixin, PaginatedMixin, \ + DispatcherMixin, PARAMETER_METHOD from boards.views.posting_mixin import PostMixin -from boards.views.mixins import FileUploadMixin, PaginatedMixin,\ - DispatcherMixin, PARAMETER_METHOD FORM_TAGS = 'tags' FORM_TEXT = 'text' diff --git a/boards/views/feed.py b/boards/views/feed.py --- a/boards/views/feed.py +++ b/boards/views/feed.py @@ -1,4 +1,4 @@ -from django.core.urlresolvers import reverse +from django.urls import reverse from django.shortcuts import render from boards import settings diff --git a/boards/views/search.py b/boards/views/search.py --- a/boards/views/search.py +++ b/boards/views/search.py @@ -1,7 +1,7 @@ from django.shortcuts import render from django.views.generic import View from django.db.models import Q -from django.core.urlresolvers import reverse +from django.urls import reverse from boards.abstracts.paginator import get_paginator from boards.forms import SearchForm, PlainErrorList 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 @@ -1,9 +1,9 @@ -from django.core.urlresolvers import reverse 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 Tag, TagAlias +from boards.models import TagAlias from boards.views.base import BaseBoardView from boards.views.mixins import PaginatedMixin diff --git a/boards/views/tag_threads.py b/boards/views/tag_threads.py --- a/boards/views/tag_threads.py +++ b/boards/views/tag_threads.py @@ -1,5 +1,5 @@ from django.shortcuts import get_object_or_404, redirect -from django.core.urlresolvers import reverse +from django.urls import reverse from boards.abstracts.settingsmanager import get_settings_manager, \ SETTING_FAVORITE_TAGS, SETTING_HIDDEN_TAGS diff --git a/boards/views/thread/thread.py b/boards/views/thread/thread.py --- a/boards/views/thread/thread.py +++ b/boards/views/thread/thread.py @@ -1,24 +1,18 @@ -from django.contrib.auth.decorators import permission_required - from django.core.exceptions import ObjectDoesNotExist -from django.core.urlresolvers import reverse from django.http import Http404 from django.shortcuts import get_object_or_404, render, redirect -from django.template.context_processors import csrf +from django.urls import reverse from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_protect from django.views.generic.edit import FormMixin -from django.utils import timezone -from django.utils.dateformat import format -from boards import utils, settings +from boards import utils from boards.abstracts.settingsmanager import get_settings_manager from boards.forms import PostForm, PlainErrorList from boards.models import Post from boards.views.base import BaseBoardView, CONTEXT_FORM from boards.views.mixins import DispatcherMixin, PARAMETER_METHOD from boards.views.posting_mixin import PostMixin -import neboard REQ_POST_ID = 'post_id' diff --git a/boards/views/translation.py b/boards/views/translation.py deleted file mode 100644 --- a/boards/views/translation.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.views.decorators.cache import cache_page -from django.views.i18n import javascript_catalog - -@cache_page(600) -def cached_javascript_catalog(request, domain='djangojs', packages=None): - return javascript_catalog(request, domain, packages) - diff --git a/neboard/settings.py b/neboard/settings.py --- a/neboard/settings.py +++ b/neboard/settings.py @@ -104,7 +104,7 @@ TEMPLATES = [{ }] -MIDDLEWARE_CLASSES = [ +MIDDLEWARE = [ 'django.middleware.http.ConditionalGetMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', @@ -179,7 +179,7 @@ POSTING_DELAY = 20 # seconds SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db' # Debug middlewares -MIDDLEWARE_CLASSES += [ +MIDDLEWARE += [ 'debug_toolbar.middleware.DebugToolbarMiddleware', ] diff --git a/neboard/urls.py b/neboard/urls.py --- a/neboard/urls.py +++ b/neboard/urls.py @@ -13,7 +13,7 @@ urlpatterns = [ # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), - url(r'^admin/', include(admin.site.urls), name='admin'), + url(r'^admin/', admin.site.urls, name='admin'), url(r'^', include('boards.urls')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)