Permalink
Browse files

Flask-Cache & DEBUG Toolbar

  • Loading branch information...
rochacbruno committed Oct 20, 2015
1 parent 1359c4c commit 27bacd25a788ffc041de332403a2426cd199b828
Showing with 36 additions and 3 deletions.
  1. +3 −1 requirements.txt
  2. +8 −1 wtf/blueprints/noticias.py
  3. +2 −0 wtf/cache.py
  4. +18 −0 wtf/development_instance/config.cfg
  5. +5 −1 wtf/news_app.py
View
@@ -1,7 +1,9 @@
https://github.com/mitsuhiko/flask/tarball/master
flask-mongoengine
https://github.com/MongoEngine/flask-mongoengine/tarball/master
nose
Flask-Bootstrap
Flask-Security
Flask-Login==0.2.11
Flask-Admin
flask-debugtoolbar
flask-cache
@@ -5,6 +5,7 @@
Blueprint, request, current_app, send_from_directory, render_template
)
from ..models import Noticia
from ..cache import cache
from flask_security import login_required
noticias_blueprint = Blueprint('noticias', __name__)
@@ -28,6 +29,7 @@ def cadastro():
@noticias_blueprint.route("/")
@cache.cached(timeout=300)
def index():
todas_as_noticias = Noticia.objects.all()
return render_template('index.html',
@@ -37,7 +39,12 @@ def index():
@noticias_blueprint.route("/noticia/<noticia_id>")
def noticia(noticia_id):
noticia = Noticia.objects.get(id=noticia_id)
noticia_cacheada = cache.get(noticia_id)
if noticia_cacheada:
noticia = noticia_cacheada
else:
noticia = Noticia.objects.get(id=noticia_id)
cache.set(noticia_id, noticia, timeout=300)
return render_template('noticia.html', noticia=noticia)
View
@@ -0,0 +1,2 @@
from flask_cache import Cache
cache = Cache(config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': '/tmp'})
@@ -19,3 +19,21 @@ SECURITY_TRACKABLE = True
SECURITY_SEND_REGISTER_EMAIL = False
SECURITY_LOGIN_WITHOUT_CONFIRMATION = True
SECURITY_CHANGEABLE = True
DEBUG = True
DEBUG_TOOLBAR_ENABLED = True
DEBUG_TB_INTERCEPT_REDIRECTS = False
DEBUG_TB_PROFILER_ENABLED = True
DEBUG_TB_TEMPLATE_EDITOR_ENABLED = True
DEBUG_TB_PANELS = (
'flask_debugtoolbar.panels.versions.VersionDebugPanel',
'flask_debugtoolbar.panels.timer.TimerDebugPanel',
'flask_debugtoolbar.panels.headers.HeaderDebugPanel',
'flask_debugtoolbar.panels.request_vars.RequestVarsDebugPanel',
'flask_debugtoolbar.panels.template.TemplateDebugPanel',
'flask_mongoengine.panels.MongoDebugPanel',
'flask_debugtoolbar.panels.logger.LoggingPanel',
'flask_debugtoolbar.panels.profiler.ProfilerDebugPanel',
'flask_debugtoolbar.panels.config_vars.ConfigVarsDebugPanel',
)
View
@@ -3,11 +3,13 @@
from flask import Flask
from flask_bootstrap import Bootstrap
from flask_security import Security, MongoEngineUserDatastore
from .admin import configure_admin
from flask_debugtoolbar import DebugToolbarExtension
from .admin import configure_admin
from .blueprints.noticias import noticias_blueprint
from .db import db
from .security_models import User, Role
from .cache import cache
def create_app(mode):
@@ -34,4 +36,6 @@ def create_app(mode):
db.init_app(app)
Security(app=app, datastore=MongoEngineUserDatastore(db, User, Role))
configure_admin(app)
DebugToolbarExtension(app)
cache.init_app(app)
return app

0 comments on commit 27bacd2

Please sign in to comment.