Compare commits
7
Commits
b11947bb7e
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73e3b67df2 | ||
|
|
689c142d2e | ||
|
|
b2dbe5c8c9 | ||
|
|
281350bee9 | ||
|
|
6b8d33d508 | ||
|
|
8281152154 | ||
|
|
cb713f5bf7 |
@@ -5,19 +5,18 @@
|
|||||||
xmlns:atom="http://www.w3.org/2005/Atom"
|
xmlns:atom="http://www.w3.org/2005/Atom"
|
||||||
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
|
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
|
||||||
xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
|
xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
|
||||||
<channel>
|
|
||||||
|
<channel>
|
||||||
<title> Le blog de {{ blog_name }} </title>
|
<title> Le blog de {{ blog_name }} </title>
|
||||||
<link> {{ base_url }}/blog/ </link>
|
<link> {{ base_url }}/blog/ </link>
|
||||||
{% if blog_description %}
|
|
||||||
<description> {{ blog_description }} </description>
|
<description> {{ blog_description }} </description>
|
||||||
{% endif %}
|
|
||||||
<language>fr</language>
|
<language>fr</language>
|
||||||
<lastBuildDate> {{ last_build_date }} </lastBuildDate>
|
|
||||||
|
<atom:link href="{{base_url}}blog/{%if user %}{{ user }}/{% endif %}rss.xml" rel="self" type="application/rss+xml" />
|
||||||
{% for post in posts %}
|
{% for post in posts %}
|
||||||
<item>
|
<item>
|
||||||
<title> {{ post.title }} </title>
|
<title> {{ post.title }} </title>
|
||||||
<pubdate> {% if post.last_updated %} {{ post.last_updated }} {% else %} {{ post.time }} {% endif %} </pubdate>
|
<pubDate>{% if post.last_updated %}{{ post.last_updated }}{% else %}{{ post.creation_date }}{% endif %}</pubDate>
|
||||||
<link> {{base_url}}/{{ url_for('blog.viewArticle', username=post.author, title_id=post.title_id) }}</link>
|
<link> {{base_url}}/{{ url_for('blog.viewArticle', username=post.author, title_id=post.title_id) }}</link>
|
||||||
<guid> {{base_url}}/{{ url_for('blog.viewArticle', username=post.author, title_id=post.title_id) }} </guid>
|
<guid> {{base_url}}/{{ url_for('blog.viewArticle', username=post.author, title_id=post.title_id) }} </guid>
|
||||||
|
|
||||||
@@ -26,7 +25,7 @@
|
|||||||
</description>
|
</description>
|
||||||
|
|
||||||
<content:encoded>
|
<content:encoded>
|
||||||
{{ post.content | safe }}
|
{{ post.content }}
|
||||||
</content:encoded>
|
</content:encoded>
|
||||||
</item>
|
</item>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -16,31 +16,49 @@
|
|||||||
|
|
||||||
<form method="POST" action="{{ url_for('blog.new_article') }}" id="postform">
|
<form method="POST" action="{{ url_for('blog.new_article') }}" id="postform">
|
||||||
|
|
||||||
<input type="text" name="title" id="title" placeholder="Titre" class="form-control"><br />
|
<input type="text" name="title" id="title" placeholder="titre" class="form-control" value="{{ title }}"><br />
|
||||||
<input type="text" name="subtitle" id="subtitle" placeholder="Sous-titre" class="form-control"><br />
|
<input type="text" name="subtitle" id="subtitle" placeholder="sous-titre" class="form-control" value="{{ subtitle }}"><br />
|
||||||
<input type="text" name="category" id="category" placeholder="Catégories #hashtag" class="form-control"><br />
|
<input type="text" name="category" id="category" placeholder="Catégorie" class="form-control" value="{{ category }}"><br />
|
||||||
<hr>
|
<textarea id="editeurMarkdown" class="form-control" form="postform" name="content" placeholder="Contenu" style="height:20vw;">
|
||||||
<textarea id="editeurMarkdown" class="form-control" form="postform" name="content" id="content" placeholder="Contenu" style="height:20vw; margin-right:2vw;"></textarea><br />
|
{{ content }}</textarea>
|
||||||
|
<br />
|
||||||
<h3> Visibilité </h3>
|
<h3> Visibilité </h3>
|
||||||
|
|
||||||
<div class="center">
|
<div class="center">
|
||||||
<p> Les articles brouillons ne sont visibles que par vous même</p>
|
<p> Les articles brouillons ne sont visibles que par vous même</p>
|
||||||
<p> Les articles privés ne sont visibles que par les membres du serveur </p>
|
<p> Les articles privés ne sont visibles que par les membres du serveur </p>
|
||||||
<p> Les articles public sont visibles par tout le monde </p>
|
<p> Les articles public sont visibles par tout le monde </p>
|
||||||
|
|
||||||
|
|
||||||
|
{% if status == 'public' or status == "public_unified" %}
|
||||||
<input type="radio" name="status" value="draft"> Brouillon
|
<input type="radio" name="status" value="draft"> Brouillon
|
||||||
<input type="radio" name="status" value="private" checked> Privé
|
<input type="radio" name="status" value="private"> Privé
|
||||||
<input type="radio" name="status" value="public">Public<br>
|
<input type="radio" name="status" value="public" checked> Publique
|
||||||
|
|
||||||
|
{% elif status == 'private' or status == "private_unified" %}
|
||||||
|
<input type="radio" name="status" value="draft"> Brouillon
|
||||||
|
<input type="radio" name="status" value="private" checked> Privé
|
||||||
|
<input type="radio" name="status" value="public"> Publique
|
||||||
|
{% else %}
|
||||||
|
<input type="radio" name="status" value="draft" checked> Brouillon
|
||||||
|
<input type="radio" name="status" value="private"> Privé
|
||||||
|
<input type="radio" name="status" value="public"> Publique
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label>
|
<label>
|
||||||
|
|
||||||
<input id="blog-unified" name="blog-unified" type="checkbox" role="switch" />
|
{% if status == "private_unified" or status == "public_unified" %}
|
||||||
Publier cet article dans le blog général
|
<input id="blog-unified" name="blog-unified" type="checkbox" role="switch" checked />
|
||||||
</label>
|
{% else %}
|
||||||
</fieldset>
|
<input id="blog-unified" name="blog-unified" type="checkbox" role="switch" />
|
||||||
|
{% endif %}
|
||||||
|
Publier cet article dans le blog général
|
||||||
|
</label>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
<button type="submit"> Créer l'article </button>
|
<button type="submit"> Créer l'article </button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
from flask import Flask
|
||||||
|
import sqlite3
|
||||||
|
import string
|
||||||
|
import time
|
||||||
|
|
||||||
|
app = Flask( 'pywallter' )
|
||||||
|
app.config.from_pyfile('config.py')
|
||||||
|
|
||||||
|
|
||||||
|
DATABASE = app.config['DATABASE']
|
||||||
|
DOSSIER_PERSO = app.config['DOSSIER_APP']
|
||||||
|
DATABASE = app.config['DATABASE']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def article_exist(title_id : str, author : str ) -> bool:
|
||||||
|
conn = sqlite3.connect(DATABASE)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("""SELECT title FROM Blog_posts WHERE title_id=? AND author=?""", (title_id, author))
|
||||||
|
article = cursor.fetchone()
|
||||||
|
if article != None:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
from flask import Flask
|
||||||
|
import sqlite3
|
||||||
|
import time
|
||||||
|
import re
|
||||||
|
|
||||||
|
app = Flask( 'pywallter' )
|
||||||
|
app.config.from_pyfile('config.py')
|
||||||
|
|
||||||
|
|
||||||
|
########################### Variables Globales #################################
|
||||||
|
extensionimg = app.config.get('EXT_IMG')
|
||||||
|
DATABASE = app.config.get('DATABASE')
|
||||||
|
|
||||||
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||||
|
cursor.execute("""SELECT title, creation_date, last_updated FROM Blog_posts """ )
|
||||||
|
list_posts=cursor.fetchall()
|
||||||
|
for post in list_posts:
|
||||||
|
title=post[0]
|
||||||
|
tmp = re.sub(r'[^a-zA-Z0-9 ]', '', title.rstrip())
|
||||||
|
title_id = tmp.replace(' ', '-')
|
||||||
|
newDatePost = ""
|
||||||
|
newDateUdatedPost = ""
|
||||||
|
if post[1] != '':
|
||||||
|
try:
|
||||||
|
date_post = time.strptime(post[1], '%d/%m/%Y %H:%M:%S')
|
||||||
|
except:
|
||||||
|
print(title +'-- Posted at: '+ str(post[1]) + ' Not modified: The date is not in the old format')
|
||||||
|
newDatePost = post[1]
|
||||||
|
else:
|
||||||
|
newDatePost = time.strftime("%Y-%m-%d %H:%M:%S", date_post)
|
||||||
|
if post[2] != '':
|
||||||
|
try:
|
||||||
|
last_updated_post = time.strptime(post[2], '%d/%m/%Y %H:%M:%S')
|
||||||
|
except:
|
||||||
|
print(title + '-- Updated at '+ str(post[2]) + ' Not modified: The date is not in the old format')
|
||||||
|
newDateUpdatedPost = post[2]
|
||||||
|
else:
|
||||||
|
newDateUpdatedPost = time.strftime("%Y-%m-%d %H:%M:%S", last_updated_post)
|
||||||
|
|
||||||
|
cursor.execute("""UPDATE Blog_posts set creation_date=?, last_updated=?, title_id=? WHERE title=?""", (newDatePost, newDateUpdatedPost, title_id, title))
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
+122
-74
@@ -10,6 +10,7 @@ import string
|
|||||||
import re
|
import re
|
||||||
from shutil import copy
|
from shutil import copy
|
||||||
from tools.utils import login_required
|
from tools.utils import login_required
|
||||||
|
import tools.blog_tools as blog_tools
|
||||||
|
|
||||||
blog = Blueprint('blog', __name__, template_folder='templates')
|
blog = Blueprint('blog', __name__, template_folder='templates')
|
||||||
|
|
||||||
@@ -38,41 +39,58 @@ def new_article():
|
|||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
tmp = re.sub(r'[^a-zA-Z0-9 ]', '', request.form['title'].rstrip())
|
tmp = re.sub(r'[^a-zA-Z0-9 ]', '', request.form['title'].rstrip())
|
||||||
title_id = tmp.replace(' ', '-')
|
title_id = tmp.replace(' ', '-')
|
||||||
print("---------title_id : " + title_id)
|
title = str(request.form['title'])
|
||||||
title = request.form['title'].rstrip()
|
subtitle = str(request.form['subtitle'])
|
||||||
subtitle = request.form['subtitle']
|
category = str(request.form['category'])
|
||||||
category = request.form['category']
|
content = str(request.form['content'])
|
||||||
content = request.form['content']
|
status = str(request.form['status'])
|
||||||
status = request.form['status']
|
post_date = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
post_date = time.strftime("%d/%m/%Y %H:%M:%S")
|
|
||||||
if 'blog-unified' in request.form.keys():
|
if 'blog-unified' in request.form.keys():
|
||||||
status = status+'_unified'
|
status = status+'_unified'
|
||||||
|
if not(blog_tools.article_exist(title_id, user)):
|
||||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||||
cursor.execute("""INSERT INTO Blog_posts(title_id, title, subtitle, category, content, creation_date, author, status) VALUES(?, ?, ?, ?, ?, ?, ?, ?)""", (title_id, title, subtitle, category, content, post_date, user, status)) # Insérer des valeurs
|
cursor.execute("""INSERT INTO Blog_posts(title_id, title, subtitle, category, content, creation_date, author, status)
|
||||||
conn.commit()
|
VALUES(?, ?, ?, ?, ?, ?, ?, ?)""", (title_id, title, subtitle, category, content, post_date, user, status))
|
||||||
|
conn.commit()
|
||||||
return redirect(url_for('blog.list_articles_blog'))
|
resp = redirect(url_for('blog.list_articles_blog'))
|
||||||
|
else:
|
||||||
|
flash(u'Cette article existe déjà ... Essayez de changer le titre ', 'error' )
|
||||||
|
|
||||||
|
resp = make_response(render_template('new_article_blog.html',
|
||||||
|
title=title, subtitle=subtitle,
|
||||||
|
category=category, content=content, status=status), 500)
|
||||||
else:
|
else:
|
||||||
return render_template('new_article_blog.html')
|
resp = render_template('new_article_blog.html')
|
||||||
|
|
||||||
|
return resp
|
||||||
|
|
||||||
@blog.route('/myblog/edit/<title_id>', methods=['GET'])
|
@blog.route('/myblog/edit/<title_id>', methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
def edit(title_id):
|
def edit(title_id):
|
||||||
user = '%s' % escape(session['username'])
|
user = '%s' % escape(session['username'])
|
||||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
title_id = '%s' % escape(title_id)
|
||||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
|
||||||
cursor.execute("""SELECT title_id, title, subtitle, creation_date, category, content, status FROM Blog_posts WHERE title_id=? AND author=?""", (title_id, user))
|
if blog_tools.article_exist(title_id, user):
|
||||||
oldpost = cursor.fetchone()
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
post = dict(title_id=oldpost[0], title=oldpost[1], subtitle=oldpost[2], creation_date=oldpost[3], category=oldpost[4], content=oldpost[5], status=oldpost[6])
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||||
|
cursor.execute("""SELECT title_id, title, subtitle, creation_date, category, content, status
|
||||||
|
FROM Blog_posts WHERE title_id=? AND author=?""", (title_id, user))
|
||||||
|
oldpost = cursor.fetchone()
|
||||||
|
post = dict(title_id=oldpost[0], title=oldpost[1], subtitle=oldpost[2], creation_date=oldpost[3],
|
||||||
|
category=oldpost[4], content=oldpost[5], status=oldpost[6])
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
return render_template('edit_article.html',
|
resp = render_template('edit_article.html',
|
||||||
section='Post-it',
|
section='Post-it',
|
||||||
oldpost=post)
|
oldpost=post)
|
||||||
|
else:
|
||||||
|
|
||||||
|
flash(u'Cette article n\'existe pas ...', 'error' )
|
||||||
|
resp = redirect(url_for('list_articles_blog'), code=500)
|
||||||
|
|
||||||
|
return resp
|
||||||
|
|
||||||
@blog.route('/myblog/update_blogpost', methods=['POST'])
|
@blog.route('/myblog/update_blogpost', methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
@@ -85,24 +103,31 @@ def update():
|
|||||||
category = str(request.form['category'])
|
category = str(request.form['category'])
|
||||||
content = str(request.form['content'])
|
content = str(request.form['content'])
|
||||||
status = str(request.form['status'])
|
status = str(request.form['status'])
|
||||||
updated = time.strftime("%d/%m/%Y %H:%M:%S")
|
updated = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
conn = sqlite3.connect(DATABASE)
|
|
||||||
cursor = conn.cursor()
|
if blog_tools.article_exist(title_id, user):
|
||||||
if 'blog-unified' in request.form.keys():
|
conn = sqlite3.connect(DATABASE)
|
||||||
status = status+'_unified'
|
cursor = conn.cursor()
|
||||||
|
if 'blog-unified' in request.form.keys():
|
||||||
|
status = status+'_unified'
|
||||||
|
|
||||||
cursor.execute("""DELETE FROM Blog_posts WHERE title_id=? AND author=?""", (title_id, user))
|
cursor.execute("""DELETE FROM Blog_posts WHERE title_id=? AND author=?""", (title_id, user))
|
||||||
cursor.execute("""INSERT INTO Blog_posts(title_id, title, subtitle, category, content, creation_date, last_updated, author, status)VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
cursor.execute("""INSERT INTO Blog_posts(title_id, title, subtitle, category, content, creation_date, last_updated, author, status)VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||||
(title_id, title, subtitle, category, content, creation_date, updated, user, status))
|
(title_id, title, subtitle, category, content, creation_date, updated, user, status))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
post = dict(title_id=title_id, title=title, subtitle=subtitle, category=category, content=content, status=status)
|
post = dict(title_id=title_id, title=title, subtitle=subtitle, category=category, content=content, status=status)
|
||||||
flash(u'Article mis à jour avec succès le: '+ updated , 'success' )
|
flash(u'Article mis à jour avec succès le: '+ updated , 'success' )
|
||||||
return render_template('edit_article.html',
|
resp = render_template('edit_article.html',
|
||||||
section='Post-it',
|
section='Post-it',
|
||||||
oldpost=post)
|
oldpost=post)
|
||||||
|
else:
|
||||||
|
|
||||||
|
flash(u'Cette article n\'existe pas ...', 'error' )
|
||||||
|
resp = redirect(url_for('list_articles_blog'), code=500)
|
||||||
|
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
@blog.route('/myblog/list-articles/', methods=['GET'])
|
@blog.route('/myblog/list-articles/', methods=['GET'])
|
||||||
@@ -111,7 +136,7 @@ def list_articles_blog():
|
|||||||
user = '%s' % escape(session['username'])
|
user = '%s' % escape(session['username'])
|
||||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||||
cursor.execute("""SELECT title_id, title, subtitle, creation_date, last_updated, status FROM Blog_posts WHERE author=? """, (user,) )
|
cursor.execute("""SELECT title_id, title, subtitle, creation_date, last_updated, status FROM Blog_posts WHERE author=? ORDER BY creation_date""", (user,) )
|
||||||
list_posts=cursor.fetchall()
|
list_posts=cursor.fetchall()
|
||||||
posts=list()
|
posts=list()
|
||||||
nb_articles=0
|
nb_articles=0
|
||||||
@@ -132,7 +157,7 @@ def list_articles_blog():
|
|||||||
@blog.route('/myblog/delete/<title_id>')
|
@blog.route('/myblog/delete/<title_id>')
|
||||||
@login_required
|
@login_required
|
||||||
def delete(title_id):
|
def delete(title_id):
|
||||||
title_id = '%s' % str(title_id).rstrip()
|
title_id = '%s' % escape(title_id)
|
||||||
user='%s'% escape(session['username'])
|
user='%s'% escape(session['username'])
|
||||||
folder_blog = DOSSIER_PERSO + user + "/blog/articles/"
|
folder_blog = DOSSIER_PERSO + user + "/blog/articles/"
|
||||||
folder_blog_public = DOSSIER_PUBLIC + user + "/blog/articles/"
|
folder_blog_public = DOSSIER_PUBLIC + user + "/blog/articles/"
|
||||||
@@ -182,15 +207,17 @@ def viewmyblog():
|
|||||||
user='%s' % escape(session['username'])
|
user='%s' % escape(session['username'])
|
||||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||||
cursor.execute("""SELECT title_id, title, subtitle, creation_date, author, status FROM Blog_posts WHERE author=? AND status!='draft'""", (user,))
|
cursor.execute("""SELECT title_id, title, subtitle, creation_date, author, status
|
||||||
|
FROM Blog_posts WHERE author=? AND status!='draft' ORDER BY creation_date""", (user,))
|
||||||
list_posts=cursor.fetchall()
|
list_posts=cursor.fetchall()
|
||||||
posts=list()
|
posts=list()
|
||||||
id=0
|
id=0
|
||||||
conn.close()
|
conn.close()
|
||||||
if list_posts != None:
|
if list_posts != None:
|
||||||
for post in list_posts:
|
for post in list_posts:
|
||||||
posts=[dict(title_id=post[0], title=post[1], subtitle=post[2], creation_date=post[3], author=post[4], status=post[5])] + posts
|
posts=[dict(title_id=post[0], title=post[1], subtitle=post[2],
|
||||||
|
creation_date=post[3], author=post[4], status=post[5])] + posts
|
||||||
|
|
||||||
return render_template('index_blog.html', section='Blog', posts=posts, author=user)
|
return render_template('index_blog.html', section='Blog', posts=posts, author=user)
|
||||||
|
|
||||||
|
|
||||||
@@ -199,14 +226,17 @@ def viewmyblog():
|
|||||||
def view_internal():
|
def view_internal():
|
||||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||||
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, last_updated, author, status FROM Blog_posts WHERE status='private_unified' OR status='public_unified' """ )
|
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, last_updated, author, status FROM
|
||||||
|
Blog_posts WHERE status='private_unified' OR status='public_unified' ORDER BY creation_date """ )
|
||||||
list_posts=cursor.fetchall()
|
list_posts=cursor.fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
posts=list()
|
posts=list()
|
||||||
id=0
|
id=0
|
||||||
if list_posts != None:
|
if list_posts != None:
|
||||||
for post in list_posts:
|
for post in list_posts:
|
||||||
posts = [dict(title_id=post[0], title=post[1], subtitle=post[2], content=post[3], creation_date=post[4], last_updated=post[5], author=post[6], status=post[7] )] + posts
|
posts = [dict(title_id=post[0], title=post[1], subtitle=post[2],
|
||||||
|
content=post[3], creation_date=post[4], last_updated=post[5],
|
||||||
|
author=post[6], status=post[7] )] + posts
|
||||||
else:
|
else:
|
||||||
return redirect(BASE_URL, code=404)
|
return redirect(BASE_URL, code=404)
|
||||||
|
|
||||||
@@ -216,14 +246,17 @@ def view_internal():
|
|||||||
def view():
|
def view():
|
||||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||||
cursor.execute("""SELECT title_id, title, subtitle, creation_date, author, status FROM Blog_posts WHERE status='public_unified'""" )
|
cursor.execute("""SELECT title_id, title, subtitle, creation_date, author, status
|
||||||
|
FROM Blog_posts WHERE status='public_unified' ORDER BY creation_date""" )
|
||||||
list_posts=cursor.fetchall()
|
list_posts=cursor.fetchall()
|
||||||
posts=list()
|
posts=list()
|
||||||
id=0
|
id=0
|
||||||
conn.close()
|
conn.close()
|
||||||
|
# print(list_posts)
|
||||||
if list_posts != None:
|
if list_posts != None:
|
||||||
for post in list_posts:
|
for post in list_posts:
|
||||||
posts=[dict(title_id=post[0], title=post[1], subtitle=post[2], creation_date=post[3], author=post[4], status=post[5])] + posts
|
posts=[dict(title_id=post[0], title=post[1], subtitle=post[2], creation_date=post[3],
|
||||||
|
author=post[4], status=post[5])] + posts
|
||||||
|
|
||||||
return render_template('index_blog.html', section='Blog', posts=posts)
|
return render_template('index_blog.html', section='Blog', posts=posts)
|
||||||
|
|
||||||
@@ -234,9 +267,11 @@ def viewuser(author):
|
|||||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||||
if 'username' in session :
|
if 'username' in session :
|
||||||
cursor.execute("""SELECT title_id, title, subtitle, creation_date, last_updated, author, status FROM Blog_posts WHERE author=? AND status!='draft' """, (author,))
|
cursor.execute("""SELECT title_id, title, subtitle, creation_date, last_updated, author, status
|
||||||
|
FROM Blog_posts WHERE author=? AND status!='draft' ORDER BY creation_date""", (author,))
|
||||||
else:
|
else:
|
||||||
cursor.execute("""SELECT title_id, title, subtitle, creation_date, last_updated, author, status FROM Blog_posts WHERE author=? AND status='public' OR status='public_unified' """, (author,))
|
cursor.execute("""SELECT title_id, title, subtitle, creation_date, last_updated, author, status
|
||||||
|
FROM Blog_posts WHERE author=? AND status='public' OR status='public_unified' ORDER BY creation_date""", (author,))
|
||||||
list_posts=cursor.fetchall()
|
list_posts=cursor.fetchall()
|
||||||
posts=None
|
posts=None
|
||||||
id=0
|
id=0
|
||||||
@@ -244,7 +279,8 @@ def viewuser(author):
|
|||||||
if list_posts != None:
|
if list_posts != None:
|
||||||
posts=list()
|
posts=list()
|
||||||
for post in list_posts:
|
for post in list_posts:
|
||||||
posts=[dict(title_id=post[0], title=post[1], subtitle=post[2], creation_date=post[3], last_updated=post[4], author=post[5], status=post[6])] + posts
|
posts=[dict(title_id=post[0], title=post[1], subtitle=post[2],
|
||||||
|
creation_date=post[3], last_updated=post[4], author=post[5], status=post[6])] + posts
|
||||||
|
|
||||||
|
|
||||||
return render_template('index_blog.html', section='Blog', posts=posts, author=author)
|
return render_template('index_blog.html', section='Blog', posts=posts, author=author)
|
||||||
@@ -253,24 +289,29 @@ def viewuser(author):
|
|||||||
def viewauthorrss(author):
|
def viewauthorrss(author):
|
||||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||||
cursor.execute("""SELECT MAX (creation_date) FROM Blog_posts WHERE author=? AND status='public_unified' OR status='public'""", (author, ) )
|
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, author, status
|
||||||
last_article_date = cursor.fetchone()
|
FROM Blog_posts WHERE author=? AND (status='public_unified' OR status='public') ORDER BY creation_date """,
|
||||||
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, author, status FROM Blog_posts WHERE author=? AND status='public_unified' OR status='public'""", (author, ) )
|
(author, ) )
|
||||||
list_posts=cursor.fetchall()
|
list_posts=cursor.fetchall()
|
||||||
posts=list()
|
posts=list()
|
||||||
id=0
|
id=0
|
||||||
conn.close()
|
conn.close()
|
||||||
if list_posts != None:
|
if list_posts != None:
|
||||||
last_build=last_article_date[0]
|
|
||||||
for post in list_posts:
|
for post in list_posts:
|
||||||
posts=[dict(title_id=post[0], title=post[1], subtitle=post[2], content=markdown(post[3], extensions=MARKDOWN_EXT), creation_date=post[4],
|
|
||||||
|
# Build date to RFC822 format
|
||||||
|
date_post = time.strptime(post[4], "%Y-%m-%d %H:%M:%S")
|
||||||
|
posts=[dict(title_id=post[0], title=post[1], subtitle=post[2], content=markdown(post[3], extensions=MARKDOWN_EXT),
|
||||||
|
creation_date=time.strftime("%a, %d %b %Y %H:%M:%S", date_post) + time.strftime(' %z'),
|
||||||
author=post[5], status=post[6])] + posts
|
author=post[5], status=post[6])] + posts
|
||||||
|
|
||||||
return render_template('blog_rss.xml',
|
resp = make_response(render_template('blog_rss.xml',
|
||||||
base_url=BASE_URL,
|
base_url=BASE_URL,
|
||||||
|
user=author,
|
||||||
blog_name=author,
|
blog_name=author,
|
||||||
last_build_date=last_build,
|
posts=posts))
|
||||||
posts=posts)
|
resp.headers['Content-type'] = 'application/xml; charset=utf-8'
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
@blog.route('/blog/private_unified/<username>/<title_id>', methods=['GET'])
|
@blog.route('/blog/private_unified/<username>/<title_id>', methods=['GET'])
|
||||||
@@ -278,9 +319,11 @@ def viewauthorrss(author):
|
|||||||
@login_required
|
@login_required
|
||||||
def viewPrivateArticle(username, title_id):
|
def viewPrivateArticle(username, title_id):
|
||||||
user = '%s' % escape(username)
|
user = '%s' % escape(username)
|
||||||
|
title_id = '%s' % escape(title_id)
|
||||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||||
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, last_updated, author, status FROM Blog_posts WHERE author=? AND title_id=? AND status!='draft' """, (user, title_id))
|
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, last_updated, author, status
|
||||||
|
FROM Blog_posts WHERE author=? AND title_id=? AND status!='draft' ORDER BY creation_date """, (user, title_id))
|
||||||
post = cursor.fetchone()
|
post = cursor.fetchone()
|
||||||
conn.close()
|
conn.close()
|
||||||
if post != None:
|
if post != None:
|
||||||
@@ -295,13 +338,18 @@ def viewPrivateArticle(username, title_id):
|
|||||||
@blog.route('/blog/public/<username>/<title_id>', methods=['GET'])
|
@blog.route('/blog/public/<username>/<title_id>', methods=['GET'])
|
||||||
def viewArticle(username, title_id):
|
def viewArticle(username, title_id):
|
||||||
user = '%s' % escape(username)
|
user = '%s' % escape(username)
|
||||||
|
title_id = '%s' % escape(title_id)
|
||||||
|
print(request.full_path)
|
||||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||||
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, last_updated, author FROM Blog_posts WHERE author=? AND title_id=? AND status='public_unified' """, (user, title_id) )
|
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, last_updated, author
|
||||||
|
FROM Blog_posts WHERE title_id=? AND author=? AND (status='public_unified' OR status='public') ORDER BY creation_date""",
|
||||||
|
(title_id, user) )
|
||||||
post = cursor.fetchone()
|
post = cursor.fetchone()
|
||||||
conn.close()
|
conn.close()
|
||||||
if post != None:
|
if post != None:
|
||||||
post_info = (dict(title_id=post[0], title=post[1], subtitle=post[2], creation_date=post[4], last_updated=post[5],author=post[6]))
|
post_info = (dict(title_id=post[0], title=post[1], subtitle=post[2],
|
||||||
|
creation_date=post[4], last_updated=post[5],author=post[6]))
|
||||||
content= markdown(post[3], extensions=MARKDOWN_EXT)
|
content= markdown(post[3], extensions=MARKDOWN_EXT)
|
||||||
|
|
||||||
return render_template('blog.html', post_info=post_info, content=content)
|
return render_template('blog.html', post_info=post_info, content=content)
|
||||||
@@ -311,25 +359,25 @@ def viewArticle(username, title_id):
|
|||||||
@blog.route('/blog/rss.xml', methods=['GET'])
|
@blog.route('/blog/rss.xml', methods=['GET'])
|
||||||
def viewrss():
|
def viewrss():
|
||||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
cursor = conn.cursor()
|
||||||
cursor.execute("""SELECT MAX(creation_date) FROM Blog_posts WHERE status='public_unified'""")
|
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, author, status
|
||||||
last_article_date = cursor.fetchone()
|
FROM Blog_posts WHERE status='public_unified' ORDER BY creation_date """)
|
||||||
print (last_article_date[0])
|
|
||||||
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, author, status FROM Blog_posts WHERE status='public_unified'""" )
|
|
||||||
list_posts=cursor.fetchall()
|
list_posts=cursor.fetchall()
|
||||||
posts=list()
|
posts=list()
|
||||||
id=0
|
id=0
|
||||||
conn.close()
|
conn.close()
|
||||||
if list_posts != None:
|
if list_posts != None:
|
||||||
last_build=last_article_date[0]
|
|
||||||
for post in list_posts:
|
for post in list_posts:
|
||||||
posts=[dict(title_id=post[0], title=post[1], subtitle=post[2], content=markdown(post[3], extensions=MARKDOWN_EXT), creation_date=post[4],
|
# Build date to RFC822 format
|
||||||
|
date_post = time.strptime(post[4], "%Y-%m-%d %H:%M:%S")
|
||||||
|
posts=[dict(title_id=post[0], title=post[1], subtitle=post[2], content=markdown(post[3], extensions=MARKDOWN_EXT),
|
||||||
|
creation_date=time.strftime("%a, %d %b %Y %H:%M:%S", date_post) + time.strftime(' %z'),
|
||||||
author=post[5], status=post[6])] + posts
|
author=post[5], status=post[6])] + posts
|
||||||
|
|
||||||
return render_template('blog_rss.xml',
|
resp = make_response(render_template('blog_rss.xml',
|
||||||
base_url=BASE_URL,
|
base_url=BASE_URL,
|
||||||
blog_name= TITLE_SERVER,
|
blog_name= TITLE_SERVER,
|
||||||
last_build_date=last_build,
|
|
||||||
blog_description=DESC_SERVER,
|
blog_description=DESC_SERVER,
|
||||||
posts=posts)
|
posts=posts))
|
||||||
|
resp.headers['Content-type'] = 'application/xml; charset=utf-8'
|
||||||
|
return resp
|
||||||
|
|||||||
@@ -90,7 +90,8 @@ def login():
|
|||||||
else:
|
else:
|
||||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||||
cursor.execute("""SELECT title_id, title, subtitle, creation_date, last_updated, author FROM Blog_posts WHERE status='public_unified'""" )
|
cursor.execute("""SELECT title_id, title, subtitle, creation_date, last_updated, author FROM Blog_posts
|
||||||
|
WHERE status='public_unified' ORDER BY creation_date""" )
|
||||||
list_posts=cursor.fetchall()
|
list_posts=cursor.fetchall()
|
||||||
posts=list()
|
posts=list()
|
||||||
id=0
|
id=0
|
||||||
@@ -105,7 +106,7 @@ def login():
|
|||||||
mail_server=MAIL_SERVER,
|
mail_server=MAIL_SERVER,
|
||||||
list_posts=posts,
|
list_posts=posts,
|
||||||
signin_enable=app.config['SIGNIN_ENABLE'])
|
signin_enable=app.config['SIGNIN_ENABLE'])
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
@loginlogout.route( '/logout/' )
|
@loginlogout.route( '/logout/' )
|
||||||
|
|||||||
Reference in New Issue
Block a user