Commits

Yang Zhang committed f5440c1

add db

Comments (0)

Files changed (6)

projectname/__init__.py

 # -*- coding: utf-8 -*-
 
-import os
-
-import flask as f
-from flask import Flask
-import flask.ext.assets as fassets
-
-import config.conf as conf
-
-app = Flask(__name__)
-
-app.config.from_object("projectname.config.conf")
-
-assets = fassets.Environment(app)
-assets.versions = 'hash:32'
-
-@app.before_request
-def something_before_request():
-    pass
-
-import controllers
+'''stupid file to package the project'''

projectname/app.py

+import os
+
+import flask as f
+from flask import Flask
+import flask.ext.assets as fassets
+
+import config.conf as conf
+
+app = Flask(__name__)
+
+app.config.from_object("projectname.config.conf")
+
+assets = fassets.Environment(app)
+assets.versions = 'hash:32'
+
+@app.before_request
+def something_before_request():
+    pass
+
+import controllers

projectname/controllers/frontend.py

 
 from flask import render_template
 
-from projectname import app
+from projectname.app import app
 
 @app.route('/')
 def main():

projectname/util/db.py

+# coding:utf8
+
+import os
+
+from mongoengine import MongoEngine
+
+from projectname.config import conf
+
+def get_db(database=None):
+    if not database:
+        database = conf.MONGODB_DB
+    if os.environ.get("UNITTEST_MODE"):
+        database = conf.MONGODB_DB_UNITTEST
+    mongo = MongoEngine()
+    mongo.connect(
+        database,
+        host=conf.MONGODB_HOST,
+        port=conf.MONGODB_PORT,
+        username=conf.MONGODB_USER,
+        password=conf.MONGODB_PASSWD
+    )
+    return mongo
+
+db = get_db()
 # -*- coding: utf-8 -*-
 
-from projectname import app
+from projectname.app import app
 
 
 if(__name__ == "__main__"):

unittest/__init__.py

+# -*- coding: utf-8 -*-