Permalink
Browse files

don't look like django (rename settings.py => config.py)

+ read configs from environ (for Heroku again)
  • Loading branch information...
1 parent 542d16c commit 438cf4e83267193fac237a3d7aaab3009812d9e9 @wil committed Feb 11, 2012
Showing with 48 additions and 21 deletions.
  1. +2 −2 shorty/__init__.py
  2. +46 −0 shorty/config.py
  3. +0 −19 shorty/settings.py
View
@@ -3,13 +3,13 @@
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
-from shorty import settings
+from shorty import config
from shorty.context_processors import static_files
from shorty.core import setup_routing
# setup application
app = Flask('shorty')
-app.config.from_object(settings)
+app.config.from_object(config)
# setup database
db = SQLAlchemy(app)
View
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+
+import os
+
+BASE_URL = os.environ.get('BASE_URL', 'http://localhost:5000')
+
+PREFIX = '_'
+
+DEBUG = True
+TESTING = False
+
+SECRET_KEY = os.environ.get('SECRET_KEY', 'DuMmY sEcReT kEy')
+CSRF_ENABLED = True
+CSRF_SESSION_KEY = '_csrf_token'
+
+if 'DATABASE_URL' in os.environ:
+ import urlparse
+
+ # Register database schemes in URLs.
+ urlparse.uses_netloc.append('postgres')
+ urlparse.uses_netloc.append('mysql')
+
+ url = urlparse.urlparse(os.environ['DATABASE_URL'])
+
+ if url.scheme == 'postgres':
+ scheme = 'postgresql+psycopg2'
+ elif url.scheme == 'mysql':
+ scheme = 'mysql+mysqldb'
+ else:
+ assert False, "Unknown scheme %s" % url.scheme
+
+ SQLALCHEMY_DATABASE_URI = '%s:///%s:%s@%s:%s/%s' % (
+ scheme,
+ url.username,
+ url.password,
+ url.hostname,
+ url.port,
+ url.path[1:],
+ )
+else:
+ SQLALCHEMY_DATABASE_URI = 'sqlite:///shorty.sqlite'
+
+try:
+ from .local_config import *
+except ImportError:
+ pass
View
@@ -1,19 +0,0 @@
-# -*- coding: utf-8 -*-
-
-BASE_URL = 'http://localhost:5000'
-
-PREFIX = '_'
-
-DEBUG = True
-TESTING = False
-
-SECRET_KEY = 'DuMmY sEcReT kEy'
-CSRF_ENABLED = True
-CSRF_SESSION_KEY = '_csrf_token'
-
-SQLALCHEMY_DATABASE_URI = 'sqlite:///shorty.sqlite'
-
-try:
- from .local_settings import *
-except ImportError:
- pass

0 comments on commit 438cf4e

Please sign in to comment.