From: hernani Date: Tue, 15 Mar 2011 02:12:27 +0000 (+0000) Subject: Fixes some weird threading problems with modules. X-Git-Tag: live~427 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/6006a10232650fcd622af648036f2e8260ed2e17 Fixes some weird threading problems with modules. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@840 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/models/node.py b/forum/models/node.py index b3ae67e..98c5383 100644 --- a/forum/models/node.py +++ b/forum/models/node.py @@ -8,7 +8,6 @@ from django.utils.safestring import mark_safe from django.utils.html import strip_tags from forum.utils.html import sanitize_html from forum.settings import SUMMARY_LENGTH -from forum.modules import MODULES_PACKAGE from utils import PickledObjectField class NodeContent(models.Model): diff --git a/forum/models/tag.py b/forum/models/tag.py index ce0d8de..5204649 100644 --- a/forum/models/tag.py +++ b/forum/models/tag.py @@ -1,10 +1,7 @@ import datetime from base import * -from forum.modules import MODULES_PACKAGE - from django.utils.translation import ugettext as _ -import django.dispatch class ActiveTagManager(models.Manager): def get_query_set(self): diff --git a/forum/modules/__init__.py b/forum/modules/__init__.py index a5fdaa6..f1ad7d9 100644 --- a/forum/modules/__init__.py +++ b/forum/modules/__init__.py @@ -1,24 +1,7 @@ -import os import types import logging -MODULES_PACKAGE = 'forum_modules' - -MODULE_LIST = [] - - -def init_modules_engine(site_src_root, disabled_modules): - modules_folder = os.path.join(site_src_root, MODULES_PACKAGE) - - MODULE_LIST.extend(filter(lambda m: getattr(m, 'CAN_USE', True), [ - __import__('forum_modules.%s' % f, globals(), locals(), ['forum_modules']) - for f in os.listdir(modules_folder) - if os.path.isdir(os.path.join(modules_folder, f)) and - os.path.exists(os.path.join(modules_folder, "%s/__init__.py" % f)) and - not f in disabled_modules - ])) - - get_modules_folder.value = modules_folder +from django.conf import settings def get_modules_folder(): return get_modules_folder.value @@ -26,7 +9,7 @@ def get_modules_folder(): def get_modules_script(script_name): all = [] - for m in MODULE_LIST: + for m in settings.MODULE_LIST: if hasattr(m, script_name): all.append(getattr(m, script_name)) continue diff --git a/forum/modules/template_loader.py b/forum/modules/template_loader.py index d0e57ac..510f308 100644 --- a/forum/modules/template_loader.py +++ b/forum/modules/template_loader.py @@ -1,7 +1,7 @@ import os, re from forum.skins import load_template_source as skins_template_loader, Template, BaseTemplateLoader -from forum import modules +from django.conf import settings MODULES_TEMPLATE_PREFIX = 'modules/' NO_OVERRIDE_TEMPLATE_PREFIX = 'no_override/' @@ -9,7 +9,7 @@ MODULES_TEMPLATE_FOLDER = 'templates' MODULES_TEMPLATE_OVERRIDES_FOLDER = 'template_overrides' TEMPLATE_OVERRIDE_LOOKUP_PATHS = [f for f in [ - os.path.join(os.path.dirname(m.__file__), MODULES_TEMPLATE_OVERRIDES_FOLDER) for m in modules.MODULE_LIST + os.path.join(os.path.dirname(m.__file__), MODULES_TEMPLATE_OVERRIDES_FOLDER) for m in settings.MODULE_LIST ] if os.path.exists(f) ] @@ -22,7 +22,7 @@ class ModulesTemplateLoader(BaseTemplateLoader): if name.startswith(MODULES_TEMPLATE_PREFIX): match = self.modules_re.search(name) - file_name = os.path.join(modules.get_modules_folder(), match.group(1), MODULES_TEMPLATE_FOLDER, match.group(2)) + file_name = os.path.join(settings.MODULES_FOLDER, match.group(1), MODULES_TEMPLATE_FOLDER, match.group(2)) if os.path.exists(file_name): template = Template(file_name) diff --git a/settings.py b/settings.py index 0db3f3b..de55240 100644 --- a/settings.py +++ b/settings.py @@ -71,16 +71,25 @@ for path in app_url_split[1].split('/')[1:]: if FORCE_SCRIPT_NAME.endswith('/'): FORCE_SCRIPT_NAME = FORCE_SCRIPT_NAME[:-1] -from forum import modules -modules.init_modules_engine(SITE_SRC_ROOT, DISABLED_MODULES) +#Module system initialization +MODULES_PACKAGE = 'forum_modules' +MODULES_FOLDER = os.path.join(SITE_SRC_ROOT, MODULES_PACKAGE) + +MODULE_LIST = filter(lambda m: getattr(m, 'CAN_USE', True), [ + __import__('forum_modules.%s' % f, globals(), locals(), ['forum_modules']) + for f in os.listdir(MODULES_FOLDER) + if os.path.isdir(os.path.join(MODULES_FOLDER, f)) and + os.path.exists(os.path.join(MODULES_FOLDER, "%s/__init__.py" % f)) and + not f in DISABLED_MODULES +]) [MIDDLEWARE_CLASSES.extend( ["%s.%s" % (m.__name__, mc) for mc in getattr(m, 'MIDDLEWARE_CLASSES', [])] - ) for m in modules.MODULE_LIST] + ) for m in MODULE_LIST] [TEMPLATE_LOADERS.extend( ["%s.%s" % (m.__name__, tl) for tl in getattr(m, 'TEMPLATE_LOADERS', [])] - ) for m in modules.MODULE_LIST] + ) for m in MODULE_LIST] INSTALLED_APPS = [