File tree Expand file tree Collapse file tree 15 files changed +265
-56
lines changed Expand file tree Collapse file tree 15 files changed +265
-56
lines changed Original file line number Diff line number Diff line change 1+ .PHONY :
2+ clean system-packages python-packages install tests run all
3+
4+ clean :
5+ find . -type f -name ' *.pyc' -delete
6+ find . -type d -name ' *pycache*' -delete
7+ find . -type f -name ' *.log' -delete
8+
9+ system-packages :
10+ sudo apt install python-pip -y
11+
12+ python-packages :
13+ pip install -r requirements.txt
14+
15+ install :
16+ system-packages python-packages
17+
18+ tests :
19+ python manage.py test
20+
21+ run :
22+ python manage.py run
23+
24+ all :
25+ clean install tests run
26+
27+ dbinit :
28+ python manage.py db init
29+
30+ migrate :
31+ python manage.py db migrate
32+ python manage.py db upgrade
Original file line number Diff line number Diff line change 1+ """ The folder to include all the unnittests according to requirement """
Original file line number Diff line number Diff line change 1- from flask import Flask
1+ """ Creation of Flask object along with configuration based on environment name specified in the settings file"""
2+ import logging
3+ from datetime import datetime as dt
4+ from flask import Flask , request
25from flask_sqlalchemy import SQLAlchemy
36from flask_bcrypt import Bcrypt
47
58from .settings import config_by_name
9+ from app .main .utils .LogSetup import LogSetup
610
11+ logs = LogSetup ()
712db = SQLAlchemy ()
813flask_bcrypt = Bcrypt ()
914
1015
1116def create_app (config_name ):
17+ """
18+ creates the Flask object
19+
20+ Args:
21+ config_name (str): string to define the environment settings the Flask object will be configured with
22+
23+ Returns:
24+ object: Flask object configured with the configuration parameters from settings based on the environment name specified
25+ """
1226 app = Flask (__name__ )
1327 app .config .from_object (config_by_name [config_name ])
1428 db .init_app (app )
29+ logs .init_app (app )
1530 flask_bcrypt .init_app (app )
1631
32+
33+ @app .after_request
34+ def after_request (response ):
35+ """ Logging after every request. """
36+ logger = logging .getLogger ("app.access" )
37+ logger .info (
38+ "%s [%s] %s %s %s %s %s %s %s" ,
39+ request .remote_addr ,
40+ dt .utcnow ().strftime ("%d/%b/%Y:%H:%M:%S.%f" )[:- 3 ],
41+ request .method ,
42+ request .path ,
43+ request .scheme ,
44+ response .status ,
45+ response .content_length ,
46+ request .referrer ,
47+ request .user_agent ,
48+ )
49+ return response
50+
51+
1752 return app
Original file line number Diff line number Diff line change 1- from app .main .models .todo import Todo
2- from app .main .models .deleted_todos import RemovedTodo
1+ """ import all the models in the folder here"""
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- from .blueprint_todo import todo
1+ # import resprctive blueprints and flask REstful resources
2+ from .blueprint_test import bp
23
4+ def add_resources (app ):
5+ """
6+ Method to add resources to app context
7+
8+ Args:
9+ app (object): object of Flask representing the app in context
10+ """
11+ pass
312
413def register_blueprints (app ):
5- app .register_blueprint (todo , url_prefix = "/todo" )
14+ """
15+ Method to add blueprints to app context
16+
17+ Args:
18+ app (object): object of Flask representing the app in context
19+ """
20+ app .register_blueprint (bp )
Original file line number Diff line number Diff line change 1+ from flask import Blueprint , current_app
2+
3+ bp = Blueprint ("public" , __name__ )
4+
5+ @bp .route ("/" )
6+ def hello_world ():
7+ current_app .logger .info ("Here I am" )
8+ current_app .logger .warning (" Warning you" )
9+ current_app .logger .error ("But you can't hear me" )
10+
11+ return "hello hello_world"
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ """ Add the services in the folder and import them based on requirement """
You can’t perform that action at this time.
0 commit comments