' % self.id
30 |
--------------------------------------------------------------------------------
/Module 2/Chapter07/my_app/static/css/main.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding-top: 50px;
3 | }
4 | .top-pad {
5 | padding: 40px 15px;
6 | text-align: center;
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/Module 2/Chapter07/my_app/templates/404.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 |
Hola Friend! Looks like in your quest you have reached a location which does not exist yet.
6 |
To continue, either check your map location (URL) or go back home
7 |
8 | {% endblock %}
9 |
--------------------------------------------------------------------------------
/Module 2/Chapter07/my_app/templates/categories.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
11 | {% endblock %}
12 |
--------------------------------------------------------------------------------
/Module 2/Chapter07/my_app/templates/category.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 |
{{ category.name }}
6 |
7 | {% for product in category.products %}
8 |
12 | {% endfor %}
13 |
14 |
15 | {% endblock %}
16 |
--------------------------------------------------------------------------------
/Module 2/Chapter07/my_app/templates/home.html:
--------------------------------------------------------------------------------
1 | {% extends 'base.html' %}
2 |
3 | {% block container %}
4 | Welcome to the Catalog Home
5 |
6 | Click here to see the catalog
7 |
8 | {% endblock %}
9 |
10 | {% block scripts %}
11 |
18 | {% endblock %}
19 |
--------------------------------------------------------------------------------
/Module 2/Chapter07/my_app/templates/product-create.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
31 | {% endblock %}
32 |
33 |
--------------------------------------------------------------------------------
/Module 2/Chapter07/my_app/templates/product.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 |
{{ product.name }} {{ product.category.name }}
6 | {{ product.company }}
7 | {{ product.price }}
8 |
9 | {% endblock %}
10 |
--------------------------------------------------------------------------------
/Module 2/Chapter07/my_app/templates/products.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 | {% for product in products.items %}
6 |
12 | {% endfor %}
13 | {% if products.has_prev %}
14 |
15 | {{"<< Previous Page"}}
16 |
17 | {% else %}
18 | {{"<< Previous Page"}}
19 | {% endif %} |
20 | {% if products.has_next %}
21 |
22 | {{"Next page >>"}}
23 |
24 | {% else %}
25 | {{"Next page >>"}}
26 | {% endif %}
27 |
28 | {% endblock %}
29 |
--------------------------------------------------------------------------------
/Module 2/Chapter07/run.py:
--------------------------------------------------------------------------------
1 | from my_app import app
2 | app.run(debug=True)
3 |
--------------------------------------------------------------------------------
/Module 2/Chapter08/my_app/__init__.py:
--------------------------------------------------------------------------------
1 | from flask import Flask
2 | from flask.ext.sqlalchemy import SQLAlchemy
3 | from flask.ext.login import LoginManager
4 | from flask.ext.admin import Admin
5 |
6 |
7 | app = Flask(__name__)
8 | app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
9 | app.config['WTF_CSRF_SECRET_KEY'] = 'random key for form'
10 | db = SQLAlchemy(app)
11 |
12 | app.secret_key = 'some_random_key'
13 |
14 | login_manager = LoginManager()
15 | login_manager.init_app(app)
16 | login_manager.login_view = 'auth.login'
17 |
18 | import my_app.auth.views as views
19 | admin = Admin(app, index_view=views.MyAdminIndexView())
20 | admin.add_view(views.HelloView(name='Hello'))
21 | admin.add_view(views.UserAdminView(views.User, db.session))
22 |
23 | from my_app.auth.views import auth
24 | app.register_blueprint(auth)
25 |
26 | db.create_all()
27 |
--------------------------------------------------------------------------------
/Module 2/Chapter08/my_app/auth/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter08/my_app/auth/__init__.py
--------------------------------------------------------------------------------
/Module 2/Chapter08/my_app/static/css/main.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding-top: 50px;
3 | }
4 | .top-pad {
5 | padding: 40px 15px;
6 | text-align: center;
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/Module 2/Chapter08/my_app/templates/admin-home.html:
--------------------------------------------------------------------------------
1 | {% extends 'base.html' %}
2 |
3 | {% block container %}
4 | Welcome to the Admin Demo
5 | Hey {{ current_user.username }}!!
6 | List of all users
7 |
8 | Create a new user
9 |
10 | Click here to logout
11 | {% endblock %}
12 |
--------------------------------------------------------------------------------
/Module 2/Chapter08/my_app/templates/edit.html:
--------------------------------------------------------------------------------
1 | {% extends 'admin/model/edit.html' %}
2 |
3 | {% block tail %}
4 | {{ super() }}
5 |
6 | {% endblock %}
7 |
--------------------------------------------------------------------------------
/Module 2/Chapter08/my_app/templates/home.html:
--------------------------------------------------------------------------------
1 | {% extends 'base.html' %}
2 |
3 | {% block container %}
4 | Welcome to the Authentication Demo
5 | {% if current_user.is_authenticated() %}
6 | Hey {{ current_user.username }}!!
7 | Click here to logout
8 | {% else %}
9 | Click here to login or register
10 | {% endif %}
11 | {% endblock %}
12 |
--------------------------------------------------------------------------------
/Module 2/Chapter08/my_app/templates/login.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
15 | {% endblock %}
16 |
--------------------------------------------------------------------------------
/Module 2/Chapter08/my_app/templates/register.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
16 | {% endblock %}
17 |
--------------------------------------------------------------------------------
/Module 2/Chapter08/my_app/templates/some-template.html:
--------------------------------------------------------------------------------
1 | This is a template just for demonstration of Flask Admin Views.
2 |
--------------------------------------------------------------------------------
/Module 2/Chapter08/my_app/templates/user-create-admin.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
16 | {% endblock %}
17 |
--------------------------------------------------------------------------------
/Module 2/Chapter08/my_app/templates/user-update-admin.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
15 | {% endblock %}
16 |
17 |
--------------------------------------------------------------------------------
/Module 2/Chapter08/my_app/templates/users-list-admin.html:
--------------------------------------------------------------------------------
1 | {% extends 'admin-home.html' %}
2 |
3 | {% block container %}
4 | Hey {{ current_user.username }}!! Below is the list of users in system
5 |
6 |
7 |
8 |
9 | ID
10 | Username
11 | Is Admin ?
12 |
13 |
14 |
15 |
16 |
17 | {% for user in users %}
18 |
19 | {{ user.id }}
20 | {{ user.username }}
21 | {{ user.admin }}
22 |
23 | Edit
24 |
25 |
26 | Delete
27 |
28 |
29 | {% endfor %}
30 |
31 |
32 | {% endblock %}
33 |
--------------------------------------------------------------------------------
/Module 2/Chapter08/run.py:
--------------------------------------------------------------------------------
1 | from my_app import app
2 | app.run(debug=True)
3 |
--------------------------------------------------------------------------------
/Module 2/Chapter09/my_app/__init__.py:
--------------------------------------------------------------------------------
1 | import os
2 | from flask import Flask
3 | from flask.ext.sqlalchemy import SQLAlchemy
4 | from flask.ext.babel import Babel
5 |
6 |
7 | ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
8 |
9 | ALLOWED_LANGUAGES = {
10 | 'en': 'English',
11 | 'fr': 'French',
12 | }
13 |
14 | app = Flask(__name__)
15 | app.config['UPLOAD_FOLDER'] = os.path.realpath('.') + '/my_app/static/uploads'
16 | app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
17 | app.config['WTF_CSRF_SECRET_KEY'] = 'random key for form'
18 | db = SQLAlchemy(app)
19 |
20 |
21 | babel = Babel(app)
22 |
23 | app.secret_key = 'some_random_key'
24 |
25 | from my_app.catalog.views import catalog
26 | app.register_blueprint(catalog)
27 |
28 | db.create_all()
29 |
--------------------------------------------------------------------------------
/Module 2/Chapter09/my_app/babel.cfg:
--------------------------------------------------------------------------------
1 | [python: catalog/**.py]
2 | [jinja2: templates/**.html]
3 | extensions=jinja2.ext.autoescape,jinja2.ext.with_
4 |
--------------------------------------------------------------------------------
/Module 2/Chapter09/my_app/catalog/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter09/my_app/catalog/__init__.py
--------------------------------------------------------------------------------
/Module 2/Chapter09/my_app/static/css/main.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding-top: 50px;
3 | }
4 | .top-pad {
5 | padding: 40px 15px;
6 | text-align: center;
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/Module 2/Chapter09/my_app/static/uploads/apple-iphone-5-front.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter09/my_app/static/uploads/apple-iphone-5-front.jpg
--------------------------------------------------------------------------------
/Module 2/Chapter09/my_app/templates/404.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 |
Hola Friend! Looks like in your quest you have reached a location which does not exist yet.
6 |
To continue, either check your map location (URL) or go back home
7 |
8 | {% endblock %}
9 |
--------------------------------------------------------------------------------
/Module 2/Chapter09/my_app/templates/categories.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
11 | {% endblock %}
12 |
--------------------------------------------------------------------------------
/Module 2/Chapter09/my_app/templates/category-create.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
11 | {% endblock %}
12 |
--------------------------------------------------------------------------------
/Module 2/Chapter09/my_app/templates/category.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 |
{{ category.name }}
6 |
7 | {% for product in category.products %}
8 |
12 | {% endfor %}
13 |
14 |
15 | {% endblock %}
16 |
--------------------------------------------------------------------------------
/Module 2/Chapter09/my_app/templates/home.html:
--------------------------------------------------------------------------------
1 | {% extends 'base.html' %}
2 |
3 | {% block container %}
4 | {{ _('Welcome to the Catalog Home') }}
5 |
6 | {{ _('Click here to see the catalog ') }}
7 |
8 | {% endblock %}
9 |
10 | {% block scripts %}
11 |
18 | {% endblock %}
19 |
--------------------------------------------------------------------------------
/Module 2/Chapter09/my_app/templates/product-create.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
17 | {% endblock %}
18 |
--------------------------------------------------------------------------------
/Module 2/Chapter09/my_app/templates/product.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 |
6 |
{{ product.name }} {{ product.category.name }}
7 |
{{ product.price }}
8 |
9 | {% endblock %}
10 |
--------------------------------------------------------------------------------
/Module 2/Chapter09/my_app/templates/products.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 | {% for product in products.items %}
6 |
12 | {% endfor %}
13 | {% if products.has_prev %}
14 |
15 | {{_("<< Previous Page")}}
16 |
17 | {% else %}
18 | {{_("No Previous Page")}}
19 | {% endif %}
20 | {{ ngettext('%(num)d page', '%(num)d pages', products.pages) }} |
21 | {% if products.has_next %}
22 |
23 | {{_("Next page >>")}}
24 |
25 | {% else %}
26 | {{_("No Next page")}}
27 | {% endif %}
28 |
29 | {% endblock %}
30 |
--------------------------------------------------------------------------------
/Module 2/Chapter09/my_app/translations/fr/LC_MESSAGES/messages.mo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter09/my_app/translations/fr/LC_MESSAGES/messages.mo
--------------------------------------------------------------------------------
/Module 2/Chapter09/run.py:
--------------------------------------------------------------------------------
1 | from my_app import app
2 | app.run(debug=True)
3 |
--------------------------------------------------------------------------------
/Module 2/Chapter10/coverage/keybd_closed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter10/coverage/keybd_closed.png
--------------------------------------------------------------------------------
/Module 2/Chapter10/coverage/keybd_open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter10/coverage/keybd_open.png
--------------------------------------------------------------------------------
/Module 2/Chapter10/generate_profile.py:
--------------------------------------------------------------------------------
1 | from werkzeug.contrib.profiler import ProfilerMiddleware
2 | from my_app import app
3 |
4 | app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions = [10])
5 | app.run(debug=True)
6 |
--------------------------------------------------------------------------------
/Module 2/Chapter10/htmlcov/keybd_closed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter10/htmlcov/keybd_closed.png
--------------------------------------------------------------------------------
/Module 2/Chapter10/htmlcov/keybd_open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter10/htmlcov/keybd_open.png
--------------------------------------------------------------------------------
/Module 2/Chapter10/my_app/babel.cfg:
--------------------------------------------------------------------------------
1 | [python: catalog/**.py]
2 | [jinja2: templates/**.html]
3 | extensions=jinja2.ext.autoescape,jinja2.ext.with_
4 |
--------------------------------------------------------------------------------
/Module 2/Chapter10/my_app/catalog/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter10/my_app/catalog/__init__.py
--------------------------------------------------------------------------------
/Module 2/Chapter10/my_app/static/css/main.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding-top: 50px;
3 | }
4 | .top-pad {
5 | padding: 40px 15px;
6 | text-align: center;
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/Module 2/Chapter10/my_app/static/uploads/apple-iphone-5-front.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter10/my_app/static/uploads/apple-iphone-5-front.jpg
--------------------------------------------------------------------------------
/Module 2/Chapter10/my_app/templates/404.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 |
Hola Friend! Looks like in your quest you have reached a location which does not exist yet.
6 |
To continue, either check your map location (URL) or go back home
7 |
8 | {% endblock %}
9 |
--------------------------------------------------------------------------------
/Module 2/Chapter10/my_app/templates/categories.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
11 | {% endblock %}
12 |
--------------------------------------------------------------------------------
/Module 2/Chapter10/my_app/templates/category-create.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
11 | {% endblock %}
12 |
--------------------------------------------------------------------------------
/Module 2/Chapter10/my_app/templates/category.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 |
{{ category.name }}
6 |
7 | {% for product in category.products %}
8 |
12 | {% endfor %}
13 |
14 |
15 | {% endblock %}
16 |
--------------------------------------------------------------------------------
/Module 2/Chapter10/my_app/templates/home.html:
--------------------------------------------------------------------------------
1 | {% extends 'base.html' %}
2 |
3 | {% block container %}
4 | {{ _('Welcome to the Catalog Home') }}
5 |
6 | {{ _('Click here to see the catalog ') }}
7 |
8 | {% endblock %}
9 |
10 | {% block scripts %}
11 |
18 | {% endblock %}
19 |
--------------------------------------------------------------------------------
/Module 2/Chapter10/my_app/templates/product-create.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
17 | {% endblock %}
18 |
--------------------------------------------------------------------------------
/Module 2/Chapter10/my_app/templates/product.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 |
6 |
{{ product.name }} {{ product.category.name }}
7 |
{{ product.price }}
8 |
{{ product.user_timezone }}
9 |
10 | {% endblock %}
11 |
--------------------------------------------------------------------------------
/Module 2/Chapter10/my_app/templates/products.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 | {% for product in products.items %}
6 |
12 | {% endfor %}
13 | {% if products.has_prev %}
14 |
15 | {{_("<< Previous Page")}}
16 |
17 | {% else %}
18 | {{_("No Previous Page")}}
19 | {% endif %}
20 | {{ ngettext('%(num)d page', '%(num)d pages', products.pages) }} |
21 | {% if products.has_next %}
22 |
23 | {{_("Next Page >>")}}
24 |
25 | {% else %}
26 | {{_("No Next Page")}}
27 | {% endif %}
28 |
29 | {% endblock %}
30 |
--------------------------------------------------------------------------------
/Module 2/Chapter10/my_app/translations/fr/LC_MESSAGES/messages.mo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter10/my_app/translations/fr/LC_MESSAGES/messages.mo
--------------------------------------------------------------------------------
/Module 2/Chapter10/run.py:
--------------------------------------------------------------------------------
1 | from my_app import app
2 | app.run(debug=True)
3 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/MANIFEST.in:
--------------------------------------------------------------------------------
1 | recursive-include my_app/templates *
2 | recursive-include my_app/static *
3 | recursive-include my_app/translations *
4 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/Procfile:
--------------------------------------------------------------------------------
1 | web: gunicorn -w 4 my_app:app --debug --log-level debug
2 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/apache_wsgi.conf:
--------------------------------------------------------------------------------
1 |
2 |
3 | WSGIScriptAlias / /Users/shalabhaggarwal/workspace/mydev/flask_catalog_deployment/app.wsgi
4 |
5 |
6 | Order allow,deny
7 | Allow from all
8 |
9 |
10 | Alias /static/uploads/ "/Users/shalabhaggarwal/workspace/mydev/flask_test_uploads/"
11 |
12 | Order allow,deny
13 | Options Indexes
14 | Allow from all
15 | IndexOptions FancyIndexing
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/app.wsgi:
--------------------------------------------------------------------------------
1 | activate_this = '/Users/shalabhaggarwal/workspace/mydev/bin/activate_this.py'
2 | execfile(activate_this, dict(__file__=activate_this))
3 |
4 | from my_app import app as application
5 | import sys, logging
6 | logging.basicConfig(stream = sys.stderr)
7 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/application.py:
--------------------------------------------------------------------------------
1 | from my_app import app as application
2 | import sys, logging
3 | logging.basicConfig(stream = sys.stderr)
4 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/coverage/keybd_closed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter11/coverage/keybd_closed.png
--------------------------------------------------------------------------------
/Module 2/Chapter11/coverage/keybd_open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter11/coverage/keybd_open.png
--------------------------------------------------------------------------------
/Module 2/Chapter11/fabfile.py:
--------------------------------------------------------------------------------
1 | from fabric.api import sudo, cd, prefix, run, settings
2 |
3 | def deploy_app():
4 | "Deploy to the server specified"
5 | root_path = '/usr/local/my_env'
6 |
7 | with cd(root_path):
8 | with prefix("source %s/bin/activate" % root_path):
9 | with cd('flask_catalog_deployment'):
10 | run('git pull')
11 | run('python setup.py install')
12 |
13 | sudo('bin/supervisorctl restart all')
14 |
15 | def deploy_app_to_server():
16 | "Deploy to the server hardcoded"
17 | with settings(host_string='my.remote.server'):
18 | deploy_app()
19 |
20 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/generate_profile.py:
--------------------------------------------------------------------------------
1 | from werkzeug.contrib.profiler import ProfilerMiddleware
2 | from my_app import app
3 |
4 | app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions = [10])
5 | app.run(debug=True)
6 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/htmlcov/keybd_closed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter11/htmlcov/keybd_closed.png
--------------------------------------------------------------------------------
/Module 2/Chapter11/htmlcov/keybd_open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter11/htmlcov/keybd_open.png
--------------------------------------------------------------------------------
/Module 2/Chapter11/my_app/babel.cfg:
--------------------------------------------------------------------------------
1 | [python: catalog/**.py]
2 | [jinja2: templates/**.html]
3 | extensions=jinja2.ext.autoescape,jinja2.ext.with_
4 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/my_app/catalog/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter11/my_app/catalog/__init__.py
--------------------------------------------------------------------------------
/Module 2/Chapter11/my_app/static/css/main.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding-top: 50px;
3 | }
4 | .top-pad {
5 | padding: 40px 15px;
6 | text-align: center;
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/my_app/static/uploads/apple-iphone-5-front.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter11/my_app/static/uploads/apple-iphone-5-front.jpg
--------------------------------------------------------------------------------
/Module 2/Chapter11/my_app/templates/404.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 |
Hola Friend! Looks like in your quest you have reached a location which does not exist yet.
6 |
To continue, either check your map location (URL) or go back home
7 |
8 | {% endblock %}
9 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/my_app/templates/categories.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
11 | {% endblock %}
12 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/my_app/templates/category-create.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
11 | {% endblock %}
12 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/my_app/templates/category.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 |
{{ category.name }}
6 |
7 | {% for product in category.products %}
8 |
12 | {% endfor %}
13 |
14 |
15 | {% endblock %}
16 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/my_app/templates/home.html:
--------------------------------------------------------------------------------
1 | {% extends 'base.html' %}
2 |
3 | {% block container %}
4 | {{ _('Welcome to the Catalog Home') }}
5 |
6 | {{ _('Click here to see the catalog ') }}
7 |
8 | {% endblock %}
9 |
10 | {% block scripts %}
11 |
18 | {% endblock %}
19 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/my_app/templates/product-create.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
17 | {% endblock %}
18 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/my_app/templates/product.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 |
6 |
{{ product.name }} {{ product.category.name }}
7 |
{{ product.price }}
8 |
{{ product.user_timezone }}
9 |
10 | {% endblock %}
11 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/my_app/templates/products.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 | {% for product in products.items %}
6 |
12 | {% endfor %}
13 | {% if products.has_prev %}
14 |
15 | {{_("<< Previous Page")}}
16 |
17 | {% else %}
18 | {{_("No Previous Page")}}
19 | {% endif %}
20 | {{ ngettext('%(num)d page', '%(num)d pages', products.pages) }} |
21 | {% if products.has_next %}
22 |
23 | {{_("Next Page >>")}}
24 |
25 | {% else %}
26 | {{_("No Next Page")}}
27 | {% endif %}
28 |
29 | {% endblock %}
30 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/my_app/translations/fr/LC_MESSAGES/messages.mo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter11/my_app/translations/fr/LC_MESSAGES/messages.mo
--------------------------------------------------------------------------------
/Module 2/Chapter11/nginx-wsgi.conf:
--------------------------------------------------------------------------------
1 | location / {
2 | include uwsgi_params;
3 | uwsgi_pass 127.0.0.1:9090;
4 | }
5 | location /static/uploads/ {
6 | alias /Users/shalabhaggarwal/workspace/mydev/flask_test_uploads/;
7 | }
8 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/requirements.txt:
--------------------------------------------------------------------------------
1 | Flask==0.10.1
2 | Flask-Restless==0.14.0
3 | Flask-SQLAlchemy==1.0
4 | Flask-WTF==0.10.0
5 | Jinja2==2.7.3
6 | MarkupSafe==0.23
7 | SQLAlchemy==0.9.7
8 | WTForms==2.0.1
9 | Werkzeug==0.9.6
10 | boto==2.32.1
11 | gunicorn==19.1.1
12 | itsdangerous==0.24
13 | mimerender==0.5.4
14 | python-dateutil==2.2
15 | python-geoip==1.2
16 | python-geoip-geolite2==2014.0207
17 | python-mimeparse==0.1.4
18 | six==1.7.3
19 | wsgiref==0.1.2
20 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/run.py:
--------------------------------------------------------------------------------
1 | from my_app import app
2 | app.run(debug=True)
3 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: UTF-8 -*-
3 | import os
4 | from setuptools import setup
5 |
6 | setup(
7 | name = 'my_app',
8 | version='1.0',
9 | license='GNU General Public License v3',
10 | author='Shalabh Aggarwal',
11 | author_email='contact@shalabhaggarwal.com',
12 | description='Catalog application for Flask',
13 | packages=[
14 | 'my_app',
15 | 'my_app.catalog',
16 | ],
17 | platforms='any',
18 | install_requires=[
19 | 'flask',
20 | 'flask-sqlalchemy',
21 | 'flask-wtf'
22 | ],
23 | include_package_data=True,
24 | classifiers=[
25 | 'Development Status :: 4 - Beta',
26 | 'Environment :: Web Environment',
27 | 'Intended Audience :: Developers',
28 | 'License :: OSI Approved :: GNU General Public License v3',
29 | 'Operating System :: OS Independent',
30 | 'Programming Language :: Python',
31 | 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
32 | 'Topic :: Software Development :: Libraries :: Python Modules'
33 | ],
34 | zip_safe = False,
35 | )
36 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/tornado_server.py:
--------------------------------------------------------------------------------
1 | from tornado.wsgi import WSGIContainer
2 | from tornado.httpserver import HTTPServer
3 | from tornado.ioloop import IOLoop
4 | from my_app import app
5 |
6 | http_server = HTTPServer(WSGIContainer(app))
7 | http_server.listen(5000)
8 | IOLoop.instance().start()
9 |
--------------------------------------------------------------------------------
/Module 2/Chapter11/uwsgi.ini:
--------------------------------------------------------------------------------
1 | [uwsgi]
2 | socket = :9090
3 | plugin = python
4 | wsgi-file = /Users/shalabhaggarwal/workspace/mydev/flask_catalog_deployment/app.wsgi
5 | processes = 3
6 |
--------------------------------------------------------------------------------
/Module 2/Chapter12/my_app/catalog/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 2/Chapter12/my_app/catalog/__init__.py
--------------------------------------------------------------------------------
/Module 2/Chapter12/my_app/static/css/main.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding-top: 50px;
3 | }
4 | .top-pad {
5 | padding: 40px 15px;
6 | text-align: center;
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/Module 2/Chapter12/my_app/templates/404.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 |
Hola Friend! Looks like in your quest you have reached a location which does not exist yet.
6 |
To continue, either check your map location (URL) or go back home
7 |
8 | {% endblock %}
9 |
--------------------------------------------------------------------------------
/Module 2/Chapter12/my_app/templates/categories.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
11 | {% endblock %}
12 |
--------------------------------------------------------------------------------
/Module 2/Chapter12/my_app/templates/category-create-email-html.html:
--------------------------------------------------------------------------------
1 | A new category has been added to the catalog.
2 |
3 | The name of the category is
4 | {{ category.name }}
5 | .
6 |
7 |
8 | This is an automated email. Do not reply to it.
9 |
--------------------------------------------------------------------------------
/Module 2/Chapter12/my_app/templates/category-create-email-text.html:
--------------------------------------------------------------------------------
1 | A new category has been added to the catalog.
2 |
3 | The name of the category is {{ category.name }}.
4 | Click on the URL below to acces the same:
5 | {{ url_for('catalog.category', id=category.id, _external = True) }}
6 |
7 | This is an automated email. Do not reply to it.
8 |
--------------------------------------------------------------------------------
/Module 2/Chapter12/my_app/templates/category.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 |
{{ category.name }}
6 |
7 | {% for product in category.products %}
8 |
12 | {% endfor %}
13 |
14 |
15 | {% endblock %}
16 |
--------------------------------------------------------------------------------
/Module 2/Chapter12/my_app/templates/home.html:
--------------------------------------------------------------------------------
1 | {% extends 'base.html' %}
2 |
3 | {% block container %}
4 | Welcome to the Catalog Home
5 |
6 | Click here to see the catalog
7 |
8 | {% endblock %}
9 |
10 | {% block scripts %}
11 |
18 | {% endblock %}
19 |
--------------------------------------------------------------------------------
/Module 2/Chapter12/my_app/templates/product.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 |
{{ product.name }} {{ product.category.name }}
6 | {{ product.company }}
7 | {{ product.price }}
8 |
9 | {% endblock %}
10 |
--------------------------------------------------------------------------------
/Module 2/Chapter12/my_app/templates/products.html:
--------------------------------------------------------------------------------
1 | {% extends 'home.html' %}
2 |
3 | {% block container %}
4 |
5 | {% for product in products.items %}
6 |
12 | {% endfor %}
13 | {% if products.has_prev %}
14 |
15 | {{"<< Previous Page"}}
16 |
17 | {% else %}
18 | {{"<< Previous Page"}}
19 | {% endif %} |
20 | {% if products.has_next %}
21 |
22 | {{"Next page >>"}}
23 |
24 | {% else %}
25 | {{"Next page >>"}}
26 | {% endif %}
27 |
28 | {% endblock %}
29 |
--------------------------------------------------------------------------------
/Module 2/Chapter12/run.py:
--------------------------------------------------------------------------------
1 | from my_app import app
2 | app.run(debug=True)
3 |
--------------------------------------------------------------------------------
/Module 3/Chapter01/chapter_1/config.py:
--------------------------------------------------------------------------------
1 | class DevConfig(object):
2 | DEBUG = True
3 |
--------------------------------------------------------------------------------
/Module 3/Chapter01/chapter_1/main.py:
--------------------------------------------------------------------------------
1 | from flask import Flask
2 | from config import DevConfig
3 |
4 | app = Flask(__name__)
5 | app.config.from_object(DevConfig)
6 |
7 |
8 | @app.route('/')
9 | def home():
10 | return 'Hello World! '
11 |
12 | if __name__ == '__main__':
13 | app.run()
14 |
--------------------------------------------------------------------------------
/Module 3/Chapter01/chapter_1/manage.py:
--------------------------------------------------------------------------------
1 | from flask.ext.script import Manager, Server
2 | from main import app
3 |
4 | manager = Manager(app)
5 | manager.add_command("server", Server())
6 |
7 | @manager.shell
8 | def make_shell_context():
9 | return dict(app=app)
10 |
11 | if __name__ == "__main__":
12 | manager.run()
13 |
--------------------------------------------------------------------------------
/Module 3/Chapter02/chapter_2/config.py:
--------------------------------------------------------------------------------
1 | class DevConfig(object):
2 | DEBUG = True
3 | SQLALCHEMY_DATABASE_URI = 'sqlite:///database.db'
4 |
--------------------------------------------------------------------------------
/Module 3/Chapter02/chapter_2/manage.py:
--------------------------------------------------------------------------------
1 | from flask.ext.script import Manager, Server
2 | from flask.ext.migrate import Migrate, MigrateCommand
3 |
4 | from main import app, db, User, Post, Tag
5 |
6 | migrate = Migrate(app, db)
7 |
8 | manager = Manager(app)
9 | manager.add_command("server", Server())
10 | manager.add_command('db', MigrateCommand)
11 |
12 |
13 | @manager.shell
14 | def make_shell_context():
15 | return dict(app=app, db=db, User=User, Post=Post, Tag=Tag)
16 |
17 | if __name__ == "__main__":
18 | manager.run()
19 |
--------------------------------------------------------------------------------
/Module 3/Chapter02/chapter_2/migrations/README:
--------------------------------------------------------------------------------
1 | Generic single-database configuration.
--------------------------------------------------------------------------------
/Module 3/Chapter02/chapter_2/migrations/alembic.ini:
--------------------------------------------------------------------------------
1 | # A generic, single database configuration.
2 |
3 | [alembic]
4 | # template used to generate migration files
5 | # file_template = %%(rev)s_%%(slug)s
6 |
7 | # set to 'true' to run the environment during
8 | # the 'revision' command, regardless of autogenerate
9 | # revision_environment = false
10 |
11 |
12 | # Logging configuration
13 | [loggers]
14 | keys = root,sqlalchemy,alembic
15 |
16 | [handlers]
17 | keys = console
18 |
19 | [formatters]
20 | keys = generic
21 |
22 | [logger_root]
23 | level = WARN
24 | handlers = console
25 | qualname =
26 |
27 | [logger_sqlalchemy]
28 | level = WARN
29 | handlers =
30 | qualname = sqlalchemy.engine
31 |
32 | [logger_alembic]
33 | level = INFO
34 | handlers =
35 | qualname = alembic
36 |
37 | [handler_console]
38 | class = StreamHandler
39 | args = (sys.stderr,)
40 | level = NOTSET
41 | formatter = generic
42 |
43 | [formatter_generic]
44 | format = %(levelname)-5.5s [%(name)s] %(message)s
45 | datefmt = %H:%M:%S
46 |
--------------------------------------------------------------------------------
/Module 3/Chapter02/chapter_2/migrations/script.py.mako:
--------------------------------------------------------------------------------
1 | """${message}
2 |
3 | Revision ID: ${up_revision}
4 | Revises: ${down_revision}
5 | Create Date: ${create_date}
6 |
7 | """
8 |
9 | # revision identifiers, used by Alembic.
10 | revision = ${repr(up_revision)}
11 | down_revision = ${repr(down_revision)}
12 |
13 | from alembic import op
14 | import sqlalchemy as sa
15 | ${imports if imports else ""}
16 |
17 | def upgrade():
18 | ${upgrades if upgrades else "pass"}
19 |
20 |
21 | def downgrade():
22 | ${downgrades if downgrades else "pass"}
23 |
--------------------------------------------------------------------------------
/Module 3/Chapter03/chapter_3/config.py:
--------------------------------------------------------------------------------
1 | class Config(object):
2 | SECRET_KEY = '736670cb10a600b695a55839ca3a5aa54a7d7356cdef815d2ad6e19a2031182b'
3 |
4 |
5 | class ProdConfig(Config):
6 | SQLALCHEMY_DATABASE_URI = 'sqlite:///database.db'
7 |
8 |
9 | class DevConfig(Config):
10 | DEBUG = True
11 | SQLALCHEMY_DATABASE_URI = 'sqlite:///database.db'
12 |
--------------------------------------------------------------------------------
/Module 3/Chapter03/chapter_3/manage.py:
--------------------------------------------------------------------------------
1 | from flask.ext.script import Manager, Server
2 | from flask.ext.migrate import Migrate, MigrateCommand
3 |
4 | from main import app, db, User, Post, Tag, Comment
5 |
6 | migrate = Migrate(app, db)
7 |
8 | manager = Manager(app)
9 | manager.add_command("server", Server())
10 | manager.add_command('db', MigrateCommand)
11 |
12 |
13 | @manager.shell
14 | def make_shell_context():
15 | return dict(
16 | app=app,
17 | db=db,
18 | User=User,
19 | Post=Post,
20 | Tag=Tag,
21 | Comment=Comment
22 | )
23 |
24 | if __name__ == "__main__":
25 | manager.run()
26 |
--------------------------------------------------------------------------------
/Module 3/Chapter03/chapter_3/static/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter03/chapter_3/static/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/Module 3/Chapter03/chapter_3/static/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter03/chapter_3/static/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/Module 3/Chapter03/chapter_3/static/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter03/chapter_3/static/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/Module 3/Chapter03/chapter_3/static/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter03/chapter_3/static/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/Module 3/Chapter03/chapter_3/static/js/npm.js:
--------------------------------------------------------------------------------
1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
2 | require('../../js/transition.js')
3 | require('../../js/alert.js')
4 | require('../../js/button.js')
5 | require('../../js/carousel.js')
6 | require('../../js/collapse.js')
7 | require('../../js/dropdown.js')
8 | require('../../js/modal.js')
9 | require('../../js/tooltip.js')
10 | require('../../js/popover.js')
11 | require('../../js/scrollspy.js')
12 | require('../../js/tab.js')
13 | require('../../js/affix.js')
--------------------------------------------------------------------------------
/Module 3/Chapter04/chapter_4/config.py:
--------------------------------------------------------------------------------
1 | class Config(object):
2 | SECRET_KEY = '736670cb10a600b695a55839ca3a5aa54a7d7356cdef815d2ad6e19a2031182b'
3 |
4 |
5 | class ProdConfig(Config):
6 | SQLALCHEMY_DATABASE_URI = 'sqlite:///database.db'
7 |
8 |
9 | class DevConfig(Config):
10 | DEBUG = True
11 | SQLALCHEMY_DATABASE_URI = 'sqlite:///database.db'
12 |
--------------------------------------------------------------------------------
/Module 3/Chapter04/chapter_4/manage.py:
--------------------------------------------------------------------------------
1 | from flask.ext.script import Manager, Server
2 | from flask.ext.migrate import Migrate, MigrateCommand
3 |
4 | from main import app, db, User, Post, Tag, Comment
5 |
6 | migrate = Migrate(app, db)
7 |
8 | manager = Manager(app)
9 | manager.add_command("server", Server())
10 | manager.add_command('db', MigrateCommand)
11 |
12 |
13 | @manager.shell
14 | def make_shell_context():
15 | return dict(
16 | app=app,
17 | db=db,
18 | User=User,
19 | Post=Post,
20 | Tag=Tag,
21 | Comment=Comment
22 | )
23 |
24 | if __name__ == "__main__":
25 | manager.run()
26 |
--------------------------------------------------------------------------------
/Module 3/Chapter04/chapter_4/static/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter04/chapter_4/static/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/Module 3/Chapter04/chapter_4/static/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter04/chapter_4/static/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/Module 3/Chapter04/chapter_4/static/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter04/chapter_4/static/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/Module 3/Chapter04/chapter_4/static/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter04/chapter_4/static/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/Module 3/Chapter04/chapter_4/static/js/npm.js:
--------------------------------------------------------------------------------
1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
2 | require('../../js/transition.js')
3 | require('../../js/alert.js')
4 | require('../../js/button.js')
5 | require('../../js/carousel.js')
6 | require('../../js/collapse.js')
7 | require('../../js/dropdown.js')
8 | require('../../js/modal.js')
9 | require('../../js/tooltip.js')
10 | require('../../js/popover.js')
11 | require('../../js/scrollspy.js')
12 | require('../../js/tab.js')
13 | require('../../js/affix.js')
--------------------------------------------------------------------------------
/Module 3/Chapter05/chapter_5/manage.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | from flask.ext.script import Manager, Server
4 | from flask.ext.script.commands import ShowUrls
5 | from flask.ext.migrate import Migrate, MigrateCommand
6 |
7 | from webapp import create_app
8 | from webapp.models import db, User, Post, Tag, Comment
9 |
10 | # default to dev config
11 | env = os.environ.get('WEBAPP_ENV', 'dev')
12 | app = create_app('webapp.config.%sConfig' % env.capitalize())
13 |
14 | migrate = Migrate(app, db)
15 |
16 | manager = Manager(app)
17 | manager.add_command("server", Server())
18 | manager.add_command("show-urls", ShowUrls())
19 | manager.add_command('db', MigrateCommand)
20 |
21 |
22 | @manager.shell
23 | def make_shell_context():
24 | return dict(
25 | app=app,
26 | db=db,
27 | User=User,
28 | Post=Post,
29 | Tag=Tag,
30 | Comment=Comment
31 | )
32 |
33 | if __name__ == "__main__":
34 | manager.run()
35 |
--------------------------------------------------------------------------------
/Module 3/Chapter05/chapter_5/webapp/__init__.py:
--------------------------------------------------------------------------------
1 | from flask import Flask
2 |
3 | from models import db
4 | from controllers.main import main_blueprint
5 | from controllers.blog import blog_blueprint
6 |
7 |
8 | def create_app(object_name):
9 | """
10 | An flask application factory, as explained here:
11 | http://flask.pocoo.org/docs/patterns/appfactories/
12 |
13 | Arguments:
14 | object_name: the python path of the config object,
15 | e.g. project.config.ProdConfig
16 | """
17 |
18 | app = Flask(__name__)
19 | app.config.from_object(object_name)
20 |
21 | db.init_app(app)
22 |
23 | app.register_blueprint(main_blueprint)
24 | app.register_blueprint(blog_blueprint)
25 |
26 | return app
27 |
28 | if __name__ == '__main__':
29 | app = app = create_app('project.config.ProdConfig')
30 | app.run()
31 |
--------------------------------------------------------------------------------
/Module 3/Chapter05/chapter_5/webapp/config.py:
--------------------------------------------------------------------------------
1 | class Config(object):
2 | SECRET_KEY = '736670cb10a600b695a55839ca3a5aa54a7d7356cdef815d2ad6e19a2031182b'
3 |
4 |
5 | class ProdConfig(Config):
6 | SQLALCHEMY_DATABASE_URI = 'sqlite://../database.db'
7 |
8 |
9 | class DevConfig(Config):
10 | DEBUG = True
11 | SQLALCHEMY_DATABASE_URI = 'sqlite:///../database.db'
12 |
--------------------------------------------------------------------------------
/Module 3/Chapter05/chapter_5/webapp/controllers/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter05/chapter_5/webapp/controllers/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter05/chapter_5/webapp/controllers/main.py:
--------------------------------------------------------------------------------
1 | from flask import Blueprint, redirect, url_for
2 |
3 | main_blueprint = Blueprint(
4 | 'main',
5 | __name__,
6 | template_folder='../templates/main'
7 | )
8 |
9 |
10 | @main_blueprint.route('/')
11 | def index():
12 | return redirect(url_for('blog.home'))
13 |
--------------------------------------------------------------------------------
/Module 3/Chapter05/chapter_5/webapp/forms.py:
--------------------------------------------------------------------------------
1 | from flask_wtf import Form
2 | from wtforms import StringField, TextAreaField
3 | from wtforms.validators import DataRequired, Length
4 |
5 |
6 | class CommentForm(Form):
7 | name = StringField(
8 | 'Name',
9 | validators=[DataRequired(), Length(max=255)]
10 | )
11 | text = TextAreaField(u'Comment', validators=[DataRequired()])
12 |
--------------------------------------------------------------------------------
/Module 3/Chapter05/chapter_5/webapp/static/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter05/chapter_5/webapp/static/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/Module 3/Chapter05/chapter_5/webapp/static/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter05/chapter_5/webapp/static/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/Module 3/Chapter05/chapter_5/webapp/static/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter05/chapter_5/webapp/static/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/Module 3/Chapter05/chapter_5/webapp/static/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter05/chapter_5/webapp/static/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/Module 3/Chapter05/chapter_5/webapp/static/js/npm.js:
--------------------------------------------------------------------------------
1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
2 | require('../../js/transition.js')
3 | require('../../js/alert.js')
4 | require('../../js/button.js')
5 | require('../../js/carousel.js')
6 | require('../../js/collapse.js')
7 | require('../../js/dropdown.js')
8 | require('../../js/modal.js')
9 | require('../../js/tooltip.js')
10 | require('../../js/popover.js')
11 | require('../../js/scrollspy.js')
12 | require('../../js/tab.js')
13 | require('../../js/affix.js')
--------------------------------------------------------------------------------
/Module 3/Chapter06/Chapter 6/chapter_6/manage.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | from flask.ext.script import Manager, Server
4 | from flask.ext.migrate import Migrate, MigrateCommand
5 |
6 | from webapp import create_app
7 | from webapp.models import db, User, Post, Tag, Comment
8 |
9 | # default to dev config
10 | env = os.environ.get('WEBAPP_ENV', 'dev')
11 | app = create_app('webapp.config.%sConfig' % env.capitalize())
12 |
13 | migrate = Migrate(app, db)
14 |
15 | manager = Manager(app)
16 | manager.add_command("server", Server())
17 | manager.add_command('db', MigrateCommand)
18 |
19 |
20 | @manager.shell
21 | def make_shell_context():
22 | return dict(
23 | app=app,
24 | db=db,
25 | User=User,
26 | Post=Post,
27 | Tag=Tag,
28 | Comment=Comment
29 | )
30 |
31 | if __name__ == "__main__":
32 | manager.run()
33 |
--------------------------------------------------------------------------------
/Module 3/Chapter06/Chapter 6/chapter_6/webapp/config.py:
--------------------------------------------------------------------------------
1 | class Config(object):
2 | SECRET_KEY = '736670cb10a600b695a55839ca3a5aa54a7d7356cdef815d2ad6e19a2031182b'
3 | RECAPTCHA_PUBLIC_KEY = "6LdKkQQTAAAAAEH0GFj7NLg5tGicaoOus7G9Q5Uw"
4 | RECAPTCHA_PRIVATE_KEY = '6LdKkQQTAAAAAMYroksPTJ7pWhobYb88fTAcxcYn'
5 |
6 |
7 | class ProdConfig(Config):
8 | SQLALCHEMY_DATABASE_URI = 'sqlite://../database.db'
9 |
10 |
11 | class DevConfig(Config):
12 | DEBUG = True
13 | SQLALCHEMY_DATABASE_URI = 'sqlite:///../database.db'
14 |
--------------------------------------------------------------------------------
/Module 3/Chapter06/Chapter 6/chapter_6/webapp/controllers/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter06/Chapter 6/chapter_6/webapp/controllers/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter06/Chapter 6/chapter_6/webapp/static/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter06/Chapter 6/chapter_6/webapp/static/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/Module 3/Chapter06/Chapter 6/chapter_6/webapp/static/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter06/Chapter 6/chapter_6/webapp/static/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/Module 3/Chapter06/Chapter 6/chapter_6/webapp/static/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter06/Chapter 6/chapter_6/webapp/static/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/Module 3/Chapter06/Chapter 6/chapter_6/webapp/static/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter06/Chapter 6/chapter_6/webapp/static/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/Module 3/Chapter06/Chapter 6/chapter_6/webapp/static/js/npm.js:
--------------------------------------------------------------------------------
1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
2 | require('../../js/transition.js')
3 | require('../../js/alert.js')
4 | require('../../js/button.js')
5 | require('../../js/carousel.js')
6 | require('../../js/collapse.js')
7 | require('../../js/dropdown.js')
8 | require('../../js/modal.js')
9 | require('../../js/tooltip.js')
10 | require('../../js/popover.js')
11 | require('../../js/scrollspy.js')
12 | require('../../js/tab.js')
13 | require('../../js/affix.js')
--------------------------------------------------------------------------------
/Module 3/Chapter07/chapter_7/manage.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | from flask.ext.script import Manager, Server
4 | from flask.ext.migrate import Migrate, MigrateCommand
5 |
6 | from webapp import create_app
7 | from webapp.models import db, User, Post, Tag, Comment
8 |
9 | # default to dev config
10 | env = os.environ.get('WEBAPP_ENV', 'dev')
11 | app = create_app('webapp.config.%sConfig' % env.capitalize())
12 |
13 | migrate = Migrate(app, db)
14 |
15 | manager = Manager(app)
16 | manager.add_command("server", Server())
17 | manager.add_command('db', MigrateCommand)
18 |
19 |
20 | @manager.shell
21 | def make_shell_context():
22 | return dict(
23 | app=app,
24 | db=db,
25 | User=User,
26 | Post=Post,
27 | Tag=Tag,
28 | Comment=Comment
29 | )
30 |
31 | if __name__ == "__main__":
32 | manager.run()
33 |
--------------------------------------------------------------------------------
/Module 3/Chapter07/chapter_7/requirements.txt:
--------------------------------------------------------------------------------
1 | Flask==0.10.1
2 |
3 | # Flask Extensions
4 | Flask-Assets==0.10
5 | Flask-Bcrypt==0.6.2
6 | Flask-Cache==0.13.1
7 | Flask-DebugToolbar==0.10.0
8 | Flask-Login==0.2.11
9 | Flask-Migrate==1.3.1
10 | Flask-OAuth==0.12
11 | Flask-OpenID==1.2.4
12 | Flask-Principal==0.4.0
13 | Flask-Script==2.0.5
14 | Flask-SQLAlchemy==2.0
15 | Flask-WTF==0.11
16 |
17 | # Other
18 | itsdangerous==0.24
19 | cssmin==0.2.0
20 | jsmin==2.1.1
21 |
22 | # Testing
23 | pytest==2.7.0
24 | pytest-cov==1.8.1
25 | mccabe==0.3
26 | flake8==2.4.0
--------------------------------------------------------------------------------
/Module 3/Chapter07/chapter_7/webapp/config.py:
--------------------------------------------------------------------------------
1 | class Config(object):
2 | SECRET_KEY = '736670cb10a600b695a55839ca3a5aa54a7d7356cdef815d2ad6e19a2031182b'
3 | RECAPTCHA_PUBLIC_KEY = "6LdKkQQTAAAAAEH0GFj7NLg5tGicaoOus7G9Q5Uw"
4 | RECAPTCHA_PRIVATE_KEY = '6LdKkQQTAAAAAMYroksPTJ7pWhobYb88fTAcxcYn'
5 |
6 |
7 | class ProdConfig(Config):
8 | SQLALCHEMY_DATABASE_URI = 'sqlite://../database.db'
9 |
10 |
11 | class DevConfig(Config):
12 | DEBUG = True
13 | SQLALCHEMY_DATABASE_URI = 'sqlite:///../database.db'
14 | MONGODB_SETTINGS = {
15 | 'db': 'local',
16 | 'host': 'localhost',
17 | 'port': 27017
18 | }
19 |
--------------------------------------------------------------------------------
/Module 3/Chapter07/chapter_7/webapp/controllers/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter07/chapter_7/webapp/controllers/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter07/chapter_7/webapp/static/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter07/chapter_7/webapp/static/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/Module 3/Chapter07/chapter_7/webapp/static/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter07/chapter_7/webapp/static/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/Module 3/Chapter07/chapter_7/webapp/static/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter07/chapter_7/webapp/static/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/Module 3/Chapter07/chapter_7/webapp/static/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter07/chapter_7/webapp/static/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/Module 3/Chapter08/chapter_8/manage.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | from flask.ext.script import Manager, Server
4 | from flask.ext.migrate import Migrate, MigrateCommand
5 |
6 | from webapp import create_app
7 | from webapp.models import db, User, Post, Tag, Comment
8 |
9 | # default to dev config
10 | env = os.environ.get('WEBAPP_ENV', 'dev')
11 | app = create_app('webapp.config.%sConfig' % env.capitalize())
12 |
13 | migrate = Migrate(app, db)
14 |
15 | manager = Manager(app)
16 | manager.add_command("server", Server())
17 | manager.add_command('db', MigrateCommand)
18 |
19 |
20 | @manager.shell
21 | def make_shell_context():
22 | return dict(
23 | app=app,
24 | db=db,
25 | User=User,
26 | Post=Post,
27 | Tag=Tag,
28 | Comment=Comment
29 | )
30 |
31 | if __name__ == "__main__":
32 | manager.run()
33 |
--------------------------------------------------------------------------------
/Module 3/Chapter08/chapter_8/webapp/config.py:
--------------------------------------------------------------------------------
1 | class Config(object):
2 | SECRET_KEY = '736670cb10a600b695a55839ca3a5aa54a7d7356cdef815d2ad6e19a2031182b'
3 | RECAPTCHA_PUBLIC_KEY = "6LdKkQQTAAAAAEH0GFj7NLg5tGicaoOus7G9Q5Uw"
4 | RECAPTCHA_PRIVATE_KEY = '6LdKkQQTAAAAAMYroksPTJ7pWhobYb88fTAcxcYn'
5 |
6 |
7 | class ProdConfig(Config):
8 | SQLALCHEMY_DATABASE_URI = 'sqlite://../database.db'
9 |
10 |
11 | class DevConfig(Config):
12 | DEBUG = True
13 | SQLALCHEMY_DATABASE_URI = 'sqlite:///../database.db'
14 |
--------------------------------------------------------------------------------
/Module 3/Chapter08/chapter_8/webapp/controllers/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter08/chapter_8/webapp/controllers/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter08/chapter_8/webapp/controllers/rest/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter08/chapter_8/webapp/controllers/rest/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter08/chapter_8/webapp/controllers/rest/auth.py:
--------------------------------------------------------------------------------
1 | from flask import abort, current_app
2 | from flask.ext.restful import Resource
3 |
4 | from webapp.models import User
5 | from .parsers import user_post_parser
6 |
7 | from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
8 |
9 |
10 | class AuthApi(Resource):
11 | def post(self):
12 | args = user_post_parser.parse_args()
13 | user = User.query.filter_by(username=args['username']).one()
14 |
15 | if user.check_password(args['password']):
16 | s = Serializer(current_app.config['SECRET_KEY'], expires_in=604800)
17 | return {"token": s.dumps({'id': user.id})}
18 | else:
19 | abort(401)
20 |
--------------------------------------------------------------------------------
/Module 3/Chapter08/chapter_8/webapp/controllers/rest/fields.py:
--------------------------------------------------------------------------------
1 | from HTMLParser import HTMLParser
2 | from flask.ext.restful import fields
3 |
4 |
5 | class HTMLStripper(HTMLParser):
6 | def __init__(self):
7 | self.reset()
8 | self.fed = []
9 |
10 | def handle_data(self, d):
11 | self.fed.append(d)
12 |
13 | def get_data(self):
14 | return ''.join(self.fed)
15 |
16 |
17 | def strip_tags(html):
18 | s = HTMLStripper()
19 | s.feed(html)
20 |
21 | return s.get_data()
22 |
23 |
24 | class HTMLField(fields.Raw):
25 | def format(self, value):
26 | return strip_tags(str(value))
27 |
--------------------------------------------------------------------------------
/Module 3/Chapter08/chapter_8/webapp/static/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter08/chapter_8/webapp/static/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/Module 3/Chapter08/chapter_8/webapp/static/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter08/chapter_8/webapp/static/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/Module 3/Chapter08/chapter_8/webapp/static/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter08/chapter_8/webapp/static/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/Module 3/Chapter08/chapter_8/webapp/static/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter08/chapter_8/webapp/static/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/Module 3/Chapter08/chapter_8/webapp/static/js/npm.js:
--------------------------------------------------------------------------------
1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
2 | require('../../js/transition.js')
3 | require('../../js/alert.js')
4 | require('../../js/button.js')
5 | require('../../js/carousel.js')
6 | require('../../js/collapse.js')
7 | require('../../js/dropdown.js')
8 | require('../../js/modal.js')
9 | require('../../js/tooltip.js')
10 | require('../../js/popover.js')
11 | require('../../js/scrollspy.js')
12 | require('../../js/tab.js')
13 | require('../../js/affix.js')
--------------------------------------------------------------------------------
/Module 3/Chapter09/chapter_9/celery_runner.py:
--------------------------------------------------------------------------------
1 | import os
2 | from webapp import create_app
3 | from celery import Celery
4 |
5 |
6 | def make_celery(app):
7 | celery = Celery(
8 | app.import_name,
9 | broker=app.config['CELERY_BROKER_URL'],
10 | backend=app.config['CELERY_BACKEND_URL']
11 | )
12 | celery.conf.update(app.config)
13 | TaskBase = celery.Task
14 |
15 | class ContextTask(TaskBase):
16 | abstract = True
17 |
18 | def __call__(self, *args, **kwargs):
19 | with app.app_context():
20 | return TaskBase.__call__(self, *args, **kwargs)
21 |
22 | celery.Task = ContextTask
23 |
24 | return celery
25 |
26 | env = os.environ.get('WEBAPP_ENV', 'dev')
27 | flask_app = create_app('webapp.config.%sConfig' % env.capitalize())
28 |
29 | celery = make_celery(flask_app)
30 |
--------------------------------------------------------------------------------
/Module 3/Chapter09/chapter_9/manage.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | from flask.ext.script import Manager, Server
4 | from flask.ext.migrate import Migrate, MigrateCommand
5 |
6 | from webapp import create_app
7 | from webapp.models import db, User, Post, Tag, Comment
8 |
9 | # default to dev config
10 | env = os.environ.get('WEBAPP_ENV', 'dev')
11 | app = create_app('webapp.config.%sConfig' % env.capitalize())
12 |
13 | migrate = Migrate(app, db)
14 |
15 | manager = Manager(app)
16 | manager.add_command("server", Server())
17 | manager.add_command('db', MigrateCommand)
18 |
19 |
20 | @manager.shell
21 | def make_shell_context():
22 | return dict(
23 | app=app,
24 | db=db,
25 | User=User,
26 | Post=Post,
27 | Tag=Tag,
28 | Comment=Comment
29 | )
30 |
31 | if __name__ == "__main__":
32 | manager.run()
33 |
--------------------------------------------------------------------------------
/Module 3/Chapter09/chapter_9/webapp/config.py:
--------------------------------------------------------------------------------
1 | from celery.schedules import crontab
2 |
3 |
4 | class Config(object):
5 | SECRET_KEY = '736670cb10a600b695a55839ca3a5aa54a7d7356cdef815d2ad6e19a2031182b'
6 | RECAPTCHA_PUBLIC_KEY = "6LdKkQQTAAAAAEH0GFj7NLg5tGicaoOus7G9Q5Uw"
7 | RECAPTCHA_PRIVATE_KEY = '6LdKkQQTAAAAAMYroksPTJ7pWhobYb88fTAcxcYn'
8 |
9 |
10 | class ProdConfig(Config):
11 | SQLALCHEMY_DATABASE_URI = 'sqlite://../database.db'
12 |
13 |
14 | class DevConfig(Config):
15 | DEBUG = True
16 | SQLALCHEMY_DATABASE_URI = 'sqlite:///../database.db'
17 | CELERY_BROKER_URL = "amqp://guest:guest@localhost:5672//"
18 | CELERY_BACKEND_URL = "amqp://guest:guest@localhost:5672//"
19 |
20 | CELERYBEAT_SCHEDULE = {
21 | 'weekly-digest': {
22 | 'task': 'tasks.digest',
23 | 'schedule': crontab(day_of_week=6, hour='10')
24 | },
25 | }
26 |
--------------------------------------------------------------------------------
/Module 3/Chapter09/chapter_9/webapp/controllers/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter09/chapter_9/webapp/controllers/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter09/chapter_9/webapp/controllers/rest/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter09/chapter_9/webapp/controllers/rest/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter09/chapter_9/webapp/controllers/rest/auth.py:
--------------------------------------------------------------------------------
1 | from flask import abort, current_app
2 | from flask.ext.restful import Resource
3 |
4 | from webapp.models import User
5 | from .parsers import user_post_parser
6 |
7 | from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
8 |
9 |
10 | class AuthApi(Resource):
11 | def post(self):
12 | args = user_post_parser.parse_args()
13 | user = User.query.filter_by(username=args['username']).one()
14 |
15 | if user.check_password(args['password']):
16 | s = Serializer(current_app.config['SECRET_KEY'], expires_in=604800)
17 | return {"token": s.dumps({'id': user.id})}
18 | else:
19 | abort(401)
20 |
--------------------------------------------------------------------------------
/Module 3/Chapter09/chapter_9/webapp/controllers/rest/fields.py:
--------------------------------------------------------------------------------
1 | from HTMLParser import HTMLParser
2 | from flask.ext.restful import fields
3 |
4 |
5 | class HTMLStripper(HTMLParser):
6 | def __init__(self):
7 | self.reset()
8 | self.fed = []
9 |
10 | def handle_data(self, d):
11 | self.fed.append(d)
12 |
13 | def get_data(self):
14 | return ''.join(self.fed)
15 |
16 |
17 | def strip_tags(html):
18 | s = HTMLStripper()
19 | s.feed(html)
20 |
21 | return s.get_data()
22 |
23 |
24 | class HTMLField(fields.Raw):
25 | def format(self, value):
26 | return strip_tags(str(value))
27 |
--------------------------------------------------------------------------------
/Module 3/Chapter09/chapter_9/webapp/static/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter09/chapter_9/webapp/static/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/Module 3/Chapter09/chapter_9/webapp/static/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter09/chapter_9/webapp/static/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/Module 3/Chapter09/chapter_9/webapp/static/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter09/chapter_9/webapp/static/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/Module 3/Chapter09/chapter_9/webapp/static/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter09/chapter_9/webapp/static/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/Module 3/Chapter09/chapter_9/webapp/static/js/npm.js:
--------------------------------------------------------------------------------
1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
2 | require('../../js/transition.js')
3 | require('../../js/alert.js')
4 | require('../../js/button.js')
5 | require('../../js/carousel.js')
6 | require('../../js/collapse.js')
7 | require('../../js/dropdown.js')
8 | require('../../js/modal.js')
9 | require('../../js/tooltip.js')
10 | require('../../js/popover.js')
11 | require('../../js/scrollspy.js')
12 | require('../../js/tab.js')
13 | require('../../js/affix.js')
--------------------------------------------------------------------------------
/Module 3/Chapter10/Chapter 10/celery_runner.py:
--------------------------------------------------------------------------------
1 | import os
2 | from webapp import create_app
3 | from celery import Celery
4 |
5 |
6 | def make_celery(app):
7 | celery = Celery(
8 | app.import_name,
9 | broker=app.config['CELERY_BROKER_URL'],
10 | backend=app.config['CELERY_BACKEND_URL']
11 | )
12 | celery.conf.update(app.config)
13 | TaskBase = celery.Task
14 |
15 | class ContextTask(TaskBase):
16 | abstract = True
17 |
18 | def __call__(self, *args, **kwargs):
19 | with app.app_context():
20 | return TaskBase.__call__(self, *args, **kwargs)
21 |
22 | celery.Task = ContextTask
23 |
24 | return celery
25 |
26 | env = os.environ.get('WEBAPP_ENV', 'dev')
27 | flask_app = create_app('webapp.config.%sConfig' % env.capitalize())
28 |
29 | celery = make_celery(flask_app)
30 |
--------------------------------------------------------------------------------
/Module 3/Chapter10/Chapter 10/webapp/config.py:
--------------------------------------------------------------------------------
1 | from celery.schedules import crontab
2 |
3 |
4 | class Config(object):
5 | SECRET_KEY = '736670cb10a600b695a55839ca3a5aa54a7d7356cdef815d2ad6e19a2031182b'
6 | RECAPTCHA_PUBLIC_KEY = "6LdKkQQTAAAAAEH0GFj7NLg5tGicaoOus7G9Q5Uw"
7 | RECAPTCHA_PRIVATE_KEY = '6LdKkQQTAAAAAMYroksPTJ7pWhobYb88fTAcxcYn'
8 |
9 | CELERYBEAT_SCHEDULE = {
10 | 'weekly-digest': {
11 | 'task': 'tasks.digest',
12 | 'schedule': crontab(day_of_week=6, hour='10')
13 | },
14 | }
15 |
16 |
17 | class ProdConfig(Config):
18 | SQLALCHEMY_DATABASE_URI = 'sqlite://../database.db'
19 |
20 | CACHE_TYPE = 'simple'
21 |
22 | CELERY_BROKER_URL = "amqp://guest:guest@localhost:5672//"
23 | CELERY_BACKEND_URL = "amqp://guest:guest@localhost:5672//"
24 |
25 |
26 | class DevConfig(Config):
27 | DEBUG = True
28 | DEBUG_TB_INTERCEPT_REDIRECTS = False
29 |
30 | ASSETS_DEBUG = True
31 |
32 | SQLALCHEMY_DATABASE_URI = 'sqlite:///../database.db'
33 |
34 | CACHE_TYPE = 'simple'
35 |
36 | CELERY_BROKER_URL = "amqp://guest:guest@localhost:5672//"
37 | CELERY_BACKEND_URL = "amqp://guest:guest@localhost:5672//"
38 |
39 | MAIL_SERVER = 'localhost'
40 | MAIL_PORT = 25
41 | MAIL_USERNAME = 'username'
42 | MAIL_PASSWORD = 'password'
43 |
--------------------------------------------------------------------------------
/Module 3/Chapter10/Chapter 10/webapp/controllers/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter10/Chapter 10/webapp/controllers/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter10/Chapter 10/webapp/controllers/admin.py:
--------------------------------------------------------------------------------
1 | from flask.ext.admin import BaseView, expose
2 | from flask.ext.admin.contrib.sqla import ModelView
3 | from flask.ext.admin.contrib.fileadmin import FileAdmin
4 | from flask.ext.login import login_required, current_user
5 |
6 | from webapp.extensions import admin_permission
7 | from webapp.forms import CKTextAreaField
8 |
9 |
10 | class CustomView(BaseView):
11 | @expose('/')
12 | @login_required
13 | @admin_permission.require(http_exception=403)
14 | def index(self):
15 | return self.render('admin/custom.html')
16 |
17 | @expose('/second_page')
18 | @login_required
19 | @admin_permission.require(http_exception=403)
20 | def second_page(self):
21 | return self.render('admin/second_page.html')
22 |
23 |
24 | class CustomModelView(ModelView):
25 | def is_accessible(self):
26 | return current_user.is_authenticated() and admin_permission.can()
27 |
28 |
29 | class PostView(CustomModelView):
30 | form_overrides = dict(text=CKTextAreaField)
31 | column_searchable_list = ('text', 'title')
32 | column_filters = ('publish_date',)
33 |
34 | create_template = 'admin/post_edit.html'
35 | edit_template = 'admin/post_edit.html'
36 |
37 |
38 | class CustomFileAdmin(FileAdmin):
39 | def is_accessible(self):
40 | return current_user.is_authenticated() and admin_permission.can()
41 |
--------------------------------------------------------------------------------
/Module 3/Chapter10/Chapter 10/webapp/controllers/rest/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter10/Chapter 10/webapp/controllers/rest/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter10/Chapter 10/webapp/controllers/rest/auth.py:
--------------------------------------------------------------------------------
1 | from flask import abort, current_app
2 | from flask.ext.restful import Resource
3 |
4 | from webapp.models import User
5 | from .parsers import user_post_parser
6 |
7 | from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
8 |
9 |
10 | class AuthApi(Resource):
11 | def post(self):
12 | args = user_post_parser.parse_args()
13 | user = User.query.filter_by(username=args['username']).one()
14 |
15 | if user.check_password(args['password']):
16 | s = Serializer(current_app.config['SECRET_KEY'], expires_in=604800)
17 | return {"token": s.dumps({'id': user.id})}
18 | else:
19 | abort(401)
20 |
--------------------------------------------------------------------------------
/Module 3/Chapter10/Chapter 10/webapp/controllers/rest/fields.py:
--------------------------------------------------------------------------------
1 | from HTMLParser import HTMLParser
2 | from flask.ext.restful import fields
3 |
4 |
5 | class HTMLStripper(HTMLParser):
6 | def __init__(self):
7 | self.reset()
8 | self.fed = []
9 |
10 | def handle_data(self, d):
11 | self.fed.append(d)
12 |
13 | def get_data(self):
14 | return ''.join(self.fed)
15 |
16 |
17 | def strip_tags(html):
18 | s = HTMLStripper()
19 | s.feed(html)
20 |
21 | return s.get_data()
22 |
23 |
24 | class HTMLField(fields.Raw):
25 | def format(self, value):
26 | return strip_tags(str(value))
27 |
--------------------------------------------------------------------------------
/Module 3/Chapter10/Chapter 10/webapp/static/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter10/Chapter 10/webapp/static/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/Module 3/Chapter10/Chapter 10/webapp/static/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter10/Chapter 10/webapp/static/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/Module 3/Chapter10/Chapter 10/webapp/static/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter10/Chapter 10/webapp/static/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/Module 3/Chapter10/Chapter 10/webapp/static/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter10/Chapter 10/webapp/static/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/Module 3/Chapter10/Chapter 10/webapp/templates/admin/custom.html:
--------------------------------------------------------------------------------
1 | {% extends 'admin/master.html' %}
2 |
3 | {% block body %}
4 | This is the custom view!
5 |
6 | Link
7 | {% endblock %}
--------------------------------------------------------------------------------
/Module 3/Chapter10/Chapter 10/webapp/templates/admin/post_edit.html:
--------------------------------------------------------------------------------
1 | {% extends 'admin/model/edit.html' %}
2 | {% block tail %}
3 | {{ super() }}
4 |
5 | {% endblock %}
--------------------------------------------------------------------------------
/Module 3/Chapter10/Chapter 10/webapp/templates/admin/second_page.html:
--------------------------------------------------------------------------------
1 | {% extends 'admin/master.html' %}
2 |
3 | {% block body %}
4 | This is the second page!
5 |
6 | Link
7 | {% endblock %}
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/Flask-YouTube/Flask_YouTube.egg-info/PKG-INFO:
--------------------------------------------------------------------------------
1 | Metadata-Version: 1.0
2 | Name: Flask-YouTube
3 | Version: 0.1
4 | Summary: Flask extension to allow easy embedding of YouTube videos
5 | Home-page: UNKNOWN
6 | Author: Jack Stouffer
7 | Author-email: example@gmail.com
8 | License: MIT
9 | Description: UNKNOWN
10 | Platform: any
11 |
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/Flask-YouTube/Flask_YouTube.egg-info/SOURCES.txt:
--------------------------------------------------------------------------------
1 | setup.py
2 | Flask_YouTube.egg-info/PKG-INFO
3 | Flask_YouTube.egg-info/SOURCES.txt
4 | Flask_YouTube.egg-info/dependency_links.txt
5 | Flask_YouTube.egg-info/requires.txt
6 | Flask_YouTube.egg-info/top_level.txt
7 | flask_youtube/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/Flask-YouTube/Flask_YouTube.egg-info/dependency_links.txt:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/Flask-YouTube/Flask_YouTube.egg-info/requires.txt:
--------------------------------------------------------------------------------
1 | Flask
2 |
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/Flask-YouTube/Flask_YouTube.egg-info/top_level.txt:
--------------------------------------------------------------------------------
1 | flask_youtube
2 |
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/Flask-YouTube/build/lib/flask_youtube/__init__.py:
--------------------------------------------------------------------------------
1 | from flask import render_template, Blueprint, Markup
2 |
3 |
4 | class Video(object):
5 | def __init__(self, video_id, cls="youtube"):
6 | self.video_id = video_id
7 | self.cls = cls
8 |
9 | def render(self, *args, **kwargs):
10 | return render_template(*args, **kwargs)
11 |
12 | @property
13 | def html(self):
14 | return Markup(self.render('youtube/video.html', video=self))
15 |
16 |
17 | def youtube(*args, **kwargs):
18 | video = Video(*args, **kwargs)
19 | return video.html
20 |
21 |
22 | class Youtube(object):
23 | def __init__(self, app=None, **kwargs):
24 | if app:
25 | self.init_app(app)
26 |
27 | def init_app(self, app):
28 | self.register_blueprint(app)
29 | app.add_template_global(youtube)
30 |
31 | def register_blueprint(self, app):
32 | module = Blueprint(
33 | "youtube",
34 | __name__,
35 | template_folder="templates"
36 | )
37 | app.register_blueprint(module)
38 | return module
39 |
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/Flask-YouTube/dist/Flask_YouTube-0.1-py2.7.egg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter11/Chapter 11/Flask-YouTube/dist/Flask_YouTube-0.1-py2.7.egg
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/Flask-YouTube/flask_youtube/__init__.py:
--------------------------------------------------------------------------------
1 | from flask import render_template, Blueprint, Markup
2 |
3 |
4 | class Video(object):
5 | def __init__(self, video_id, cls="youtube"):
6 | self.video_id = video_id
7 | self.cls = cls
8 |
9 | def render(self, *args, **kwargs):
10 | return render_template(*args, **kwargs)
11 |
12 | @property
13 | def html(self):
14 | return Markup(self.render('youtube/video.html', video=self))
15 |
16 |
17 | def youtube(*args, **kwargs):
18 | video = Video(*args, **kwargs)
19 | return video.html
20 |
21 |
22 | class Youtube(object):
23 | def __init__(self, app=None, **kwargs):
24 | if app:
25 | self.init_app(app)
26 |
27 | def init_app(self, app):
28 | self.register_blueprint(app)
29 | app.add_template_global(youtube)
30 |
31 | def register_blueprint(self, app):
32 | module = Blueprint(
33 | "youtube",
34 | __name__,
35 | template_folder="templates"
36 | )
37 | app.register_blueprint(module)
38 | return module
39 |
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/Flask-YouTube/flask_youtube/templates/youtube/video.html:
--------------------------------------------------------------------------------
1 | VIDEO
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/Flask-YouTube/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import setup, find_packages
2 |
3 | setup(
4 | name='Flask-YouTube',
5 | version='0.1',
6 | license='MIT',
7 | description='Flask extension to allow easy embedding of YouTube videos',
8 | author='Jack Stouffer',
9 | author_email='example@gmail.com',
10 | platforms='any',
11 | install_requires=['Flask'],
12 | packages=find_packages()
13 | )
14 |
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/celery_runner.py:
--------------------------------------------------------------------------------
1 | import os
2 | from webapp import create_app
3 | from celery import Celery
4 |
5 |
6 | def make_celery(app):
7 | celery = Celery(
8 | app.import_name,
9 | broker=app.config['CELERY_BROKER_URL'],
10 | backend=app.config['CELERY_BACKEND_URL']
11 | )
12 | celery.conf.update(app.config)
13 | TaskBase = celery.Task
14 |
15 | class ContextTask(TaskBase):
16 | abstract = True
17 |
18 | def __call__(self, *args, **kwargs):
19 | with app.app_context():
20 | return TaskBase.__call__(self, *args, **kwargs)
21 |
22 | celery.Task = ContextTask
23 |
24 | return celery
25 |
26 | env = os.environ.get('WEBAPP_ENV', 'dev')
27 | flask_app = create_app('webapp.config.%sConfig' % env.capitalize())
28 |
29 | celery = make_celery(flask_app)
30 |
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/webapp/config.py:
--------------------------------------------------------------------------------
1 | from celery.schedules import crontab
2 |
3 |
4 | class Config(object):
5 | SECRET_KEY = '736670cb10a600b695a55839ca3a5aa54a7d7356cdef815d2ad6e19a2031182b'
6 | RECAPTCHA_PUBLIC_KEY = "6LdKkQQTAAAAAEH0GFj7NLg5tGicaoOus7G9Q5Uw"
7 | RECAPTCHA_PRIVATE_KEY = '6LdKkQQTAAAAAMYroksPTJ7pWhobYb88fTAcxcYn'
8 |
9 | CELERYBEAT_SCHEDULE = {
10 | 'weekly-digest': {
11 | 'task': 'tasks.digest',
12 | 'schedule': crontab(day_of_week=6, hour='10')
13 | },
14 | }
15 |
16 |
17 | class ProdConfig(Config):
18 | SQLALCHEMY_DATABASE_URI = 'sqlite://../database.db'
19 |
20 | CACHE_TYPE = 'simple'
21 |
22 | CELERY_BROKER_URL = "amqp://guest:guest@localhost:5672//"
23 | CELERY_BACKEND_URL = "amqp://guest:guest@localhost:5672//"
24 |
25 |
26 | class DevConfig(Config):
27 | DEBUG = True
28 | DEBUG_TB_INTERCEPT_REDIRECTS = False
29 |
30 | ASSETS_DEBUG = True
31 |
32 | SQLALCHEMY_DATABASE_URI = 'sqlite:///../database.db'
33 |
34 | CACHE_TYPE = 'simple'
35 |
36 | CELERY_BROKER_URL = "amqp://guest:guest@localhost:5672//"
37 | CELERY_BACKEND_URL = "amqp://guest:guest@localhost:5672//"
38 |
39 | MAIL_SERVER = 'localhost'
40 | MAIL_PORT = 25
41 | MAIL_USERNAME = 'username'
42 | MAIL_PASSWORD = 'password'
43 |
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/webapp/controllers/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter11/Chapter 11/webapp/controllers/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/webapp/controllers/rest/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter11/Chapter 11/webapp/controllers/rest/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/webapp/controllers/rest/auth.py:
--------------------------------------------------------------------------------
1 | from flask import abort, current_app
2 | from flask.ext.restful import Resource
3 |
4 | from webapp.models import User
5 | from .parsers import user_post_parser
6 |
7 | from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
8 |
9 |
10 | class AuthApi(Resource):
11 | def post(self):
12 | args = user_post_parser.parse_args()
13 | user = User.query.filter_by(username=args['username']).one()
14 |
15 | if user.check_password(args['password']):
16 | s = Serializer(current_app.config['SECRET_KEY'], expires_in=604800)
17 | return {"token": s.dumps({'id': user.id})}
18 | else:
19 | abort(401)
20 |
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/webapp/controllers/rest/fields.py:
--------------------------------------------------------------------------------
1 | from HTMLParser import HTMLParser
2 | from flask.ext.restful import fields
3 |
4 |
5 | class HTMLStripper(HTMLParser):
6 | def __init__(self):
7 | self.reset()
8 | self.fed = []
9 |
10 | def handle_data(self, d):
11 | self.fed.append(d)
12 |
13 | def get_data(self):
14 | return ''.join(self.fed)
15 |
16 |
17 | def strip_tags(html):
18 | s = HTMLStripper()
19 | s.feed(html)
20 |
21 | return s.get_data()
22 |
23 |
24 | class HTMLField(fields.Raw):
25 | def format(self, value):
26 | return strip_tags(str(value))
27 |
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/webapp/static/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter11/Chapter 11/webapp/static/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/webapp/static/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter11/Chapter 11/webapp/static/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/webapp/static/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter11/Chapter 11/webapp/static/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/webapp/static/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter11/Chapter 11/webapp/static/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/webapp/templates/admin/custom.html:
--------------------------------------------------------------------------------
1 | {% extends 'admin/master.html' %}
2 |
3 | {% block body %}
4 | This is the custom view!
5 |
6 | Link
7 | {% endblock %}
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/webapp/templates/admin/post_edit.html:
--------------------------------------------------------------------------------
1 | {% extends 'admin/model/edit.html' %}
2 | {% block tail %}
3 | {{ super() }}
4 |
5 | {% endblock %}
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/webapp/templates/admin/second_page.html:
--------------------------------------------------------------------------------
1 | {% extends 'admin/master.html' %}
2 |
3 | {% block body %}
4 | This is the second page!
5 |
6 | Link
7 | {% endblock %}
--------------------------------------------------------------------------------
/Module 3/Chapter11/Chapter 11/webapp/templates/youtube/video.html:
--------------------------------------------------------------------------------
1 | VIDEO
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/.coverage:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter12/chapter_12/.coverage
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/Flask-GZip/flask_gzip/__init__.py:
--------------------------------------------------------------------------------
1 | from gzip import GzipFile
2 | from io import BytesIO
3 |
4 | from flask import request
5 |
6 |
7 | class GZip(object):
8 | def __init__(self, app=None):
9 | self.app = app
10 | if app is not None:
11 | self.init_app(app)
12 |
13 | def init_app(self, app):
14 | app.after_request(self.after_request)
15 |
16 | def after_request(self, response):
17 | encoding = request.headers.get('Accept-Encoding')
18 |
19 | if 'gzip' not in encoding or \
20 | not response.status_code == 200 or \
21 | 'Content-Encoding' in response.headers:
22 | return response
23 |
24 | response.direct_passthrough = False
25 |
26 | gzip_buffer = BytesIO()
27 | with GzipFile(mode='wb', compresslevel=5, fileobj=gzip_buffer) as gzip_file:
28 | gzip_file.write(response.get_data())
29 |
30 | response.set_data(bytes(gzip_buffer.getvalue()))
31 |
32 | response.headers['Content-Encoding'] = 'gzip'
33 | response.headers['Content-Length'] = response.content_length
34 |
35 | return response
36 |
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/Flask-GZip/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import setup, find_packages
2 |
3 | setup(
4 | name='Flask-GZip',
5 | version='0.1',
6 | license='MIT',
7 | description='Flask extension to allow easy GZip compressing of web pagess',
8 | author='Jack Stouffer',
9 | author_email='example@gmail.com',
10 | platforms='any',
11 | install_requires=['Flask'],
12 | packages=find_packages()
13 | )
14 |
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/Flask-YouTube/Flask_YouTube.egg-info/PKG-INFO:
--------------------------------------------------------------------------------
1 | Metadata-Version: 1.0
2 | Name: Flask-YouTube
3 | Version: 0.1
4 | Summary: Flask extension to allow easy embedding of YouTube videos
5 | Home-page: UNKNOWN
6 | Author: Jack Stouffer
7 | Author-email: example@gmail.com
8 | License: MIT
9 | Description: UNKNOWN
10 | Platform: any
11 |
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/Flask-YouTube/Flask_YouTube.egg-info/SOURCES.txt:
--------------------------------------------------------------------------------
1 | setup.py
2 | Flask_YouTube.egg-info/PKG-INFO
3 | Flask_YouTube.egg-info/SOURCES.txt
4 | Flask_YouTube.egg-info/dependency_links.txt
5 | Flask_YouTube.egg-info/requires.txt
6 | Flask_YouTube.egg-info/top_level.txt
7 | flask_youtube/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/Flask-YouTube/Flask_YouTube.egg-info/dependency_links.txt:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/Flask-YouTube/Flask_YouTube.egg-info/requires.txt:
--------------------------------------------------------------------------------
1 | Flask
2 |
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/Flask-YouTube/Flask_YouTube.egg-info/top_level.txt:
--------------------------------------------------------------------------------
1 | flask_youtube
2 |
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/Flask-YouTube/build/lib/flask_youtube/__init__.py:
--------------------------------------------------------------------------------
1 | from flask import render_template, Blueprint, Markup
2 |
3 |
4 | class Video(object):
5 | def __init__(self, video_id, cls="youtube"):
6 | self.video_id = video_id
7 | self.cls = cls
8 |
9 | def render(self, *args, **kwargs):
10 | return render_template(*args, **kwargs)
11 |
12 | @property
13 | def html(self):
14 | return Markup(self.render('youtube/video.html', video=self))
15 |
16 |
17 | def youtube(*args, **kwargs):
18 | video = Video(*args, **kwargs)
19 | return video.html
20 |
21 |
22 | class Youtube(object):
23 | def __init__(self, app=None, **kwargs):
24 | if app:
25 | self.init_app(app)
26 |
27 | def init_app(self, app):
28 | self.register_blueprint(app)
29 | app.add_template_global(youtube)
30 |
31 | def register_blueprint(self, app):
32 | module = Blueprint(
33 | "youtube",
34 | __name__,
35 | template_folder="templates"
36 | )
37 | app.register_blueprint(module)
38 | return module
39 |
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/Flask-YouTube/dist/Flask_YouTube-0.1-py2.7.egg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter12/chapter_12/Flask-YouTube/dist/Flask_YouTube-0.1-py2.7.egg
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/Flask-YouTube/flask_youtube/__init__.py:
--------------------------------------------------------------------------------
1 | from flask import render_template, Blueprint, Markup
2 |
3 |
4 | class Video(object):
5 | def __init__(self, video_id, cls="youtube"):
6 | self.video_id = video_id
7 | self.cls = cls
8 |
9 | def render(self, *args, **kwargs):
10 | return render_template(*args, **kwargs)
11 |
12 | @property
13 | def html(self):
14 | return Markup(self.render('youtube/video.html', video=self))
15 |
16 |
17 | def youtube(*args, **kwargs):
18 | video = Video(*args, **kwargs)
19 | return video.html
20 |
21 |
22 | class Youtube(object):
23 | def __init__(self, app=None, **kwargs):
24 | if app:
25 | self.init_app(app)
26 |
27 | def init_app(self, app):
28 | self.register_blueprint(app)
29 | app.add_template_global(youtube)
30 |
31 | def register_blueprint(self, app):
32 | module = Blueprint(
33 | "youtube",
34 | __name__,
35 | template_folder="templates"
36 | )
37 | app.register_blueprint(module)
38 | return module
39 |
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/Flask-YouTube/flask_youtube/templates/youtube/video.html:
--------------------------------------------------------------------------------
1 | VIDEO
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/Flask-YouTube/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import setup, find_packages
2 |
3 | setup(
4 | name='Flask-YouTube',
5 | version='0.1',
6 | license='MIT',
7 | description='Flask extension to allow easy embedding of YouTube videos',
8 | author='Jack Stouffer',
9 | author_email='example@gmail.com',
10 | platforms='any',
11 | install_requires=['Flask'],
12 | packages=find_packages()
13 | )
14 |
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/celery_runner.py:
--------------------------------------------------------------------------------
1 | import os
2 | from webapp import create_app
3 | from celery import Celery
4 |
5 |
6 | def make_celery(app):
7 | celery = Celery(
8 | app.import_name,
9 | broker=app.config['CELERY_BROKER_URL'],
10 | backend=app.config['CELERY_BACKEND_URL']
11 | )
12 | celery.conf.update(app.config)
13 | TaskBase = celery.Task
14 |
15 | class ContextTask(TaskBase):
16 | abstract = True
17 |
18 | def __call__(self, *args, **kwargs):
19 | with app.app_context():
20 | return TaskBase.__call__(self, *args, **kwargs)
21 |
22 | celery.Task = ContextTask
23 |
24 | return celery
25 |
26 | env = os.environ.get('WEBAPP_ENV', 'dev')
27 | flask_app = create_app('webapp.config.%sConfig' % env.capitalize())
28 |
29 | celery = make_celery(flask_app)
30 |
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/run_test_server.py:
--------------------------------------------------------------------------------
1 | from webapp import create_app
2 | from webapp.models import db, User, Role
3 |
4 | app = create_app('webapp.config.TestConfig')
5 |
6 | db.app = app
7 | db.create_all()
8 |
9 | default = Role("default")
10 | poster = Role("poster")
11 | db.session.add(default)
12 | db.session.add(poster)
13 | db.session.commit()
14 |
15 | test_user = User("test")
16 | test_user.set_password("test")
17 | test_user.roles.append(poster)
18 | db.session.add(test_user)
19 | db.session.commit()
20 |
21 | app.run()
22 |
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/tests/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter12/chapter_12/tests/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/webapp/controllers/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter12/chapter_12/webapp/controllers/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/webapp/controllers/rest/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter12/chapter_12/webapp/controllers/rest/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/webapp/controllers/rest/auth.py:
--------------------------------------------------------------------------------
1 | from flask import abort, current_app
2 | from flask.ext.restful import Resource
3 |
4 | from webapp.models import User
5 | from .parsers import user_post_parser
6 |
7 | from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
8 |
9 |
10 | class AuthApi(Resource):
11 | def post(self):
12 | args = user_post_parser.parse_args()
13 | user = User.query.filter_by(username=args['username']).one()
14 |
15 | if user.check_password(args['password']):
16 | s = Serializer(current_app.config['SECRET_KEY'], expires_in=604800)
17 | return {"token": s.dumps({'id': user.id})}
18 | else:
19 | abort(401)
20 |
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/webapp/controllers/rest/fields.py:
--------------------------------------------------------------------------------
1 | from HTMLParser import HTMLParser
2 | from flask.ext.restful import fields
3 |
4 |
5 | class HTMLStripper(HTMLParser):
6 | def __init__(self):
7 | self.reset()
8 | self.fed = []
9 |
10 | def handle_data(self, d):
11 | self.fed.append(d)
12 |
13 | def get_data(self):
14 | return ''.join(self.fed)
15 |
16 |
17 | def strip_tags(html):
18 | s = HTMLStripper()
19 | s.feed(html)
20 |
21 | return s.get_data()
22 |
23 |
24 | class HTMLField(fields.Raw):
25 | def format(self, value):
26 | return strip_tags(str(value))
27 |
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/webapp/static/.webassets-cache/49d7031c832760f1c8af0e8f1f9a1954:
--------------------------------------------------------------------------------
1 | S'331a10ae21d04e9646dd1280cfd734b1'
2 | p1
3 | .
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/webapp/static/.webassets-cache/592e4efb9c5f8cd91720dd6d646679e7:
--------------------------------------------------------------------------------
1 | S'1cbf25481f487566bb2ac19ee9816a46'
2 | p1
3 | .
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/webapp/static/.webassets-cache/677b6b8fc43f52ebf6307be93396d33b:
--------------------------------------------------------------------------------
1 | S'e5dc859d'
2 | p1
3 | .
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/webapp/static/.webassets-cache/efe2845331acfbfa19510a0d780942a5:
--------------------------------------------------------------------------------
1 | S'549042f1'
2 | p1
3 | .
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/webapp/static/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter12/chapter_12/webapp/static/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/webapp/static/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter12/chapter_12/webapp/static/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/webapp/static/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter12/chapter_12/webapp/static/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/webapp/static/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter12/chapter_12/webapp/static/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/webapp/templates/admin/custom.html:
--------------------------------------------------------------------------------
1 | {% extends 'admin/master.html' %}
2 |
3 | {% block body %}
4 | This is the custom view!
5 |
6 | Link
7 | {% endblock %}
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/webapp/templates/admin/post_edit.html:
--------------------------------------------------------------------------------
1 | {% extends 'admin/model/edit.html' %}
2 | {% block tail %}
3 | {{ super() }}
4 |
5 | {% endblock %}
--------------------------------------------------------------------------------
/Module 3/Chapter12/chapter_12/webapp/templates/admin/second_page.html:
--------------------------------------------------------------------------------
1 | {% extends 'admin/master.html' %}
2 |
3 | {% block body %}
4 | This is the second page!
5 |
6 | Link
7 | {% endblock %}
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Elastic Beanstalk Files
3 | .elasticbeanstalk/*
4 | !.elasticbeanstalk/*.cfg.yml
5 | !.elasticbeanstalk/*.global.yml
6 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/Flask-GZip/flask_gzip/__init__.py:
--------------------------------------------------------------------------------
1 | from gzip import GzipFile
2 | from io import BytesIO
3 |
4 | from flask import request
5 |
6 |
7 | class GZip(object):
8 | def __init__(self, app=None):
9 | self.app = app
10 | if app is not None:
11 | self.init_app(app)
12 |
13 | def init_app(self, app):
14 | app.after_request(self.after_request)
15 |
16 | def after_request(self, response):
17 | encoding = request.headers.get('Accept-Encoding')
18 |
19 | if 'gzip' not in encoding or \
20 | not response.status_code == 200 or \
21 | 'Content-Encoding' in response.headers:
22 | return response
23 |
24 | response.direct_passthrough = False
25 |
26 | gzip_buffer = BytesIO()
27 | with GzipFile(mode='wb', compresslevel=5, fileobj=gzip_buffer) as gzip_file:
28 | gzip_file.write(response.get_data())
29 |
30 | response.set_data(bytes(gzip_buffer.getvalue()))
31 |
32 | response.headers['Content-Encoding'] = 'gzip'
33 | response.headers['Content-Length'] = response.content_length
34 |
35 | return response
36 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/Flask-GZip/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import setup, find_packages
2 |
3 | setup(
4 | name='Flask-GZip',
5 | version='0.1',
6 | license='MIT',
7 | description='Flask extension to allow easy GZip compressing of web pagess',
8 | author='Jack Stouffer',
9 | author_email='example@gmail.com',
10 | platforms='any',
11 | install_requires=['Flask'],
12 | packages=find_packages()
13 | )
14 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/Flask-YouTube/Flask_YouTube.egg-info/PKG-INFO:
--------------------------------------------------------------------------------
1 | Metadata-Version: 1.0
2 | Name: Flask-YouTube
3 | Version: 0.1
4 | Summary: Flask extension to allow easy embedding of YouTube videos
5 | Home-page: UNKNOWN
6 | Author: Jack Stouffer
7 | Author-email: example@gmail.com
8 | License: MIT
9 | Description: UNKNOWN
10 | Platform: any
11 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/Flask-YouTube/Flask_YouTube.egg-info/SOURCES.txt:
--------------------------------------------------------------------------------
1 | setup.py
2 | Flask_YouTube.egg-info/PKG-INFO
3 | Flask_YouTube.egg-info/SOURCES.txt
4 | Flask_YouTube.egg-info/dependency_links.txt
5 | Flask_YouTube.egg-info/requires.txt
6 | Flask_YouTube.egg-info/top_level.txt
7 | flask_youtube/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/Flask-YouTube/Flask_YouTube.egg-info/dependency_links.txt:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/Flask-YouTube/Flask_YouTube.egg-info/requires.txt:
--------------------------------------------------------------------------------
1 | Flask
2 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/Flask-YouTube/Flask_YouTube.egg-info/top_level.txt:
--------------------------------------------------------------------------------
1 | flask_youtube
2 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/Flask-YouTube/build/lib/flask_youtube/__init__.py:
--------------------------------------------------------------------------------
1 | from flask import render_template, Blueprint, Markup
2 |
3 |
4 | class Video(object):
5 | def __init__(self, video_id, cls="youtube"):
6 | self.video_id = video_id
7 | self.cls = cls
8 |
9 | def render(self, *args, **kwargs):
10 | return render_template(*args, **kwargs)
11 |
12 | @property
13 | def html(self):
14 | return Markup(self.render('youtube/video.html', video=self))
15 |
16 |
17 | def youtube(*args, **kwargs):
18 | video = Video(*args, **kwargs)
19 | return video.html
20 |
21 |
22 | class Youtube(object):
23 | def __init__(self, app=None, **kwargs):
24 | if app:
25 | self.init_app(app)
26 |
27 | def init_app(self, app):
28 | self.register_blueprint(app)
29 | app.add_template_global(youtube)
30 |
31 | def register_blueprint(self, app):
32 | module = Blueprint(
33 | "youtube",
34 | __name__,
35 | template_folder="templates"
36 | )
37 | app.register_blueprint(module)
38 | return module
39 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/Flask-YouTube/dist/Flask_YouTube-0.1-py2.7.egg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter13/Chapter 13/Flask-YouTube/dist/Flask_YouTube-0.1-py2.7.egg
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/Flask-YouTube/flask_youtube/__init__.py:
--------------------------------------------------------------------------------
1 | from flask import render_template, Blueprint, Markup
2 |
3 |
4 | class Video(object):
5 | def __init__(self, video_id, cls="youtube"):
6 | self.video_id = video_id
7 | self.cls = cls
8 |
9 | def render(self, *args, **kwargs):
10 | return render_template(*args, **kwargs)
11 |
12 | @property
13 | def html(self):
14 | return Markup(self.render('youtube/video.html', video=self))
15 |
16 |
17 | def youtube(*args, **kwargs):
18 | video = Video(*args, **kwargs)
19 | return video.html
20 |
21 |
22 | class Youtube(object):
23 | def __init__(self, app=None, **kwargs):
24 | if app:
25 | self.init_app(app)
26 |
27 | def init_app(self, app):
28 | self.register_blueprint(app)
29 | app.add_template_global(youtube)
30 |
31 | def register_blueprint(self, app):
32 | module = Blueprint(
33 | "youtube",
34 | __name__,
35 | template_folder="templates"
36 | )
37 | app.register_blueprint(module)
38 | return module
39 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/Flask-YouTube/flask_youtube/templates/youtube/video.html:
--------------------------------------------------------------------------------
1 | VIDEO
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/Flask-YouTube/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import setup, find_packages
2 |
3 | setup(
4 | name='Flask-YouTube',
5 | version='0.1',
6 | license='MIT',
7 | description='Flask extension to allow easy embedding of YouTube videos',
8 | author='Jack Stouffer',
9 | author_email='example@gmail.com',
10 | platforms='any',
11 | install_requires=['Flask'],
12 | packages=find_packages()
13 | )
14 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/Procfile:
--------------------------------------------------------------------------------
1 | web: uwsgi uwsgi.ini
2 | celery: celery worker -A celery_runner
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/application.py:
--------------------------------------------------------------------------------
1 | from webapp import create_app
2 |
3 | application = create_app("webapp.config.ProdConfig")
4 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/celery_runner.py:
--------------------------------------------------------------------------------
1 | import os
2 | from webapp import create_app
3 | from celery import Celery
4 |
5 |
6 | def make_celery(app):
7 | celery = Celery(
8 | app.import_name,
9 | broker=app.config['CELERY_BROKER_URL'],
10 | backend=app.config['CELERY_BACKEND_URL']
11 | )
12 | celery.conf.update(app.config)
13 | TaskBase = celery.Task
14 |
15 | class ContextTask(TaskBase):
16 | abstract = True
17 |
18 | def __call__(self, *args, **kwargs):
19 | with app.app_context():
20 | return TaskBase.__call__(self, *args, **kwargs)
21 |
22 | celery.Task = ContextTask
23 |
24 | return celery
25 |
26 | env = os.environ.get('WEBAPP_ENV', 'dev')
27 | flask_app = create_app('webapp.config.%sConfig' % env.capitalize())
28 |
29 | celery = make_celery(flask_app)
30 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/gserver.py:
--------------------------------------------------------------------------------
1 | from gevent.wsgi import WSGIServer
2 | from webapp import create_app
3 |
4 | app = create_app('webapp.config.ProdConfig')
5 |
6 | server = WSGIServer(('', 80), app)
7 | server.serve_forever()
8 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/nginx.conf:
--------------------------------------------------------------------------------
1 | server {
2 | listen 80;
3 | server_name your_domain_name;
4 |
5 | location / {
6 | include uwsgi_params;
7 | uwsgi_pass 127.0.0.1:8080;
8 | }
9 |
10 | location /static {
11 | alias /home/deploy/webapp/webapp/static;
12 | }
13 | }
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/requirements.txt:
--------------------------------------------------------------------------------
1 | alembic==0.7.6
2 | amqp==1.4.6
3 | celery==3.1.18
4 | coverage==3.7.1
5 | cssmin==0.2.0
6 | Fabric==1.10.2
7 | Flask==0.10.1
8 | Flask-Admin==1.1.0
9 | Flask-Assets==0.10
10 | Flask-Bcrypt==0.6.2
11 | Flask-Cache==0.13.1
12 | Flask-Celery-Helper==1.1.0
13 | Flask-DebugToolbar==0.10.0
14 | Flask-Login==0.2.11
15 | Flask-Mail==0.9.1
16 | Flask-Migrate==1.4.0
17 | flask-mongoengine==0.7.1
18 | Flask-OAuth==0.12
19 | Flask-OpenID==1.2.4
20 | Flask-Principal==0.4.0
21 | Flask-RESTful==0.3.3
22 | Flask-Script==2.0.5
23 | Flask-SQLAlchemy==2.0
24 | Flask-WTF==0.11
25 | Jinja2==2.7.3
26 | jsmin==2.1.1
27 | mongoengine==0.9.0
28 | python-openid==2.2.5
29 | selenium==2.46.0
30 | SQLAlchemy==1.0.4
31 | uWSGI==2.0.11
32 | webassets==0.10.1
33 | Werkzeug==0.10.4
34 | WTForms==2.0.2
35 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/run_test_server.py:
--------------------------------------------------------------------------------
1 | from webapp import create_app
2 | from webapp.models import db, User, Role
3 |
4 | app = create_app('webapp.config.TestConfig')
5 |
6 | db.app = app
7 | db.create_all()
8 |
9 | default = Role("default")
10 | poster = Role("poster")
11 | db.session.add(default)
12 | db.session.add(poster)
13 | db.session.commit()
14 |
15 | test_user = User("test")
16 | test_user.set_password("test")
17 | test_user.roles.append(poster)
18 | db.session.add(test_user)
19 | db.session.commit()
20 |
21 | app.run()
22 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/runtime.txt:
--------------------------------------------------------------------------------
1 | python-2.7.10
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/supervisor.conf:
--------------------------------------------------------------------------------
1 | [program:webapp]
2 | command=python gserver.py
3 | directory=/home/deploy/webapp
4 | user=deploy
5 |
6 | [program:rabbitmq]
7 | command=rabbitmq-server
8 | user=deploy
9 |
10 | [program:celery]
11 | command=celery worker -A celery_runner
12 | directory=/home/deploy/webapp
13 | user=deploy
14 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/tests/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter13/Chapter 13/tests/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/tserver.py:
--------------------------------------------------------------------------------
1 | from tornado.wsgi import WSGIContainer
2 | from tornado.httpserver import HTTPServer
3 | from tornado.ioloop import IOLoop
4 | from webapp import create_app
5 |
6 | app = WSGIContainer(create_app("webapp.config.ProdConfig"))
7 | http_server = HTTPServer(app)
8 | http_server.listen(80)
9 | IOLoop.instance().start()
10 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/uwsgi.ini:
--------------------------------------------------------------------------------
1 | [uwsgi]
2 | http-socket = :$(PORT)
3 | die-on-term = true
4 | wsgi-file = wsgi.py
5 | callable = app
6 | processes = 4
7 | threads = 2
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/webapp/controllers/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter13/Chapter 13/webapp/controllers/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/webapp/controllers/rest/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter13/Chapter 13/webapp/controllers/rest/__init__.py
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/webapp/controllers/rest/auth.py:
--------------------------------------------------------------------------------
1 | from flask import abort, current_app
2 | from flask.ext.restful import Resource
3 |
4 | from webapp.models import User
5 | from .parsers import user_post_parser
6 |
7 | from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
8 |
9 |
10 | class AuthApi(Resource):
11 | def post(self):
12 | args = user_post_parser.parse_args()
13 | user = User.query.filter_by(username=args['username']).one()
14 |
15 | if user.check_password(args['password']):
16 | s = Serializer(current_app.config['SECRET_KEY'], expires_in=604800)
17 | return {"token": s.dumps({'id': user.id})}
18 | else:
19 | abort(401)
20 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/webapp/controllers/rest/fields.py:
--------------------------------------------------------------------------------
1 | from HTMLParser import HTMLParser
2 | from flask.ext.restful import fields
3 |
4 |
5 | class HTMLStripper(HTMLParser):
6 | def __init__(self):
7 | self.reset()
8 | self.fed = []
9 |
10 | def handle_data(self, d):
11 | self.fed.append(d)
12 |
13 | def get_data(self):
14 | return ''.join(self.fed)
15 |
16 |
17 | def strip_tags(html):
18 | s = HTMLStripper()
19 | s.feed(html)
20 |
21 | return s.get_data()
22 |
23 |
24 | class HTMLField(fields.Raw):
25 | def format(self, value):
26 | return strip_tags(str(value))
27 |
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/webapp/static/.webassets-cache/49d7031c832760f1c8af0e8f1f9a1954:
--------------------------------------------------------------------------------
1 | S'331a10ae21d04e9646dd1280cfd734b1'
2 | p1
3 | .
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/webapp/static/.webassets-cache/592e4efb9c5f8cd91720dd6d646679e7:
--------------------------------------------------------------------------------
1 | S'1cbf25481f487566bb2ac19ee9816a46'
2 | p1
3 | .
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/webapp/static/.webassets-cache/677b6b8fc43f52ebf6307be93396d33b:
--------------------------------------------------------------------------------
1 | S'e5dc859d'
2 | p1
3 | .
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/webapp/static/.webassets-cache/efe2845331acfbfa19510a0d780942a5:
--------------------------------------------------------------------------------
1 | S'549042f1'
2 | p1
3 | .
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/webapp/static/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter13/Chapter 13/webapp/static/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/webapp/static/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter13/Chapter 13/webapp/static/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/webapp/static/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter13/Chapter 13/webapp/static/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/webapp/static/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Chapter13/Chapter 13/webapp/static/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/webapp/templates/admin/custom.html:
--------------------------------------------------------------------------------
1 | {% extends 'admin/master.html' %}
2 |
3 | {% block body %}
4 | This is the custom view!
5 |
6 | Link
7 | {% endblock %}
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/webapp/templates/admin/post_edit.html:
--------------------------------------------------------------------------------
1 | {% extends 'admin/model/edit.html' %}
2 | {% block tail %}
3 | {{ super() }}
4 |
5 | {% endblock %}
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/webapp/templates/admin/second_page.html:
--------------------------------------------------------------------------------
1 | {% extends 'admin/master.html' %}
2 |
3 | {% block body %}
4 | This is the second page!
5 |
6 | Link
7 | {% endblock %}
--------------------------------------------------------------------------------
/Module 3/Chapter13/Chapter 13/wsgi.py:
--------------------------------------------------------------------------------
1 | from webapp import create_app
2 |
3 | app = create_app("webapp.config.ProdConfig")
4 |
--------------------------------------------------------------------------------
/Module 3/Software Hardware List.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Module 3/Software Hardware List.docx
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flask-Building-Python-Web-Services/9c309b0f3721b27de4648d8d4b72dcc577eda39b/Readme.md
--------------------------------------------------------------------------------