Skip to content

Commit 020fa23

Browse files
committed
Merge pull request #13 from iromli/simplified-config
Simplify config loading from single source
2 parents 0da0897 + be5acde commit 020fa23

3 files changed

Lines changed: 26 additions & 72 deletions

File tree

users/__init__.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@
1010
from flask import Flask
1111
from flask_mail import Mail
1212

13-
from users.config import (
14-
PROJECT_NAME,
15-
PUBLIC_URL,
16-
PROJECT_FAVICON_FILE,
17-
MAIL_CONFIG,
18-
SQLITE_DB_PATH,
19-
USER_ICONS)
20-
2113

2214
def add_handler_once(logger, handler):
2315
"""A helper to add a handler to a logger, ensuring there are no duplicates.
@@ -75,16 +67,18 @@ def setup_logger():
7567

7668
APP = Flask(__name__)
7769

78-
# Load configuration
79-
APP.config['PROJECT_NAME'] = PROJECT_NAME
80-
APP.config['PUBLIC_URL'] = PUBLIC_URL
81-
APP.config['PROJECT_FAVICON_FILE'] = PROJECT_FAVICON_FILE
82-
APP.config.update(MAIL_CONFIG)
70+
# Load configuration from ``users.config``.
71+
# This will raise ``ImportError`` if such module isn't exist.
72+
# Simply copy the contents of ``config.py.example`` file,
73+
# and save it into a file named ``config.py``.
74+
APP.config.from_object("users.config")
8375
mail = Mail(APP)
84-
APP.config['DATABASE'] = SQLITE_DB_PATH
85-
APP.config['USER_ICONS'] = USER_ICONS
76+
77+
# backward-compat
78+
APP.config['DATABASE'] = APP.config['SQLITE_DB_PATH']
79+
8680
# Don't import actual view methods themselves - see:
8781
# http://flask.pocoo.org/docs/patterns/packages/#larger-applications
8882
# Also views must be imported AFTER app is created above.
8983
# noinspection PyUnresolvedReferences
90-
import users.views
84+
import users.views # noqa
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,24 @@ SQLITE_DB_PATH = os.path.abspath(
2323
)
2424
)
2525

26-
# MAIL SERVER
27-
MAIL_CONFIG = dict(
28-
MAIL_SERVER='smtp.gmail.com',
29-
MAIL_PORT=587,
30-
MAIL_USE_TLS=True,
31-
MAIL_USE_SSL=False,
32-
MAIL_USERNAME='',
33-
MAIL_PASSWORD='',
34-
MAIL_SUPPRESS_SEND=False,
35-
)
26+
# Alternatively, set to ``127.0.0.1`` for development/testing.
27+
MAIL_SERVER = 'smtp.gmail.com'
28+
29+
# Alternatively, set to ``25`` for development/testing.
30+
MAIL_PORT = 587
31+
32+
MAIL_USE_TLS = True
33+
MAIL_USE_SSL = False
34+
MAIL_USERNAME = ''
35+
MAIL_PASSWORD = ''
36+
37+
# Set the value to ``True`` to suppress email sending.
38+
# Useful for testing/development where machine doesn't have
39+
# mail server installed in it.
40+
MAIL_SUPPRESS_SEND = False
3641

3742
# MAIL ADMINISTRATOR
38-
MAIL_ADMIN = ('InaSAFE User Map Administrator', MAIL_CONFIG['MAIL_USERNAME'])
43+
MAIL_ADMIN = ('Python Indonesia User Map Administrator', MAIL_USERNAME)
3944

4045
# USER ICONS: All icon paths that are used.
4146
USER_ICONS = dict(

users/config.py.test

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)