-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from greyli/sqla2
Use type annotated model class
- Loading branch information
Showing
6 changed files
with
101 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,8 @@ | |
import sys | ||
from pathlib import Path | ||
|
||
basedir = Path(__file__).resolve().parent.parent | ||
|
||
# SQLite URI compatible | ||
prefix = 'sqlite:///' if sys.platform.startswith('win') else 'sqlite:////' | ||
BASE_DIR = Path(__file__).resolve().parent.parent | ||
SQLITE_PREFIX = 'sqlite:///' if sys.platform.startswith('win') else 'sqlite:////' | ||
|
||
|
||
class BaseConfig: | ||
|
@@ -26,22 +24,22 @@ class BaseConfig: | |
MAIL_PASSWORD = os.getenv('MAIL_PASSWORD') | ||
MAIL_DEFAULT_SENDER = f'Greybook <{MAIL_USERNAME}>' | ||
|
||
GREYBOOK_ADMIN_EMAIL = os.getenv('GREYBOOK_ADMIN_EMAIL') | ||
GREYBOOK_ADMIN_EMAIL = os.getenv('GREYBOOK_ADMIN_EMAIL', '[email protected]') | ||
GREYBOOK_POST_PER_PAGE = 10 | ||
GREYBOOK_MANAGE_POST_PER_PAGE = 15 | ||
GREYBOOK_COMMENT_PER_PAGE = 15 | ||
# ('theme name', 'display name') | ||
GREYBOOK_THEMES = {'default': 'Default', 'perfect_blue': 'Perfect Blue'} | ||
GREYBOOK_SLOW_QUERY_THRESHOLD = 1 | ||
|
||
GREYBOOK_UPLOAD_PATH = os.getenv('GREYBOOK_UPLOAD_PATH', basedir / 'uploads') | ||
GREYBOOK_UPLOAD_PATH = os.getenv('GREYBOOK_UPLOAD_PATH', BASE_DIR / 'uploads') | ||
GREYBOOK_ALLOWED_IMAGE_EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif'] | ||
GREYBOOK_LOGGING_PATH = os.getenv('GREYBOOK_LOGGING_PATH', basedir / 'logs/greybook.log') | ||
GREYBOOK_LOGGING_PATH = os.getenv('GREYBOOK_LOGGING_PATH', BASE_DIR / 'logs/greybook.log') | ||
GREYBOOK_ERROR_EMAIL_SUBJECT = '[Greybook] Application Error' | ||
|
||
|
||
class DevelopmentConfig(BaseConfig): | ||
SQLALCHEMY_DATABASE_URI = prefix + str(basedir / 'data-dev.db') | ||
SQLALCHEMY_DATABASE_URI = SQLITE_PREFIX + str(BASE_DIR / 'data-dev.db') | ||
|
||
|
||
class TestingConfig(BaseConfig): | ||
|
@@ -51,7 +49,7 @@ class TestingConfig(BaseConfig): | |
|
||
|
||
class ProductionConfig(BaseConfig): | ||
SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URL', prefix + str(basedir / 'data.db')) | ||
SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URL', SQLITE_PREFIX + str(BASE_DIR / 'data.db')) | ||
|
||
|
||
config = {'development': DevelopmentConfig, 'testing': TestingConfig, 'production': ProductionConfig} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,9 @@ def setUp(self): | |
) | ||
category = Category(name='Test Category') | ||
post = Post(title='Test Post Title', category=category, body='Test post body') | ||
comment = Comment(body='Test comment body', post=post, reviewed=True) | ||
comment = Comment( | ||
author='Test comment author', email='[email protected]', body='Test comment body', post=post, reviewed=True | ||
) | ||
link = Link(name='Test Link', url='http://example.com') | ||
db.session.add_all([user, category, post, comment, link]) | ||
db.session.commit() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters