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:sy="http://purl.org/rss/1.0/modules/syndication/"
|
||||
xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
|
||||
<channel>
|
||||
|
||||
<channel>
|
||||
<title> Le blog de {{ blog_name }} </title>
|
||||
<link> {{ base_url }}/blog/ </link>
|
||||
{% if blog_description %}
|
||||
<description> {{ blog_description }} </description>
|
||||
{% endif %}
|
||||
<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 %}
|
||||
<item>
|
||||
<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>
|
||||
<guid> {{base_url}}/{{ url_for('blog.viewArticle', username=post.author, title_id=post.title_id) }} </guid>
|
||||
|
||||
@@ -26,7 +25,7 @@
|
||||
</description>
|
||||
|
||||
<content:encoded>
|
||||
{{ post.content | safe }}
|
||||
{{ post.content }}
|
||||
</content:encoded>
|
||||
</item>
|
||||
{% endfor %}
|
||||
|
||||
@@ -16,30 +16,48 @@
|
||||
|
||||
<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="subtitle" id="subtitle" placeholder="Sous-titre" class="form-control"><br />
|
||||
<input type="text" name="category" id="category" placeholder="Catégories #hashtag" class="form-control"><br />
|
||||
<hr>
|
||||
<textarea id="editeurMarkdown" class="form-control" form="postform" name="content" id="content" placeholder="Contenu" style="height:20vw; margin-right:2vw;"></textarea><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" value="{{ subtitle }}"><br />
|
||||
<input type="text" name="category" id="category" placeholder="Catégorie" class="form-control" value="{{ category }}"><br />
|
||||
<textarea id="editeurMarkdown" class="form-control" form="postform" name="content" placeholder="Contenu" style="height:20vw;">
|
||||
{{ content }}</textarea>
|
||||
<br />
|
||||
<h3> Visibilité </h3>
|
||||
|
||||
<div class="center">
|
||||
<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 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="private" checked> Privé
|
||||
<input type="radio" name="status" value="public">Public<br>
|
||||
<input type="radio" name="status" value="private"> Privé
|
||||
<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>
|
||||
<br/>
|
||||
|
||||
<fieldset>
|
||||
<label>
|
||||
<label>
|
||||
|
||||
<input id="blog-unified" name="blog-unified" type="checkbox" role="switch" />
|
||||
Publier cet article dans le blog général
|
||||
</label>
|
||||
</fieldset>
|
||||
{% if status == "private_unified" or status == "public_unified" %}
|
||||
<input id="blog-unified" name="blog-unified" type="checkbox" role="switch" checked />
|
||||
{% else %}
|
||||
<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>
|
||||
</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()
|
||||
+116
-68
@@ -10,6 +10,7 @@ import string
|
||||
import re
|
||||
from shutil import copy
|
||||
from tools.utils import login_required
|
||||
import tools.blog_tools as blog_tools
|
||||
|
||||
blog = Blueprint('blog', __name__, template_folder='templates')
|
||||
|
||||
@@ -38,41 +39,58 @@ def new_article():
|
||||
if request.method == 'POST':
|
||||
tmp = re.sub(r'[^a-zA-Z0-9 ]', '', request.form['title'].rstrip())
|
||||
title_id = tmp.replace(' ', '-')
|
||||
print("---------title_id : " + title_id)
|
||||
title = request.form['title'].rstrip()
|
||||
subtitle = request.form['subtitle']
|
||||
category = request.form['category']
|
||||
content = request.form['content']
|
||||
status = request.form['status']
|
||||
post_date = time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
title = str(request.form['title'])
|
||||
subtitle = str(request.form['subtitle'])
|
||||
category = str(request.form['category'])
|
||||
content = str(request.form['content'])
|
||||
status = str(request.form['status'])
|
||||
post_date = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
if 'blog-unified' in request.form.keys():
|
||||
status = status+'_unified'
|
||||
if not(blog_tools.article_exist(title_id, user)):
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
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))
|
||||
conn.commit()
|
||||
resp = redirect(url_for('blog.list_articles_blog'))
|
||||
else:
|
||||
flash(u'Cette article existe déjà ... Essayez de changer le titre ', 'error' )
|
||||
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
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
|
||||
conn.commit()
|
||||
|
||||
return redirect(url_for('blog.list_articles_blog'))
|
||||
resp = make_response(render_template('new_article_blog.html',
|
||||
title=title, subtitle=subtitle,
|
||||
category=category, content=content, status=status), 500)
|
||||
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'])
|
||||
@login_required
|
||||
def edit(title_id):
|
||||
user = '%s' % escape(session['username'])
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
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])
|
||||
title_id = '%s' % escape(title_id)
|
||||
|
||||
conn.close()
|
||||
if blog_tools.article_exist(title_id, user):
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
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])
|
||||
|
||||
return render_template('edit_article.html',
|
||||
conn.close()
|
||||
|
||||
resp = render_template('edit_article.html',
|
||||
section='Post-it',
|
||||
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'])
|
||||
@login_required
|
||||
@@ -85,24 +103,31 @@ def update():
|
||||
category = str(request.form['category'])
|
||||
content = str(request.form['content'])
|
||||
status = 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():
|
||||
status = status+'_unified'
|
||||
updated = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
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(?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
if blog_tools.article_exist(title_id, user):
|
||||
conn = sqlite3.connect(DATABASE)
|
||||
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("""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))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
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' )
|
||||
return render_template('edit_article.html',
|
||||
section='Post-it',
|
||||
oldpost=post)
|
||||
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' )
|
||||
resp = render_template('edit_article.html',
|
||||
section='Post-it',
|
||||
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'])
|
||||
@@ -111,7 +136,7 @@ def list_articles_blog():
|
||||
user = '%s' % escape(session['username'])
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
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()
|
||||
posts=list()
|
||||
nb_articles=0
|
||||
@@ -132,7 +157,7 @@ def list_articles_blog():
|
||||
@blog.route('/myblog/delete/<title_id>')
|
||||
@login_required
|
||||
def delete(title_id):
|
||||
title_id = '%s' % str(title_id).rstrip()
|
||||
title_id = '%s' % escape(title_id)
|
||||
user='%s'% escape(session['username'])
|
||||
folder_blog = DOSSIER_PERSO + user + "/blog/articles/"
|
||||
folder_blog_public = DOSSIER_PUBLIC + user + "/blog/articles/"
|
||||
@@ -182,14 +207,16 @@ def viewmyblog():
|
||||
user='%s' % escape(session['username'])
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
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()
|
||||
posts=list()
|
||||
id=0
|
||||
conn.close()
|
||||
if list_posts != None:
|
||||
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)
|
||||
|
||||
@@ -199,14 +226,17 @@ def viewmyblog():
|
||||
def view_internal():
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
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()
|
||||
conn.close()
|
||||
posts=list()
|
||||
id=0
|
||||
if list_posts != None:
|
||||
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:
|
||||
return redirect(BASE_URL, code=404)
|
||||
|
||||
@@ -216,14 +246,17 @@ def view_internal():
|
||||
def view():
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
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()
|
||||
posts=list()
|
||||
id=0
|
||||
conn.close()
|
||||
# print(list_posts)
|
||||
if list_posts != None:
|
||||
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)
|
||||
|
||||
@@ -234,9 +267,11 @@ def viewuser(author):
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||
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:
|
||||
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()
|
||||
posts=None
|
||||
id=0
|
||||
@@ -244,7 +279,8 @@ def viewuser(author):
|
||||
if list_posts != None:
|
||||
posts=list()
|
||||
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)
|
||||
@@ -253,24 +289,29 @@ def viewuser(author):
|
||||
def viewauthorrss(author):
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
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, ) )
|
||||
last_article_date = cursor.fetchone()
|
||||
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, ) )
|
||||
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, author, status
|
||||
FROM Blog_posts WHERE author=? AND (status='public_unified' OR status='public') ORDER BY creation_date """,
|
||||
(author, ) )
|
||||
list_posts=cursor.fetchall()
|
||||
posts=list()
|
||||
id=0
|
||||
conn.close()
|
||||
if list_posts != None:
|
||||
last_build=last_article_date[0]
|
||||
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
|
||||
|
||||
return render_template('blog_rss.xml',
|
||||
resp = make_response(render_template('blog_rss.xml',
|
||||
base_url=BASE_URL,
|
||||
user=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'])
|
||||
@@ -278,9 +319,11 @@ def viewauthorrss(author):
|
||||
@login_required
|
||||
def viewPrivateArticle(username, title_id):
|
||||
user = '%s' % escape(username)
|
||||
title_id = '%s' % escape(title_id)
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
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()
|
||||
conn.close()
|
||||
if post != None:
|
||||
@@ -295,13 +338,18 @@ def viewPrivateArticle(username, title_id):
|
||||
@blog.route('/blog/public/<username>/<title_id>', methods=['GET'])
|
||||
def viewArticle(username, title_id):
|
||||
user = '%s' % escape(username)
|
||||
title_id = '%s' % escape(title_id)
|
||||
print(request.full_path)
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
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()
|
||||
conn.close()
|
||||
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)
|
||||
|
||||
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'])
|
||||
def viewrss():
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||
cursor.execute("""SELECT MAX(creation_date) FROM Blog_posts WHERE status='public_unified'""")
|
||||
last_article_date = cursor.fetchone()
|
||||
print (last_article_date[0])
|
||||
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, author, status FROM Blog_posts WHERE status='public_unified'""" )
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, author, status
|
||||
FROM Blog_posts WHERE status='public_unified' ORDER BY creation_date """)
|
||||
list_posts=cursor.fetchall()
|
||||
posts=list()
|
||||
id=0
|
||||
conn.close()
|
||||
if list_posts != None:
|
||||
last_build=last_article_date[0]
|
||||
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
|
||||
|
||||
return render_template('blog_rss.xml',
|
||||
resp = make_response(render_template('blog_rss.xml',
|
||||
base_url=BASE_URL,
|
||||
blog_name= TITLE_SERVER,
|
||||
last_build_date=last_build,
|
||||
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:
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
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()
|
||||
posts=list()
|
||||
id=0
|
||||
@@ -105,7 +106,7 @@ def login():
|
||||
mail_server=MAIL_SERVER,
|
||||
list_posts=posts,
|
||||
signin_enable=app.config['SIGNIN_ENABLE'])
|
||||
return resp
|
||||
return resp
|
||||
|
||||
|
||||
@loginlogout.route( '/logout/' )
|
||||
|
||||
Reference in New Issue
Block a user