-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLibraries_Documentation.txt
101 lines (75 loc) · 3.62 KB
/
Libraries_Documentation.txt
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
THIS DOCUMENTATION CONTAINS ALL THE LIBRARIES AND METHODS USED IN THIS REPOSITORY
⁃ Classes always start with a uppercase.
⁃ Packages always start with a lowercase.
⁃ Model is an internal representation of an entity.
⁃ Resource is an external representation of an entity to which client interacts.
⁃ Model is an helper that gives us more flexibility without polluting the Resources.
⁃ Fresh Token which we receive after entering username and password.
⁃ Non Fresh Token which we receive by refreshing a previous token.
⁃ @jwt_required ;will work for both access_token and refresh_token, either of those will work
⁃ @fresh_jwt_required ;needs fresh jwt if access_token comes through this post is not fresh ;when recent logged required
⁃ @jwt_refresh_token_required ;will issue a new refresh_token
⁃ @jwt.invalid_token_loader ;When token sent us is not an actual JWT
⁃ @jwt.unauthorized_loader ;When request doesn't sends jwt, so not authorized
⁃ @jwt.needs_fresh_token_loader ;When our end point requires a fresh token but the req contains not_fresh_token
⁃ @jwt.revoked_token_loader ;When user logged out so put that token in revoked tokens list
⁃ # INSTANCE METHOD
item = Item()
item.get()
⁃ # CLASS METHOD(Better) & STATIC METHOD
Item.get() ; No diff when called, only diff is class method passes 'class' as an arg i.e. def get(cls, name):
⁃ MARSHMALLOW
⁃ Serialization ;Takes an obj and passes obj properties to Schema and gives a dict, when do a 'dump'
⁃ Deserialization ;Takes a dict and converts it into obj
⁃ # FLASK MARSHMALLOW
Added lib and give 'model = UserModel' to create and instead of giving json back it looks into the column def and
validates against them and if all passes it gives back a user model instead of a dict
⁃ confirmation = db.relationship(
"ConfirmationModel", lazy="dynamic", cascade="all, delete-orphan"
)
# user = UserModel()
# confirmation = ConfirmationModel()
# confirmation.save_to_db()
# print(user.confirmation) ; if lazy=dynamic otherwise it will say 'None'
⁃ USE DEFAULT LOCALIZATION
from libs import strings
strings.gettext("mailgun_failed_load_api_key")
⁃ CHANGE DEFAULT LOCALIZATION
strings.default_locale = 'es-es'
strings.refresh()
strings.gettext("mailgun_failed_load_api_key") OR USE SETTER FUNC IN LIB TO CHANGE LOCALE
-------------------------------------------------------------------------------------------------------------------------------------
• TO USE FLASK INTO APP
from flask import Flask
app = Flask(__name__)
• TO CONVERT DICTIONARY TO JSON
from flask import jsonify
jsonify(dict)
• TO LET BROWSER ACCESS THE DATA
from flask import request
request_data = request.get_json()
• TO RENDER HTML CODE FROM ‘TEMPLATES’ FOLDER INTO FLASK APP
from flask import render_template
render_template(‘index.html’)
• TO USE FLASK RESTFUL INTO APP
from flask_restful import Resource, Api
api = Api(app)
• TO COMPARE STRINGS SAFELY
from werkzeug.security import safe_str_cmp
safe_str_cmp(str1, str2)
• TO SETUP JWT INTO APP
from flask_jwt import JWT
from security import authenticate, identity
jwt = JWT(app, authenticate, identity)
• TO PARSE THE REQUEST
from flask_restful import Resource
parser = reqparse.RequestParser()
• TO ENABLE JWT DECORATOR
from flask_jwt import jwt_required
@jwt_required()
• TO ENABLE SQLITE
import sqlite3
connection = sqlite3.connect('data.db')
• TO USE FLASK_JWT_EXTENDED INTO APP
from flask_jwt_extended import JWTManager
jwt = JWTManager(app)