Browse Source

Merge pull request #634 from NotKit/master

Django 1.10 compatibility
Rafał Pitoń 8 years ago
parent
commit
3b57e42758

+ 2 - 1
misago/acl/testutils.py

@@ -1,4 +1,5 @@
 # pylint: disable=protected-access
+from copy import deepcopy
 from hashlib import md5
 
 from misago.core import threadstore
@@ -25,7 +26,7 @@ def fake_post_data(target, data_dict):
 
 def override_acl(user, new_acl):
     """overrides user permissions with specified ones"""
-    final_cache = user.acl
+    final_cache = deepcopy(user.acl)
     final_cache.update(new_acl)
 
     if user.is_authenticated():

+ 1 - 1
misago/admin/urls.py

@@ -1,4 +1,4 @@
-from django.conf.urls import include, patterns, url
+from django.conf.urls import include, url
 
 from misago import admin
 

+ 5 - 4
misago/categories/tests/test_prunecategories.py

@@ -1,5 +1,6 @@
 from datetime import timedelta
 
+from django.core.management import call_command
 from django.test import TestCase
 from django.utils import timezone
 from django.utils.six import StringIO
@@ -37,7 +38,7 @@ class PruneCategoriesTests(TestCase):
         command = prunecategories.Command()
 
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
 
         category.synchronize()
         self.assertEqual(category.threads, 10)
@@ -73,7 +74,7 @@ class PruneCategoriesTests(TestCase):
         command = prunecategories.Command()
 
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
 
         category.synchronize()
         self.assertEqual(category.threads, 10)
@@ -119,7 +120,7 @@ class PruneCategoriesTests(TestCase):
         command = prunecategories.Command()
 
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
 
         category.synchronize()
         self.assertEqual(category.threads, 10)
@@ -168,7 +169,7 @@ class PruneCategoriesTests(TestCase):
         command = prunecategories.Command()
 
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
 
         category.synchronize()
         self.assertEqual(category.threads, 10)

+ 2 - 1
misago/categories/tests/test_synchronizecategories.py

@@ -1,3 +1,4 @@
+from django.core.management import call_command
 from django.test import TestCase
 from django.utils.six import StringIO
 from django.utils.six.moves import range
@@ -23,7 +24,7 @@ class SynchronizeCategoriesTests(TestCase):
         command = synchronizecategories.Command()
 
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
 
         category = Category.objects.get(id=category.id)
         self.assertEqual(category.threads, 10)

+ 5 - 5
misago/conf/defaults.py

