diff --git a/.travis.yml b/.travis.yml index 25ba6bf..cf10381 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: python python: - - 3.5.1 + - 3.6 cache: pip diff --git a/README.md b/README.md index e8b87d2..9aa2262 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[](https://travis-ci.org/rafaelhenrique/flask_tutorial) +[](https://travis-ci.org/python-sorocaba/flask_tutorial) # Flask Tutorial @@ -40,6 +40,34 @@ $ python manage.py runserver More information? Follow explanatory videos below. +## How to execute queries manually? + +Inside on your virtualenv: +``` +$ python manage.py shell +``` + +Import db and model: +``` +from tvseries.ext import db +from tvseries.core.models import TVSerie +``` + +Bind your session with your application: +``` +db.app = app +``` + +Quering example: +``` +db.session.query(TVSerie).all() +``` + +If operation is "create", "update" or "delete" dont forget to run commit operation to confirm operation: +``` +db.session.commit() +``` + ## 1.0 - Flask and the most basic application of the world! - See release code: https://github.com/rafaelhenrique/flask_tutorial/tree/1.0 @@ -112,3 +140,11 @@ More information? Follow explanatory videos below. - See explanation about release: https://github.com/rafaelhenrique/flask_tutorial/releases/tag/12.0 - See video: https://www.youtube.com/watch?v=t4dGoI4S4SE +## 13.0 - Working with forms! + +- See release code: https://github.com/rafaelhenrique/flask_tutorial/tree/13.0 +- See explanation about release: https://github.com/rafaelhenrique/flask_tutorial/releases/tag/13.0 +- See videos: + - https://www.youtube.com/watch?v=ffJ3ia8SZds + - https://www.youtube.com/watch?v=5-fUl-_ODhg + diff --git a/requirements.txt b/requirements.txt index ef7c4a9..d81eb6c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ pytest-flask==0.10.0 python-decouple==3.0 uWSGI==2.0.14 Flask-Collect==1.3.2 -ansible==2.2.0.0 +ansible==2.7.1 Flask-Migrate==2.0.1 -psycopg2==2.6.2 +psycopg2==2.7.5 +Flask-WTF==0.13.1 diff --git a/tvseries/__init__.py b/tvseries/__init__.py index eeda833..4f1a4a1 100644 --- a/tvseries/__init__.py +++ b/tvseries/__init__.py @@ -1,7 +1,7 @@ from flask import Flask from tvseries import config -from tvseries.ext import db +from tvseries.ext import db, csrf from tvseries.core import core_blueprint @@ -10,4 +10,5 @@ def create_app(config=config.ProductionConfig): app.config.from_object(config) app.register_blueprint(core_blueprint, url_prefix='/') db.init_app(app) + csrf.init_app(app) return app diff --git a/tvseries/config.py b/tvseries/config.py index daa8efb..3d13fd4 100644 --- a/tvseries/config.py +++ b/tvseries/config.py @@ -11,6 +11,7 @@ class BaseConfig(object): SQLALCHEMY_TRACK_MODIFICATIONS = True COLLECT_STATIC_ROOT = os.path.join(BASE_DIR, "static") COLLECT_STORAGE = 'flask_collect.storage.file' + WTF_CSRF_ENABLED = True DEBUG = False TESTING = False @@ -22,6 +23,7 @@ class DevelopmentConfig(BaseConfig): class TestConfig(BaseConfig): SQLALCHEMY_DATABASE_URI = 'sqlite:///tvseries-test.sqlite3' TESTING = True + WTF_CSRF_ENABLED = False class ProductionConfig(BaseConfig): diff --git a/tvseries/core/forms.py b/tvseries/core/forms.py new file mode 100644 index 0000000..dccd3d0 --- /dev/null +++ b/tvseries/core/forms.py @@ -0,0 +1,10 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, DateField + + +class TVSerieForm(FlaskForm): + name = StringField('name') + description = StringField('description') + episodies_number = StringField('episodies_number') + author = StringField('author') + year = DateField('year') diff --git a/tvseries/core/templates/add.html b/tvseries/core/templates/add.html index ff38af4..2d7fca6 100644 --- a/tvseries/core/templates/add.html +++ b/tvseries/core/templates/add.html @@ -1,6 +1,7 @@ {% extends 'base.html' %} {% block content %} -