Commits

Niall O'Higgins  committed 9250a8b

first cut at adding mongodb scaffold during init

  • Participants
  • Parent commits f782b76

Comments (0)

Files changed (6)

File akhet/paster_templates/__init__.py

     vars = [
         var("sqlalchemy", "Include SQLAlchemy configuration? (y/n)",
             default=True),
+        var("mongodb", "Include MongoDB configuration? (y/n)",
+            default=False),
         ]
 
     def pre(self, command, output_dir, vars): # pragma: no cover
         PyramidTemplate.pre(self, command, output_dir, vars)
         # Superclass sets vars 'random_string' and 'package_logger'.
         vars["sqlalchemy"] = asbool(vars["sqlalchemy"])
+        vars["mongodb"] = asbool(vars["mongodb"])

File akhet/paster_templates/akhet/+package+/__init__.py_tmpl

 import sqlahelper
 import sqlalchemy
 {{endif}}
+{{if mongodb}}
+import pymongo
+{{endif}}
 
 def main(global_config, **settings):
     """ This function returns a Pyramid WSGI application.
     config.include("pyramid_tm")
 {{endif}}
 
+{{if mongodb}}
+    def add_mongo_db(event):
+        settings = event.request.registry.settings
+        url = settings['mongodb.url']
+        db_name = url.rsplit('/').pop()
+        db = settings['mongodb_conn'][db_name]
+        event.request.db = db
+        event.request.fs = GridFS(db)
+    db_uri = settings['mongodb.url']
+    conn = pymongo.Connection(db_uri)
+    config.registry.settings['mongodb_conn'] = conn
+    config.add_subscriber(add_mongo_db, NewRequest)
+{{endif}}
+
     # Configure Beaker sessions and caching
     session_factory = pyramid_beaker.session_factory_from_settings(settings)
     config.set_session_factory(session_factory)

File akhet/paster_templates/akhet/development.ini_tmpl

 {{if sqlalchemy}}
 sqlalchemy.url = sqlite:///%(here)s/db.sqlite
 {{endif}}
+{{if mongodb}}
+mongodb.url = mongodb://localhost/mydb
+{{endif}}
 
 
 [pipeline:main]

File akhet/paster_templates/akhet/production.ini_tmpl

 {{if sqlalchemy}}
 sqlalchemy.url = sqlite:///%(here)s/db.sqlite
 {{endif}}
+{{if mongodb}}
+mongodb.url = mongodb://localhost/mydb
+{{endif}}
 
 
 [filter:weberror]

File akhet/paster_templates/akhet/requirements.txt_tmpl

 {{if sqlalchemy}}
 zope.sqlalchemy
 {{endif}}
+{{if mongodb}}
+pymongo
+{{endif}}

File akhet/paster_templates/akhet/setup.py_tmpl

 {{if sqlalchemy}}
     "zope.sqlalchemy",
 {{endif}}
+{{if mongodb}}
+    "pymongo"
+{{endif}}
 ]