From 79e81d69b4be8c6d082aa25626f6f442df830ddb Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Mon, 18 Jun 2012 13:41:53 -0400 Subject: [PATCH] Delay initializition of the MongoKeyStore until required --- .../contentstore/management/commands/import.py | 7 +++---- cms/djangoapps/contentstore/views.py | 2 +- common/lib/keystore/django.py | 11 ++++++++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cms/djangoapps/contentstore/management/commands/import.py b/cms/djangoapps/contentstore/management/commands/import.py index 8b33f32b94..d6064e1e3d 100644 --- a/cms/djangoapps/contentstore/management/commands/import.py +++ b/cms/djangoapps/contentstore/management/commands/import.py @@ -160,9 +160,8 @@ class Command(BaseCommand): element_actions[e.tag](e) for k in results: - print k - keystore.create_item(k, 'Piotr Mitros') + keystore().create_item(k, 'Piotr Mitros') if 'data' in results[k]: - keystore.update_item(k, results[k]['data']) + keystore().update_item(k, results[k]['data']) if 'children' in results[k]: - keystore.update_children(k, results[k]['children']) + keystore().update_children(k, results[k]['children']) diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index 64bde14869..e29c41ea59 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -7,6 +7,6 @@ def index(request): # FIXME (cpennington): These need to be read in from the active user org = 'mit.edu' course = '6002xs12' - course = keystore.get_item(['i4x', org, course, 'Course', None]) + course = keystore().get_item(['i4x', org, course, 'Course', None]) weeks = course.get_children() return render_to_response('index.html', {'weeks': weeks}) diff --git a/common/lib/keystore/django.py b/common/lib/keystore/django.py index b6ffb83b5c..b88c74b8a3 100644 --- a/common/lib/keystore/django.py +++ b/common/lib/keystore/django.py @@ -9,4 +9,13 @@ from __future__ import absolute_import from django.conf import settings from .mongo import MongoKeyStore -keystore = MongoKeyStore(**settings.KEYSTORE) +_KEYSTORE = None + + +def keystore(): + global _KEYSTORE + + if _KEYSTORE is None: + _KEYSTORE = MongoKeyStore(**settings.KEYSTORE) + + return _KEYSTORE