@@ -84,11 +84,11 @@ MIDDLEWARE_CLASSES = (
 
 TEMPLATE_CONTEXT_PROCESSORS = (
     'django.contrib.auth.context_processors.auth',
-    'django.core.context_processors.debug',
-    'django.core.context_processors.i18n',
-    'django.core.context_processors.media',
-    'django.core.context_processors.static',
-    'django.core.context_processors.tz',
+    'django.template.context_processors.debug',
+    'django.template.context_processors.i18n',
+    'django.template.context_processors.media',
+    'django.template.context_processors.static',
+    'django.template.context_processors.tz',
     'django.contrib.messages.context_processors.messages',
 
     'misago.core.context_processors.site_address',

+ 2 - 4
misago/core/mail.py

@@ -1,5 +1,4 @@
 from django.core import mail as djmail
-from django.template import RequestContext
 from django.template.loader import render_to_string
 
 
@@ -8,10 +7,9 @@ def build_mail(request, recipient, subject, template, context=None):
     context['sender'] = request.user
     context['recipient'] = recipient
     context['subject'] = subject
-    context = RequestContext(request, context)
 
-    message_plain = render_to_string('%s.txt' % template, context)
-    message_html = render_to_string('%s.html' % template, context)
+    message_plain = render_to_string('%s.txt' % template, context, request=request)
+    message_html = render_to_string('%s.html' % template, context, request=request)
 
     message = djmail.EmailMultiAlternatives(
         subject, message_plain, to=[recipient.email])

+ 1 - 1
misago/core/management/commands/misagodbrelations.py

@@ -35,7 +35,7 @@ class Command(BaseCommand):
                             self.stdout.write(field_pattern % (
                                 field.name,
                                 field.__class__.__name__,
-                                field.related.model.__name__,
+                                field.related_model.__name__,
                                 field.rel.on_delete.__name__,
                             ))
 

+ 10 - 1
misago/core/management/commands/remakemisagochecksums.py

@@ -8,12 +8,21 @@ from ...signals import secret_key_changed
 class Command(BaseCommand):
     help = 'Regenerates Misago checksums after SECRET_KEY changed.'
 
+    def add_arguments(self, parser):
+        parser.add_argument(
+            '--force',
+            action='store_true',
+            dest='force',
+            default=False,
+            help='Do not ask for confirmation',
+        )
+
     def handle(self, *args, **options):
         message = force_str("This will replace all checksums "
                             "in database with new ones, marking "
                             "all data as trusted. Are you sure "
                             "you wish to continue? [Y/n]")
-        if '--force' in args or input(message).strip().lower() == "y":
+        if options['force'] or input(message).strip().lower() == "y":
             self.stdout.write("\nRegenerating checksums...")
             secret_key_changed.send(self)
             self.stdout.write("\nDone!")

+ 4 - 6
misago/core/management/commands/testemailsetup.py

@@ -8,16 +8,14 @@ from django.core.validators import validate_email
 class Command(BaseCommand):
     help = 'Sends test e-mail to given address'
 
+    def add_arguments(self, parser):
+        parser.add_argument('email', type=str)
+
     def handle(self, *args, **options):
         try:
-            if len(args) != 1:
-                raise ValueError()
-            email = args[0]
+            email = options['email']
             validate_email(email)
             self.send_message(email)
-        except ValueError:
-            self.stderr.write("Command accepts exactly "
-                              "one argument (e-mail address)")
         except ValidationError:
             self.stderr.write("This isn't valid e-mail address")
 

+ 2 - 1
misago/core/tests/test_misagodbrelations.py

@@ -1,3 +1,4 @@
+from django.core.management import call_command
 from django.test import TestCase
 from django.utils.six import StringIO
 
@@ -9,4 +10,4 @@ class MisagoDBRelationsTests(TestCase):
         """command raises no errors during execution"""
         command = misagodbrelations.Command()
 
-        command.execute(stdout=StringIO())
+        call_command(command, stdout=StringIO())

+ 2 - 1
misago/core/tests/test_remakemisagochecksums.py

@@ -1,3 +1,4 @@
+from django.core.management import call_command
 from django.test import TestCase
 from django.utils.six import StringIO
 
@@ -10,6 +11,6 @@ class RemakeMisagoChecksumsTests(TestCase):
         command = remakemisagochecksums.Command()
 
         out = StringIO()
-        command.execute("--force", stdout=out)
+        call_command(command, "--force", stdout=out)
         command_output = out.getvalue().splitlines()[-1].strip()
         self.assertEqual(command_output, "Done!")

+ 4 - 14
misago/core/tests/test_testmailsetup.py

@@ -1,7 +1,9 @@
 from django.core import mail
+from django.core.management import call_command
 from django.test import TestCase
 from django.utils.six import StringIO
 
+
 from ..management.commands import testemailsetup
 
 
@@ -11,7 +13,7 @@ class TestEmailSetupTests(TestCase):
         command = testemailsetup.Command()
 
         out = StringIO()
-        command.execute("t@mail.com", stdout=out)
+        call_command(command, "t@mail.com", stdout=out)
         command_output = out.getvalue().splitlines()[0].strip()
 
         self.assertEqual(command_output, 'Test message was sent to t@mail.com')
@@ -26,18 +28,6 @@ class TestEmailSetupTests(TestCase):
         out = StringIO()
         err = StringIO()
 
-        command.execute(stdout=out, stderr=err)
-        command_output = err.getvalue().splitlines()[-1].strip()
-        self.assertEqual(
-            command_output,
-            "Command accepts exactly one argument (e-mail address)")
-
-        command.execute("baww", "awww", stdout=out, stderr=err)
-        command_output = err.getvalue().splitlines()[-1].strip()
-        self.assertEqual(
-            command_output,
-            "Command accepts exactly one argument (e-mail address)")
-
-        command.execute("bawww", stdout=out, stderr=err)
+        call_command(command, "bawww", stdout=out, stderr=err)
         command_output = err.getvalue().splitlines()[-1].strip()
         self.assertEqual(command_output, "This isn't valid e-mail address")

+ 12 - 5
misago/project_template/project_name/settings.py

@@ -23,8 +23,6 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 # SECURITY WARNING: don't run with debug turned on in production!
 DEBUG = True
 
-TEMPLATE_DEBUG = DEBUG
-
 # Hosts allowed to POST to your site
 # If you are unsure, just enter here your host name, eg. 'mysite.com'
 
@@ -96,9 +94,18 @@ STATICFILES_DIRS = (
     os.path.join(BASE_DIR, 'theme', 'static'),
 )
 
-TEMPLATE_DIRS = (
-    os.path.join(BASE_DIR, 'theme', 'templates'),
-)
+TEMPLATES = [
+    {
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
+        'DIRS': [
+            os.path.join(BASE_DIR, 'theme', 'templates'),
+        ],
+        'APP_DIRS': True,
+        'OPTIONS': {
+            'context_processors': TEMPLATE_CONTEXT_PROCESSORS,
+        },
+    },
+]
 
 
 # SECURITY WARNING: keep the secret key used in production secret!

+ 3 - 2
misago/threads/tests/test_clearattachments.py

@@ -1,6 +1,7 @@
 from datetime import timedelta
 
 from django.conf import settings
+from django.core.management import call_command
 from django.test import TestCase
 from django.utils import timezone
 from django.utils.six import StringIO
@@ -18,7 +19,7 @@ class ClearAttachmentsTests(TestCase):
         command = clearattachments.Command()
 
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
         command_output = out.getvalue().strip()
 
         self.assertEqual(command_output, "No attachments were found")
@@ -75,7 +76,7 @@ class ClearAttachmentsTests(TestCase):
         command = clearattachments.Command()
 
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
 
         command_output = out.getvalue().splitlines()[-1].strip()
         self.assertEqual(command_output, "Cleared 5 attachments")

+ 3 - 2
misago/threads/tests/test_synchronizethreads.py

@@ -1,3 +1,4 @@
+from django.core.management import call_command
 from django.test import TestCase
 from django.utils.six import StringIO
 from django.utils.six.moves import range
@@ -14,7 +15,7 @@ class SynchronizeThreadsTests(TestCase):
         command = synchronizethreads.Command()
 
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
         command_output = out.getvalue().strip()
 
         self.assertEqual(command_output, "No threads were found")
@@ -32,7 +33,7 @@ class SynchronizeThreadsTests(TestCase):
         command = synchronizethreads.Command()
 
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
 
         for i, thread in enumerate(threads):
             db_thread = category.thread_set.get(id=thread.id)

+ 19 - 24
misago/users/management/commands/createsuperuser.py

@@ -4,7 +4,6 @@ works with double authentication fields on user model
 """
 import sys
 from getpass import getpass
-from optparse import make_option
 
 from django.contrib.auth import get_user_model
 from django.core.exceptions import ValidationError
@@ -23,29 +22,25 @@ class NotRunningInTTYException(Exception):
 class Command(BaseCommand):
     help = 'Used to create a superuser.'
 
-    def __init__(self, *args, **kwargs):
-        super(Command, self).__init__(*args, **kwargs)
-
-        self.option_list = BaseCommand.option_list + (
-            make_option('--username', dest='username', default=None,
-                        help='Specifies the username for the superuser.'),
-            make_option('--email', dest='email', default=None,
-                        help='Specifies the username for the superuser.'),
-            make_option('--password', dest='password', default=None,
-                        help='Specifies the username for the superuser.'),
-            make_option('--noinput', action='store_false', dest='interactive',
-                        default=True,
-                        help=('Tells Miago to NOT prompt the user for input '
-                              'of any kind. You must use --username with '
-                              '--noinput, along with an option for any other '
-                              'required field. Superusers created with '
-                              '--noinput will  not be able to log in until '
-                              'they\'re given a valid password.')),
-            make_option('--database', action='store', dest='database',
-                        default=DEFAULT_DB_ALIAS,
-                        help=('Specifies the database to use. '
-                              'Default is "default".')),
-        )
+    def add_arguments(self, parser):
+        parser.add_argument('--username', dest='username', default=None,
+                    help='Specifies the username for the superuser.')
+        parser.add_argument('--email', dest='email', default=None,
+                    help='Specifies the username for the superuser.')
+        parser.add_argument('--password', dest='password', default=None,
+                    help='Specifies the username for the superuser.')
+        parser.add_argument('--noinput', action='store_false', dest='interactive',
+                    default=True,
+                    help=('Tells Misago to NOT prompt the user for input '
+                          'of any kind. You must use --username with '
+                          '--noinput, along with an option for any other '
+                          'required field. Superusers created with '
+                          '--noinput will  not be able to log in until '
+                          'they\'re given a valid password.'))
+        parser.add_argument('--database', action='store', dest='database',
+                    default=DEFAULT_DB_ALIAS,
+                    help=('Specifies the database to use. '
+                          'Default is "default".'))
 
     def execute(self, *args, **options):
         self.stdin = options.get('stdin', sys.stdin)  # Used for testing

+ 1 - 1
misago/users/serializers/__init__.py

@@ -1,4 +1,4 @@
 from .ban import *
 from .rank import *
 from .user import *
-from .userfeed import UserFeedSerializer
+# from .userfeed import UserFeedSerializer

+ 4 - 3
misago/users/tests/test_bansmaintenance.py

@@ -1,6 +1,7 @@
 from datetime import timedelta
 
 from django.contrib.auth import get_user_model
+from django.core.management import call_command
 from django.test import TestCase
 from django.utils import timezone
 from django.utils.six import StringIO
@@ -25,7 +26,7 @@ class BansMaintenanceTests(TestCase):
         command = bansmaintenance.Command()
 
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
         command_output = out.getvalue().splitlines()[0].strip()
 
         self.assertEqual(command_output, 'Bans invalidated: 5')
@@ -49,7 +50,7 @@ class BansMaintenanceTests(TestCase):
         command = bansmaintenance.Command()
 
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
         command_output = out.getvalue().splitlines()[1].strip()
 
         self.assertEqual(command_output, 'Ban caches emptied: 0')
@@ -62,7 +63,7 @@ class BansMaintenanceTests(TestCase):
 
         # invalidate expired ban cache
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
         command_output = out.getvalue().splitlines()[1].strip()
 
         self.assertEqual(command_output, 'Ban caches emptied: 1')

+ 2 - 1
misago/users/tests/test_populateonlinetracker.py

@@ -1,4 +1,5 @@
 from django.contrib.auth import get_user_model
+from django.core.management import call_command
 from django.test import TestCase
 from django.utils.six import StringIO
 
@@ -17,7 +18,7 @@ class PopulateOnlineTrackerTests(TestCase):
         self.assertEqual(Online.objects.filter(user=test_user).count(), 0)
 
         out = StringIO()
-        populateonlinetracker.Command().execute(stdout=out)
+        call_command(populateonlinetracker.Command(), stdout=out)
         command_output = out.getvalue().splitlines()[0].strip()
 
         self.assertEqual(command_output, 'Tracker entries created: 1')

+ 2 - 1
misago/users/tests/test_updateblankavatar.py

@@ -1,3 +1,4 @@
+from django.core.management import call_command
 from django.test import TestCase
 from django.utils.six import StringIO
 
@@ -10,7 +11,7 @@ class UpdateBlankAvatarTests(TestCase):
         command = updateblankavatar.Command()
 
         out = StringIO()
-        command.execute(stdout=out)
+        call_command(command, stdout=out)
         command_output = out.getvalue().splitlines()[0].strip()
 
         self.assertEqual(command_output, 'Blank avatar was updated')

+ 1 - 1
misago/users/viewmodels/threads.py

@@ -10,7 +10,7 @@ from misago.threads.utils import add_categories_to_items, add_likes_to_posts
 from misago.threads.viewmodels import ThreadsRootCategory
 from misago.users.online.utils import make_users_status_aware
 
-from ..serializers import UserFeedSerializer
+from ..serializers.userfeed import UserFeedSerializer
 
 
 class UserThreads(object):

+ 13 - 13
requirements.txt

@@ -1,17 +1,17 @@
-django~=1.9.6
-djangorestframework==3.3.3
-beautifulsoup4==4.4.1
-bleach==1.4.3
-django-debug-toolbar==1.4
-django-crispy-forms==1.6.0
-django-htmlmin==0.9.1
-django-mptt==0.8.4
-fake-factory~=0.5.7
+django~=1.10.3
+djangorestframework==3.5.3
+beautifulsoup4==4.5.1
+bleach==1.5.0
+django-debug-toolbar==1.6
+django-crispy-forms==1.6.1
+django-htmlmin==0.10.0
+django-mptt==0.8.6
+fake-factory~=0.7.2
 html5lib<0.99999999,>=0.999
-markdown==2.6.6
-path.py==8.2.1
-pillow==3.2.0
-psycopg2==2.6.1
+markdown==2.6.7
+path.py==9.0
+pillow==3.4.2
+psycopg2==2.6.2
 pytz
 requests<3
 unidecode

+ 2 - 2
runtests.py

@@ -119,8 +119,8 @@ def run_django(*args, **kwargs):
     setup()
     setup_test_environment()
 
-    from django.core.management.commands import test
-    sys.exit(test.Command().execute(*args, **kwargs))
+    from django.core.management import call_command
+    sys.exit(call_command('test', *args, **kwargs))
 
 
 if __name__ == '__main__':