Permalink
Browse files

blueprints added

  • Loading branch information...
rochacbruno committed Jun 19, 2014
1 parent f0c6e91 commit 315c7af699bb215b53299c43af017becb7c1a8c2
View
No changes.
@@ -1,13 +1,15 @@
# coding: utf-8
import os
from werkzeug import secure_filename
from flask import request, current_app, send_from_directory, render_template
from flask import (
Blueprint, request, current_app, send_from_directory, render_template
)
from db import noticias
from news_app import app
noticias_blueprint = Blueprint('noticias', __name__)
@app.route("/noticias/cadastro", methods=["GET", "POST"])
@noticias_blueprint.route("/noticias/cadastro", methods=["GET", "POST"])
def cadastro():
if request.method == "POST":
@@ -27,20 +29,20 @@ def cadastro():
return render_template('cadastro.html', title=u"Inserir nova noticia")
@app.route("/")
@noticias_blueprint.route("/")
def index():
todas_as_noticias = noticias.all()
return render_template('index.html',
noticias=todas_as_noticias,
title=u"Todas as notícias")
@app.route("/noticia/<int:noticia_id>")
@noticias_blueprint.route("/noticia/<int:noticia_id>")
def noticia(noticia_id):
noticia = noticias.find_one(id=noticia_id)
return render_template('noticia.html', noticia=noticia)
@app.route('/media/<path:filename>')
@noticias_blueprint.route('/media/<path:filename>')
def media(filename):
return send_from_directory(current_app.config.get('MEDIA_ROOT'), filename)
View
@@ -1,7 +1,7 @@
# coding: utf-8
from flask import Flask
from blueprints.noticias import noticias_blueprint
app = Flask("wtf")
app.config.from_object('settings')
import views
app.register_blueprint(noticias_blueprint)
View
@@ -5,9 +5,9 @@
<body>
<img src="{{url_for('static', filename='generic_logo.gif')}}">
<nav>
<a href="{{url_for('index')}}">HOME</a> | <a href="{{url_for('cadastro')}}">CADASTRO</a>
<a href="{{url_for('noticias.index')}}">HOME</a> | <a href="{{url_for('noticias.cadastro')}}">CADASTRO</a>
</nav>
<hr />
{% block content %} {% endblock %}
</body>
</html>
</html>
View
@@ -1,6 +1,6 @@
{% extends "base.html" %}
{% block content %}
<form method="post" action="{{ url_for('cadastro') }}" enctype="multipart/form-data">
<form method="post" action="{{ url_for('noticias.cadastro') }}" enctype="multipart/form-data">
<label>Titulo:<br />
<input type="text" name="titulo" id="titulo" />
</label>
@@ -14,4 +14,4 @@
</label>
<input type="submit" value="Postar" />
</form>
{% endblock %}
{% endblock %}
@@ -5,6 +5,6 @@
{% block content %}
<h1>Notícia {{id_nova_noticia}} inserida com sucesso!</h1>
<a href="{{url_for('noticia', noticia_id=id_nova_noticia)}}"> Ler Notícia </a><br />
<a href="{{url_for('cadastro')}}"> Cadastrar nova notícia </a>
{% endblock %}
<a href="{{url_for('noticias.noticia', noticia_id=id_nova_noticia)}}"> Ler Notícia </a><br />
<a href="{{url_for('noticias.cadastro')}}"> Cadastrar nova notícia </a>
{% endblock %}
View
@@ -3,10 +3,10 @@
<ul>
{% for noticia in noticias %}
<li>
<a href="{{url_for('noticia', noticia_id=noticia.id)}}">
<a href="{{url_for('noticias.noticia', noticia_id=noticia.id)}}">
{{noticia.titulo}}
</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% endblock %}
View
@@ -6,10 +6,10 @@
{% block content %}
<h1>{{noticia.titulo}}</h1>
{% if noticia.imagem %}
<img src="{{ url_for('media', filename=noticia.imagem) }}" width="300" />
<img src="{{ url_for('noticias.media', filename=noticia.imagem) }}" width="300" />
{% endif %}
<hr />
<p>
{{noticia.texto}}
</p>
{% endblock %}
{% endblock %}

0 comments on commit 315c7af

Please sign in to comment.