Permalink
Browse files

modified views

  • Loading branch information...
rochacbruno committed Oct 16, 2015
1 parent 88effa0 commit 189f4d4d2c8af845ccc0b181e4f6a1831578fbfa
Showing with 8 additions and 13 deletions.
  1. +6 −13 wtf/blueprints/noticias.py
  2. +2 −0 wtf/news_app.py
View
@@ -4,45 +4,38 @@
from flask import (
Blueprint, request, current_app, send_from_directory, render_template
)
from ..db import get_table
from ..models import Noticia
noticias_blueprint = Blueprint('noticias', __name__)
@noticias_blueprint.route("/noticias/cadastro", methods=["GET", "POST"])
def cadastro():
noticias = get_table('noticias')
if request.method == "POST":
dados_do_formulario = request.form.to_dict()
imagem = request.files.get('imagem')
if imagem:
filename = secure_filename(imagem.filename)
path = os.path.join(current_app.config['MEDIA_ROOT'], filename)
imagem.save(path)
dados_do_formulario['imagem'] = filename
id_nova_noticia = noticias.insert(dados_do_formulario)
nova_noticia = Noticia.objects.create(**dados_do_formulario)
return render_template('cadastro_sucesso.html',
id_nova_noticia=id_nova_noticia)
id_nova_noticia=nova_noticia.id)
return render_template('cadastro.html', title=u"Inserir nova noticia")
@noticias_blueprint.route("/")
def index():
noticias = get_table('noticias')
todas_as_noticias = noticias.all()
todas_as_noticias = Noticia.objects.all()
return render_template('index.html',
noticias=todas_as_noticias,
title=u"Todas as notícias")
@noticias_blueprint.route("/noticia/<int:noticia_id>")
@noticias_blueprint.route("/noticia/<noticia_id>")
def noticia(noticia_id):
noticias = get_table('noticias')
noticia = noticias.find_one(id=noticia_id)
noticia = Noticia.objects.get(id=noticia_id)
return render_template('noticia.html', noticia=noticia)
View
@@ -3,6 +3,7 @@
from flask import Flask
from .blueprints.noticias import noticias_blueprint
from flask_bootstrap import Bootstrap
from db import db
def create_app(mode):
@@ -26,4 +27,5 @@ def create_app(mode):
app.register_blueprint(noticias_blueprint)
Bootstrap(app)
db.init_app(app)
return app

0 comments on commit 189f4d4

Please sign in to comment.