config
Configuration files for the app. We will put all of the config settings into and Enum class for easier reference.
- Configuration Files
- app_config.py
- document_style.py
- flask_app.py
app_config.py
1 2 3 4 5 6 7 8 9 10 |
# /config / app_config.py # system library -------------------------------------------------------------- from enum import Enum class AppConfig(Enum): # version VERSION = "1.1.0" DATABASE = 'database/word_file_app.sqlite' |
Import the standard Enum class
VERSION is just for reference, value is not that key.
DATABASE is the relative location from the base directory, it should be a subdirectory inside of the app folders.
document_style.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# /config / document_style.py # system library -------------------------------------------------------------- from enum import Enum class DocumentStyle(Enum): # DOCUMENT TEMPLATE_NAME = 'word_documents/cl_template.docx' OUTPUT_DIRECTORY_WORD = 'download' OUTPUT_DIRECTORY_PDF = 'download' OUTPUT_FILE_NAME = '_FileName_' OUTPUT_FILE_PREFIX = 'output_prefix' OUTPUT_FILE_USE_PLACEHOLDER_VALUE = True OUTPUT_FILE_PLACEHOLDER_TO_USE = 'Company Name' # DATE FORMAT DATE_FORMAT = '%d %B %Y' FILENAME_DATE_FORMAT = '%Y-%m-%d' # PAGE LAYOUT PAGE_MARGIN_TOP = 0.75 PAGE_MARGIN_BOTTOM = 0.50 PAGE_MARGIN_LEFT = 0.75 PAGE_MARGIN_RIGHT = 0.75 # PARAGRAPH LAYOUT PARAGRAPH_FONT_NAME = 'Times New Roman' PARAGRAPH_FONT_POINT = 12 # PARAGRAPH BULLET BULLET_FONT_NAME = 'Times New Roman' BULLET_FONT_POINT = 12 BULLET_STYLE = 'List Bullet 2' BULLET_CHARACTER = '-' # PARAGRAPH CL_P_BREAK = "\n" |
The following are the document options when creating the Microsoft Word document.
Most of the options are self explanatory. And for most part, the default values in this file should work.
The only ones that might need adjustment are
OUTPUT_FILE_USE_PLACEHOLDER_VALUE: True
OUTPUT_FILE_PLACEHOLDER_TO_USE: ‘Valid_Placeholder_Name’
If generating the Microsoft Word file to download you want to automatically put the value from one of the defined placeholders in the template file, you can set the OUTPUT_FILE_USE_PLACEHOLDER_VALUE can set the value to True, and in the OUTPUT_FILE_PLACEHOLDER_TO_USE set the value to a placeholder in the document.
When working with DATE_FORMAT and FILENAME_DATE_FORMAT configuration, you can reference, the appropriate codes here. Python String Format Codes
flask_app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# /config / flask_app.py # system library -------------------------------------------------------------- from enum import Enum class FlaskOptions(Enum): # Used to connect to sqlite3 database SESSION_TYPE = "sqlalchemy" SESSION_SQLALCHEMY_TABLE = 'sessions' #port to run flask on API_PORT_DEBUG ="7000" API_PORT_TEST = "7001" API_PORT_PROD = "7002" |
Here are the configuration settings that are passed to the flask application. The key one is to define how we will store the SESSION variable information. Using sqlalchemy and table name of sessions, seems to be the most common way of doing it. Since the app is running locally, I wouldn’t be overly concerned about the settings here.
I set up debug, test, prod port numbers, most likely you would only run the app on the PROD port number.
Leave a Reply