Skip to content

Commit

Permalink
Merge pull request #1149 from rafalp/remove-global-state-threadstore
Browse files Browse the repository at this point in the history
Remove misago.core.threadstore
  • Loading branch information
rafalp committed Dec 20, 2018
2 parents 9ecf2bd + 4477bb0 commit fa50746
Show file tree
Hide file tree
Showing 23 changed files with 68 additions and 431 deletions.
1 change: 0 additions & 1 deletion devproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@
'misago.users.middleware.OnlineTrackerMiddleware',
'misago.admin.middleware.AdminAuthMiddleware',
'misago.threads.middleware.UnreadThreadsCountMiddleware',
'misago.core.middleware.ThreadStoreMiddleware',
]

ROOT_URLCONF = 'devproject.urls'
Expand Down
10 changes: 1 addition & 9 deletions misago/acl/migrations/0002_acl_version_tracker.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
from django.db import migrations


def register_acl_version_tracker(apps, schema_editor):
from misago.core.migrationutils import cachebuster_register_cache
cachebuster_register_cache(apps, "misago_acl")


class Migration(migrations.Migration):
"""Superseded by 0004"""

Expand All @@ -14,7 +9,4 @@ class Migration(migrations.Migration):
('misago_core', '0001_initial'),
]

operations = [
# FIXME: remove this operation
migrations.RunPython(register_acl_version_tracker),
]
operations = []
35 changes: 17 additions & 18 deletions misago/admin/views/generic/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ def dispatch(self, request, *args, **kwargs):
# So address ball contains copy-friendly link
refresh_querystring = True

SearchForm = self.get_search_form(request)
if SearchForm:
filtering_methods = self.get_filtering_methods(request)
search_form = self.get_search_form(request)
if search_form:
filtering_methods = self.get_filtering_methods(request, search_form)
active_filters = self.get_filtering_method_to_use(filtering_methods)
if request.GET.get('clear_filters'):
# Clear filters from querystring
request.session.pop(self.filters_session_key, None)
active_filters = {}
self.apply_filtering_on_context(context, active_filters, SearchForm)
self.apply_filtering_on_context(context, active_filters, search_form)

if (filtering_methods['GET'] and
filtering_methods['GET'] != filtering_methods['session']):
Expand Down Expand Up @@ -181,12 +181,23 @@ def get_search_form(self, request):
def filters_session_key(self):
return 'misago_admin_%s_filters' % self.root_link

def get_filters_from_GET(self, search_form, request):
def get_filtering_methods(self, request, search_form):
methods = {
'GET': self.get_filters_from_GET(request, search_form),
'session': self.get_filters_from_session(request, search_form),
}

if request.GET.get('set_filters'):
methods['session'] = {}

return methods

def get_filters_from_GET(self, request, search_form):
form = search_form(request.GET)
form.is_valid()
return self.clean_filtering_data(form.cleaned_data)

def get_filters_from_session(self, search_form, request):
def get_filters_from_session(self, request, search_form):
session_filters = request.session.get(self.filters_session_key, {})
form = search_form(session_filters)
form.is_valid()
Expand All @@ -198,18 +209,6 @@ def clean_filtering_data(self, data):
del data[key]
return data

def get_filtering_methods(self, request):
SearchForm = self.get_search_form(request)
methods = {
'GET': self.get_filters_from_GET(SearchForm, request),
'session': self.get_filters_from_session(SearchForm, request),
}

if request.GET.get('set_filters'):
methods['session'] = {}

return methods

def get_filtering_method_to_use(self, methods):
for method in ('GET', 'session'):
if methods.get(method):
Expand Down
7 changes: 4 additions & 3 deletions misago/categories/tests/test_category_model.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.test import TestCase

from misago.categories import THREADS_ROOT_NAME
from misago.categories.models import Category
from misago.core.testutils import MisagoTestCase
from misago.threads import testutils
from misago.threads.threadtypes import trees_map


class CategoryManagerTests(MisagoTestCase):
class CategoryManagerTests(TestCase):
def test_private_threads(self):
"""private_threads returns private threads category"""
category = Category.objects.private_threads()
Expand Down Expand Up @@ -45,7 +46,7 @@ def test_get_categories_dict_from_db(self):
self.assertNotIn(category.id, test_dict)


class CategoryModelTests(MisagoTestCase):
class CategoryModelTests(TestCase):
def setUp(self):
super().setUp()

Expand Down
3 changes: 0 additions & 3 deletions misago/categories/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from misago.categories.models import Category
from misago.categories.utils import get_categories_tree, get_category_path
from misago.conftest import get_cache_versions
from misago.core import threadstore
from misago.users.testutils import AuthenticatedUserTestCase

cache_versions = get_cache_versions()
Expand Down Expand Up @@ -33,9 +32,7 @@ def setUp(self):
Category E
+ Subcategory F
"""

super().setUp()
threadstore.clear()

self.root = Category.objects.root_category()
self.first_category = Category.objects.get(slug='first-category')
Expand Down
4 changes: 0 additions & 4 deletions misago/conf/dynamicsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ def remove_overrides(cls):
cls._overrides = {}


def get_cache_name(cache_versions):
return "%s_%s" % (SETTINGS_CACHE, cache_versions[SETTINGS_CACHE])


def get_settings_from_db():
settings = {}
for setting in Setting.objects.iterator():
Expand Down
12 changes: 3 additions & 9 deletions misago/conf/tests/test_context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@

from django.test import TestCase

from misago.cache.versions import get_cache_versions
from misago.core import threadstore
from misago.conftest import get_cache_versions

from misago.conf.context_processors import conf
from misago.conf.dynamicsettings import DynamicSettings


class ContextProcessorsTests(TestCase):
def tearDown(self):
threadstore.clear()

def test_db_settings(self):
"""DBSettings are exposed to templates"""
def test_request_settings_are_included_in_template_context(self):
cache_versions = get_cache_versions()
mock_request = Mock(settings=DynamicSettings(cache_versions))
context_settings = conf(mock_request)['settings']
assert context_settings == mock_request.settings

def test_preload_settings(self):
"""site configuration is preloaded by middleware"""
def test_settings_are_included_in_frontend_context(self):
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
self.assertContains(response, '"SETTINGS": {"')
4 changes: 0 additions & 4 deletions misago/conf/tests/test_migrationutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from misago.conf import migrationutils
from misago.conf.models import SettingsGroup
from misago.core import threadstore


class DBConfMigrationUtilsTests(TestCase):
Expand Down Expand Up @@ -36,9 +35,6 @@ def setUp(self):
migrationutils.migrate_settings_group(apps, self.test_group)
self.groups_count = SettingsGroup.objects.count()

def tearDown(self):
threadstore.clear()

def test_get_custom_group_and_settings(self):
"""tests setup created settings group"""
custom_group = migrationutils.get_group(
Expand Down
104 changes: 0 additions & 104 deletions misago/core/cachebuster.py

This file was deleted.

8 changes: 1 addition & 7 deletions misago/core/middleware.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.utils.deprecation import MiddlewareMixin

from misago.core import exceptionhandler, threadstore
from misago.core import exceptionhandler
from misago.core.utils import is_request_to_misago


Expand All @@ -19,9 +19,3 @@ class FrontendContextMiddleware(MiddlewareMixin):
def process_request(self, request):
request.include_frontend_context = True
request.frontend_context = {}


class ThreadStoreMiddleware(MiddlewareMixin):
def process_response(self, request, response):
threadstore.clear()
return response
24 changes: 0 additions & 24 deletions misago/core/migrationutils.py

This file was deleted.

Loading

0 comments on commit fa50746

Please sign in to comment.