Todo se fue a docker igual que el otro repo

Decidi pasar todo esto a docker igual para tener todo ahi, parece mas
ordenado y mas facil de mantener en mi servidor

de paso tambien hice el trabajo de pasar los modelos a sqlalchemy para
usar mysql :3
This commit is contained in:
Daniel Cortes
2019-03-15 03:16:59 -03:00
parent 6b34e909f2
commit c9ffcb8dca
22 changed files with 253 additions and 264 deletions

View File

@@ -1,23 +1,16 @@
from flask import (
Blueprint, flash, g, redirect, render_template, request, url_for
)
from flask import Blueprint, flash, redirect, render_template, request, url_for
from werkzeug.exceptions import abort
import markdown as md
from www.db import get_db
from www.auth import admin_required
from www.models import db, Post
from www.auth import admin_required
bp = Blueprint('blog', __name__, url_prefix='/blog')
@bp.route('/')
def index():
db = get_db()
posts = db.execute(
'SELECT id, title, resume, created_at'
' FROM posts'
' ORDER BY created_at DESC'
).fetchall()
posts = Post.query.order_by(Post.created_at.desc()).all()
return render_template('blog/index.html', posts=posts)
@@ -38,13 +31,10 @@ def create():
if error is not None:
flash(error)
else:
db = get_db()
db.execute(
'INSERT INTO posts (title, markdown, html, resume)'
' VALUES (?, ?, ?, ?)',
(title, markdown, html, resume)
)
db.commit()
post = Post(title, markdown, html, resume)
db.session.add(post)
db.session.commit()
return redirect(url_for('blog.index'))
return render_template('blog/create.html')
@@ -52,12 +42,7 @@ def create():
@bp.route('/update/<int:id>', methods=('GET', 'POST'))
@admin_required
def update(id):
post = get_db().execute(
'SELECT id, title, markdown, resume'
' FROM posts'
' WHERE id = ?',
(id,)
).fetchone()
post = Post.query.get(id)
if post is None:
abort(404)
@@ -76,55 +61,37 @@ def update(id):
if error is not None:
flash(error)
else:
db = get_db()
db.execute(
'UPDATE posts'
' SET title = ?, markdown = ?, html = ?, resume = ?'
' WHERE id = ?',
(title, markdown, html, resume, id)
)
db.commit()
post.title = title
post.markdown = markdown
post.html = html
post.resume = resume
db.session.commit()
return redirect(url_for('blog.index'))
return render_template('blog/update.html', post=post)
@bp.route('/<int:id>')
def view(id):
post = get_db().execute(
'SELECT id, title, html'
' FROM posts'
' WHERE id = ?',
(id,)
).fetchone()
post = Post.query.get(id)
if post is None:
abort(404)
else:
return render_template('blog/view.html', post=post)
@bp.route('/delete/<int:id>', methods=('GET', 'POST',))
@bp.route('/delete/<int:id>', methods=['POST'])
@admin_required
def delete(id):
if request.method == 'GET':
abort(404)
post = Post.query.get(id)
db = get_db()
post = db.execute(
'SELECT id'
' FROM posts'
' WHERE id = ?',
(id,)
).fetchone()
print(post)
if post is None:
abort(404)
else:
db.execute('DELETE FROM posts WHERE id = ?', (id,))
db.commit()
db.session.delete(post)
db.session.commit()
return redirect(url_for('blog.index'))
def parse_markdown(markdown):
html = md.markdown(markdown)
html = md.markdown(markdown)
return html