Expanded page width to 960px
[mediagoblin.git] / mediagoblin / app.py
index e93e0c4e31e62c3bf7ec2bc38c67addd5bac3147..714404deeef23d31b5fc6fdca3a41b2d29f7f6fc 100644 (file)
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+import os
 import urllib
 
 import routes
-import mongokit
 from paste.deploy.converters import asbool
 from webob import Request, exc
 
-from mediagoblin import routing, util, models, storage, staticdirect
+from mediagoblin import routing, util, storage, staticdirect
+from mediagoblin.db.open import setup_connection_and_db_from_config
 from mediagoblin.globals import setup_globals
 from mediagoblin.celery_setup import setup_celery_from_config
 
@@ -34,13 +35,13 @@ class MediaGoblinApp(object):
     """
     Really basic wsgi app using routes and WebOb.
     """
-    def __init__(self, connection, database_path,
+    def __init__(self, connection, db,
                  public_store, queue_store,
                  staticdirector,
                  email_sender_address, email_debug_mode,
                  user_template_path=None):
         # Get the template environment
-        self.template_env = util.get_jinja_env(user_template_path)
+        self.template_loader = util.get_jinja_loader(user_template_path)
         
         # Set up storage systems
         self.public_store = public_store
@@ -48,8 +49,7 @@ class MediaGoblinApp(object):
 
         # Set up database
         self.connection = connection
-        self.db = connection[database_path]
-        models.register_models(connection)
+        self.db = db
 
         # set up routing
         self.routing = routing.get_mapper()
@@ -103,7 +103,10 @@ class MediaGoblinApp(object):
         # Attach self as request.app
         # Also attach a few utilities from request.app for convenience?
         request.app = self
-        request.template_env = self.template_env
+        request.locale = util.get_locale_from_request(request)
+            
+        request.template_env = util.get_jinja_env(
+            self.template_loader, request.locale)
         request.db = self.db
         request.staticdirect = self.staticdirector
 
@@ -114,8 +117,7 @@ class MediaGoblinApp(object):
 
 def paste_app_factory(global_config, **app_config):
     # Get the database connection
-    connection = mongokit.Connection(
-        app_config.get('db_host'), app_config.get('db_port'))
+    connection, db = setup_connection_and_db_from_config(app_config)
 
     # Set up the storage systems.
     public_store = storage.storage_system_from_paste_config(
@@ -137,15 +139,20 @@ def paste_app_factory(global_config, **app_config):
         raise ImproperlyConfigured(
             "One of direct_remote_path or direct_remote_paths must be provided")
 
-    setup_celery_from_config(app_config, global_config)
+    if asbool(os.environ.get('CELERY_ALWAYS_EAGER')):
+        setup_celery_from_config(
+            app_config, global_config,
+            force_celery_always_eager=True)
+    else:
+        setup_celery_from_config(app_config, global_config)
 
     mgoblin_app = MediaGoblinApp(
-        connection, app_config.get('db_name', 'mediagoblin'),
+        connection, db,
         public_store=public_store, queue_store=queue_store,
         staticdirector=staticdirector,
         email_sender_address=app_config.get(
             'email_sender_address', 'notice@mediagoblin.example.org'),
-        email_debug_mode=app_config.get('email_debug_mode'),
+        email_debug_mode=asbool(app_config.get('email_debug_mode')),
         user_template_path=app_config.get('local_templates'))
 
     return mgoblin_app