Work on blog
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from flask import Blueprint, render_template, session, redirect, url_for, request, flash, abort, Flask
|
||||
from flask import Blueprint, render_template, session, redirect, url_for, request, flash, abort, Flask, make_response
|
||||
import time
|
||||
from markupsafe import escape
|
||||
import sqlite3
|
||||
@@ -24,6 +24,9 @@ DOSSIER_PERSO = app.config.get('DOSSIER_APP')+'/'
|
||||
DOSSIER_PUBLIC = app.config.get('DOSSIER_PUBLIC')+'/'
|
||||
TITLE_SERVER = app.config.get('TITLE_SERVER')
|
||||
DESC_SERVER = app.config.get('DESC_SERVER')
|
||||
MARKDOWN_EXT=["extra", "toc", "codehilite",
|
||||
"nl2br", "extra", "admonition",
|
||||
"sane_lists", "smarty"]
|
||||
################################################################################
|
||||
|
||||
@blog.route('/myblog/new-article/', methods=['GET', 'POST'])
|
||||
@@ -82,6 +85,28 @@ def edit(title):
|
||||
oldpost=post)
|
||||
|
||||
|
||||
@blog.route('/myblog/update/<title>', methods=['POST'])
|
||||
@login_required
|
||||
def update(title):
|
||||
user='%s'% escape(session['username'])
|
||||
folder_blog = DOSSIER_PERSO + user + "/blog/articles/"
|
||||
newtitle = str(request.form['title'])
|
||||
subtitle = str(request.form['subtitle'])
|
||||
category = str(request.form['category'])
|
||||
newcontent = str(request.form['content'])
|
||||
newstatus = str(request.form['status'])
|
||||
updated = time.strftime("%d/%m/%Y à %H:%M:%S")
|
||||
conn = sqlite3.connect(DATABASE)
|
||||
cursor = conn.cursor()
|
||||
if 'blog-unified' in request.form.keys():
|
||||
newstatus = newstatus+'_unified'
|
||||
|
||||
cursor.execute("""UPDATE Blog_posts SET title=?, subtitle=?, category=?, last_updated=?, status=?, content=? WHERE title=? AND author=?""", (newtitle, subtitle, category, updated, newstatus, newcontent, title, user))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
response = """ <p class="center success" >Article mis à jour le """+ updated +""" .</p>"""
|
||||
return response
|
||||
|
||||
@blog.route('/myblog/list-articles/', methods=['GET'])
|
||||
@login_required
|
||||
def list_articles_blog():
|
||||
@@ -239,7 +264,7 @@ def viewauthorrss(author):
|
||||
if list_posts != None:
|
||||
last_build=last_article_date[0]
|
||||
for post in list_posts:
|
||||
posts=[dict(title=post[0], subtitle=post[1], content=markdown(post[2]), creation_date=post[3], author=post[4], status=post[5])] + posts
|
||||
posts=[dict(title=post[0], subtitle=post[1], content=markdown(post[2], extensions=MARKDOWN_EXT), creation_date=post[3], author=post[4], status=post[5])] + posts
|
||||
|
||||
return render_template('blog_rss.xml',
|
||||
base_url=BASE_URL,
|
||||
@@ -261,7 +286,7 @@ def viewPrivateArticle(username, title):
|
||||
conn.close()
|
||||
if post != None:
|
||||
post_info = (dict(title=post[0], subtitle=post[1], creation_date=post[3], last_updated=post[4],author=post[5]))
|
||||
content = markdown(post[2])
|
||||
content = markdown(post[2], extensions=MARKDOWN_EXT)
|
||||
return render_template('blog.html', post_info=post_info, content=content)
|
||||
else:
|
||||
return redirect(url_for('blog'), code=404)
|
||||
@@ -278,7 +303,7 @@ def viewArticle(username, title):
|
||||
conn.close()
|
||||
if post != None:
|
||||
post_info = (dict(title=post[0], subtitle=post[1], creation_date=post[3], last_updated=post[4],author=post[5]))
|
||||
content= markdown(post[2])
|
||||
content= markdown(post[2], extensions=MARKDOWN_EXT)
|
||||
|
||||
return render_template('blog.html', post_info=post_info, content=content)
|
||||
else:
|
||||
@@ -299,7 +324,7 @@ def viewrss():
|
||||
if list_posts != None:
|
||||
last_build=last_article_date[0]
|
||||
for post in list_posts:
|
||||
posts=[dict(title=post[0], subtitle=post[1], content=markdown(post[2]), creation_date=post[3], author=post[4], status=post[5])] + posts
|
||||
posts=[dict(title=post[0], subtitle=post[1], content=markdown(post[2], extensions=MARKDOWN_EXT), creation_date=post[3], author=post[4], status=post[5])] + posts
|
||||
|
||||
return render_template('blog_rss.xml',
|
||||
base_url=BASE_URL,
|
||||
|
||||
Reference in New Issue
Block a user