Work on blog

rewrite entire blog section
This commit is contained in:
kitoy 2025-12-13 02:30:50 +01:00
parent 68d798845d
commit a5ba0b90bb
14 changed files with 354 additions and 72 deletions

View File

@ -22,13 +22,20 @@
</li>
<li>
<a href="/myblog/personnalize/" {% if request.path == "/myblog/personnalize/" %} class="invert" {% endif %} ><span class="icons custom-blog"></span>
Configurer mon site web
Personnaliser mon blog
</a>
</li>
<li>
<a href="/private-blog/" {% if request.path == "/private-blog/" %} class="invert" {% endif %} ><span class="icons view-blog" aria-hidden="true"></span>
Voir le blog
<a href="/myblog/" {% if request.path == "/myblog/" %} class="invert" {% endif %} ><span class="icons view-blog" aria-hidden="true"></span>
Voir mon blog
</a>
</li>
<li>
<a href="/private-blog/" {% if request.path == "/private-blog/" %} class="invert" {% endif %} ><span class="icons view-blog" aria-hidden="true"></span>
Voir le blog général
</a>
</li>
</ul>

View File

@ -12,7 +12,7 @@
<h2 class="titre"> {{ post_info.title }} </h2>
<h5 class="titre">Publié le : {{ post_info.creation_date }} </h5>
<h5 class="titre">Publié le : {{ post_info.creation_date }} par <a href="{{ url_for('blog.view') }}/{{ post_info.author }}"> {{ post_info.author }} </h5>
{% if post_info.last_updated %}
<h5 class="titre">Mis à jour le : {{ post_info.last_updated }} </h5>
{% endif %}

View File

@ -0,0 +1,26 @@
<!doctype html>
<html>
<head>
<title> Article de {{ post_info.author }} </title>
<link rel="stylesheet" href="/static/{{ post_info.author}}/blog.css" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="articles">
<h2 class="titre"> {{ post_info.title }} </h2>
<h5 class="titre">Publié le : {{ post_info.creation_date }} </h5>
{% if post_info.last_updated %}
<h5 class="titre">Mis à jour le : {{ post_info.last_updated }} </h5>
{% endif %}
<h3 class="description titre"> {{ post_info.subtitle }} </h3>
<hr/>
{{ content|safe }}
</div>
</body>
</html>

35
templates/blog_rss.xml Normal file
View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
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>
<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>
{% for post in posts %}
<item>
<title> {{ post.title }} </title>
<pubdate> {% if post.last_updated %} {{ post.last_updated }} {% else %} {{ post.time }} {% endif %} </pubdate>
<link> {{base_url}}/blog/{{ post.status }}/{{post.author}}/{{post.title}}</link>
<guid> {{base_url}}/blog/{{ post.status }}/{{post.author}}/{{post.title}}</guid>
<description>
{{ post.subtitle }}
</description>
<content:encoded>
{{ post.content | safe }}
</content:encoded>
</item>
{% endfor %}
</channel>
</rss>

View File

@ -2,16 +2,17 @@
{% block main %}
<p>Vous pouvez modifier votre article. </p>
<h2> {{ oldpost['title'] }}</h2><br />
<form action="" method="POST" id="postform" style="height: 15vw;">
<input type="text" name="subtitle" id="subtitle" placeholder="sous-titre" class="form-control" value="{{ oldpost['title'] }}"><br />
<input type="text" name="title" id="title" placeholder="titre" class="form-control" value="{{ oldpost['title'] }}"><br />
<input type="text" name="subtitle" id="subtitle" placeholder="sous-titre" class="form-control" value="{{ oldpost['subtitle'] }}"><br />
<input type="text" name="category" id="category" placeholder="Catégorie" class="form-control" value="{{ oldpost['category'] }}"><br />
<textarea id="editeurMarkdown" class="form-control" form="postform" name="content" id="content" placeholder="Contenu" style="height:20vw;">{{ oldpost['content'] }}</textarea><br />
<textarea id="editeurMarkdown" class="form-control" form="postform" name="content" id="content" placeholder="Contenu" style="height:20vw;">{{ oldpost['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>
@ -34,15 +35,23 @@
{% endif %}
</div>
<br />
<fieldset>
<label>
{% if blog_unified == "True" %}
<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"> Mettre à jour </button>
</form>
<br />
{% endblock %}
{% block js %}
{% include '_js_editor.html' %}
{% endblock %}

View File

@ -0,0 +1,41 @@
<!doctype html>
<html>
<head>
<title> Le Blog du serveur </title>
<link rel="stylesheet" href="/static/{{author}}/blog.css" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
{% if not(posts) %}
<h1 style="text-align: center;"> Désolé ce blog n'existe pas encore :/ </h1>
{% else %}
<div class="articles">
{% for post in posts %}
<h2 class="index"><a href="/blog/{author}}/{{post.title}}"> {{ post.title }}</a></h2>
<small>
<time datetime="{{ post.time }}">
Publié le {{ post.creation_date }}
</time>
<br/>
{% if post.last_updated %}
<time datetime="{{ post.last_updated }}">
Mis à jour le {{ post.last_updated }}
</time>
{% endif %}
</small>
<div class="slug">
<p> {{ post.subtitle }} </p>
<p class="readmore"> <a style="margin-right:2rem;" href="/blog/{{ post.status }}/{{post.author}}/{{post.title}}"> Lire la suite... </a></p>
</div>
{% endfor %}
</div>
{% endif %}
</body>
</html>

View File

@ -14,13 +14,15 @@
{% else %}
<div class="articles">
<a href="/blog/rss.xml"> S'abonner au flux RSS </a>
{% for post in posts %}
<h2 class="index"><a href="/blog/{{user}}/{{post.title}}"> {{ post.title }}</a></h2>
<h2 class="index"><a href="/blog/{{post.author}}/{{post.title}}"> {{ post.title }}</a></h2>
<small>
<time datetime="{{ post.time }}">
Publié le {{ post.creation_date }}
Publié le {{ post.creation_date }} par <a href="{{ url_for('blog.view') }}/{{ post.author }}"> {{ post.author }}</a>
</time>
<br/>
{% if post.last_updated %}

View File

@ -3,9 +3,10 @@
{% block main %}
<h2> Vos articles de blog </h2>
{% if nb_articles > 1 %}
<h2> Vos {{ nb_articles }} articles de blog </h2>
{% endif %}
<br/>
{% for article in list_posts %}
<article>
@ -14,9 +15,25 @@
<br/>
<small> Créé le : {{ article.time }} </small> <br/>
<small> Modifié le : {{ article.last_updated }}</small>
<p> Status : {{ article.status }}</p>
<br/>
{% if article.last_updated == "private" %}
<small> Modifié le : {{ article.last_updated }}</small><br/>
{% endif %}
{% if article.status == "private" %}
<small> Status : privé </small>
<small> (L'article n'est pas publié dans le blog général) </small>
{% elif article.status == "private_unified" %}
<small> Status : privé </small>
<small> (L'article est publié dans le blog général) </small>
{% elif article.status == "public" %}
<small> Status : public </small>
<small> (L'article n'est pas publié dans le blog général) </small>
{% elif article.status == "public_unified" %}
<small> Status : public </small>
<small> (L'article est publié dans le blog général) </small>
{% endif %}
<br/>
<a href="{{ url_for('blog.edit', title=article.title) }}"><button type="button"> Editer </button></a>
<a href="{{ url_for('blog.delete', title=article.title) }}"><button type="button">Supprimer</button></a>

View File

@ -32,6 +32,18 @@
<input type="radio" name="status" value="public">Public<br>
</div>
<br/>
<fieldset>
<label>
{% if blog_unified == "True" %}
<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>

View File

@ -3,6 +3,32 @@
{% block main %}
<h2> Ça va venir dans la prochaine version ! </h2>
<h2> Personnalisation du blog </h2>
<form method="POST" action="" enctype="multipart/form-data">
<br />
<label for="blog-theme">Theme</label>
<select id="blog-theme" name="blog-theme">
<option selected> Default </option>
<option>Blanc et noir</option>
<option>Noir et blanc </option>
<option>Chocolat</option>
<option>Orange et noir</option>
</select>
<div id="personnal-blog-theme" class="center">
<p> Vous pouvez faire le choix d'envoyer un fichier css pour personnaliser votre blog directement.
<label> Envoyer mon thème </label>
<input type="file" class="center" name="personnal-blog-theme" id="personnal-blog-theme"/>
<br />
</div>
<button class="btn btn-default btn-primary" type="submit"> Enregistrer mes modifications </button>
</form>
{% endblock %}

View File

@ -45,7 +45,6 @@ def init_db(database):
category TEXT,
author TEXT,
status TEXT,
blog_theme TEXT,
PRIMARY KEY(title, author)
)
""")
@ -74,19 +73,22 @@ def check_directories(users_folder):
print("Le dossier {} a été créé".format(users_folder))
def db_migrate(database):
conn = sqlite3.connect(database)
cursor = conn.cursor()
cursor.execute("""SELECT name FROM PRAGMA_TABLE_INFO('users');""")
db_columns = cursor.fetchall()
invitations_col = False
lost_password_token_col = False
totp_col = False
totp_col = False
blog_unified_col = False
blog_theme_col = False
updated_col = False
creation_date_col = False
content_col = False
conn = sqlite3.connect(database)
cursor = conn.cursor()
cursor.execute("""SELECT name FROM PRAGMA_TABLE_INFO('users');""")
db_columns = cursor.fetchall()
for col in db_columns:
if "invitations" == col[0]:
invitations_col = True
@ -94,12 +96,13 @@ def db_migrate(database):
lost_password_token_col = True
if "totp" == col[0]:
totp_col = True
if "blog_theme" == col[0]:
blog_theme_col = True
cursor.execute("""SELECT name FROM PRAGMA_TABLE_INFO('Blog_posts');""")
db_columns = cursor.fetchall()
for col in db_columns:
if "blog_theme" == col[0]:
blog_theme_col = True
if "last_updated" == col[0]:
updated_col = True
if "content" == col[0]:
@ -127,7 +130,6 @@ def db_migrate(database):
print ("Ajout du champ totp dans la table Users")
if not(blog_theme_col):
cursor.execute("""ALTER TABLE Blog_posts ADD COLUMN blog_theme TEXT;""")
conn.commit()

View File

@ -7,6 +7,7 @@ import sqlite3
from markdown import markdown
from tools.filesutils import getFileSizeKo
import string
from shutil import copy
from tools.utils import login_required
blog = Blueprint('blog', __name__, template_folder='templates')
@ -18,10 +19,11 @@ app.config.from_pyfile('config.py')
########################### Variables Globales #################################
extensionimg = app.config['EXT_IMG']
DATABASE = app.config['DATABASE']
BASE_URL= app.config['BASE_URL']
DOSSIER_PERSO= app.config['DOSSIER_APP']+'/'
DOSSIER_PUBLIC= app.config['DOSSIER_PUBLIC']+'/'
BASE_URL = app.config['BASE_URL']
DOSSIER_PERSO = app.config['DOSSIER_APP']+'/'
DOSSIER_PUBLIC = app.config['DOSSIER_PUBLIC']+'/'
TITLE_SERVER = app.config['TITLE_SERVER']
DESC_SERVER = app.config['DESC_SERVER']
################################################################################
@blog.route('/myblog/new-article/', methods=['GET', 'POST'])
@ -35,6 +37,8 @@ def new_article():
content = request.form['content']
status = request.form['status']
post_date = time.strftime("%d/%m/%Y %H:%M:%S")
if 'blog-unified' in request.form.keys():
status = status+'_unified'
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
cursor = conn.cursor() # Création de l'objet "curseur"
@ -51,7 +55,7 @@ def edit(title):
user='%s'% escape(session['username'])
folder_blog = DOSSIER_PERSO + user + "/blog/articles/"
if request.method == 'POST' :
title = requrest.form['title']
title = request.form['title']
subtitle = request.form['subtitle']
category = request.form['category']
newcontent = request.form['content']
@ -59,7 +63,10 @@ def edit(title):
updated = time.strftime("%d/%m/%Y %H:%M:%S")
conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
cursor.execute("""UPDATE Blog_posts SET title, subtitle=?, category=?, last_updated=?, status=?, content=? WHERE title=? AND author=?""", (title, subtitle, category, updated, newstatus, newcontent, title, user))
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=?""", (title, subtitle, category, updated, newstatus, newcontent, title, user))
conn.commit()
conn.close()
return redirect(url_for('blog.list_articles_blog'))
@ -91,13 +98,12 @@ def list_articles_blog():
time=post[2],
last_updated=post[3],
status=post[4])] + posts
nb_articles =+ 1
nb_articles = nb_articles + 1
return render_template('list_articles.html',
section="Articles",
list_posts=posts,
nb_articles=nb_articles
)
return render_template('list_articles.html',
section="Articles",
list_posts=posts,
nb_articles=nb_articles )
@blog.route('/myblog/delete/<title>')
@login_required
@ -114,17 +120,62 @@ def delete(title):
return redirect(url_for('blog.list_articles_blog'))
@blog.route('/myblog/personnalize/', methods=['GET'])
@blog.route('/myblog/personnalize/', methods=['GET', 'POST'])
@login_required
def personnalize_blog():
return render_template('personnalize_blog.html')
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 blog_unified, blog_theme FROM users WHERE name=?""", (user,))
blog_info = cursor.fetchone()
conn.close()
blog_unified = blog_info[0]
if request.method == 'POST' :
f = request.files['personnal-blog-theme']
blog_theme = escape(request.form['blog-theme'])
if blog_theme != "Default":
copy( "static/blog-"+blog_theme+".css",
DOSSIER_PERSO+ user +'blog.css' )
if f: # On vérifie qu'un fichier a bien été envoyé
nom = secure_filename(f.filename)
f.save(DOSSIER_PERSO + user + nom)
else:
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
cursor = conn.cursor() # Création de l\'objet "curseur"
cursor.execute("UPDATE users SET blog_unified=?, blog_theme=? WHERE name=?", (blog_unified, blog_theme, user))
conn.commit()
return render_template('personnalize_blog.html', section='personnalize_blog', blog_unified=blog_unified, blog_theme=blog_info[1])
@blog.route('/myblog/', methods=['GET'])
@login_required
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, subtitle, creation_date, author, status FROM Blog_posts WHERE author=? AND status!='draft'""", (user,))
list_posts=cursor.fetchall()
posts=list()
id=0
conn.close()
if list_posts != None:
for post in list_posts:
posts=[dict(title=post[0], subtitle=post[1], creation_date=post[2], author=post[3], status=post[4])] + posts
return render_template('index_blog.html', section='Blog', posts=posts)
@blog.route('/private-blog/', methods=['GET'])
@login_required
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, subtitle, content, creation_date, last_updated, author, status FROM Blog_posts WHERE status!='draft' """ )
cursor.execute("""SELECT title, subtitle, content, creation_date, last_updated, author, status FROM Blog_posts WHERE status='private_unified' OR status='public_unified' """ )
list_posts=cursor.fetchall()
conn.close()
posts=list()
@ -141,7 +192,7 @@ 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, subtitle, creation_date, author, status FROM Blog_posts WHERE status='public'""" )
cursor.execute("""SELECT title, subtitle, creation_date, author, status FROM Blog_posts WHERE status='public_unified'""" )
list_posts=cursor.fetchall()
posts=list()
id=0
@ -149,9 +200,6 @@ def view():
if list_posts != None:
for post in list_posts:
posts=[dict(title=post[0], subtitle=post[1], creation_date=post[2], author=post[3], status=post[4])] + posts
else:
return redirect(BASE_URL, code=404)
return render_template('index_blog.html', section='Blog', posts=posts)
@ -161,7 +209,10 @@ def viewuser(author):
author = escape(author)
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
cursor = conn.cursor() # Création de l'objet "curseur"
cursor.execute("""SELECT title, subtitle, creation_date, last_updated, author FROM Blog_posts WHERE author=? AND status='public' """, (author,))
if 'username' in session :
cursor.execute("""SELECT title, subtitle, creation_date, last_updated, author, status FROM Blog_posts WHERE author=? AND status != 'draft' """, (author,))
else:
cursor.execute("""SELECT title, subtitle, creation_date, last_updated, author, status FROM Blog_posts WHERE author=? AND status='public' OR status='public_unified' """, (author,))
list_posts=cursor.fetchall()
posts=None
id=0
@ -169,14 +220,35 @@ def viewuser(author):
if list_posts != None:
posts=list()
for post in list_posts:
posts=[dict(title=post[0], subtitle=post[1], creation_date=post[2], author=post[3], status=post[4])] + posts
else:
return redirect(BASE_URL, code=404)
posts=[dict(title=post[0], subtitle=post[1], creation_date=post[2], last_updated=post[3], author=post[4], status=post[5])] + posts
return render_template('index_blog.html', section='Blog', posts=posts)
return render_template('index_author_blog.html', section='Blog', posts=posts)
@blog.route('/blog/<author>/rss.xml', methods=['GET'])
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, subtitle, content, creation_date, author, status FROM Blog_posts WHERE author=? AND status='public_unified' OR status='public'""", (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=post[0], subtitle=post[1], content=markdown(post[2]), creation_date=post[3], author=post[4], status=post[5])] + posts
return render_template('blog_rss.xml',
base_url=BASE_URL,
blog_name=author,
last_build_date=last_build,
posts=posts)
@blog.route('/blog/private_unified/<username>/<title>', methods=['GET'])
@blog.route('/blog/private/<username>/<title>', methods=['GET'])
@login_required
def viewPrivateArticle(username, title):
@ -192,17 +264,16 @@ def viewPrivateArticle(username, title):
content= markdown(post[2])
return render_template('blog.html', post_info=post_info, content=content)
else:
return redirect(url_for('blog'), code=404);
return redirect(url_for('blog'), code=404)
@blog.route('/blog/public_unified/<username>/<title>', methods=['GET'])
@blog.route('/blog/public/<username>/<title>', methods=['GET'])
def viewArticle(username, title):
user = username
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
cursor = conn.cursor() # Création de l'objet "curseur"
cursor.execute("""SELECT title, subtitle, content, creation_date, last_updated, author FROM Blog_posts WHERE author=? AND title=? AND status='public' """, (user, title) )
cursor.execute("""SELECT title, subtitle, content, creation_date, last_updated, author FROM Blog_posts WHERE author=? AND title=? AND status='public_unified' """, (user, title) )
post = cursor.fetchone()
conn.close()
if post != None:
@ -211,5 +282,29 @@ def viewArticle(username, title):
return render_template('blog.html', post_info=post_info, content=content)
else:
return redirect(url_for('blog'), code=404);
return redirect(url_for('blog.view'), code=404)
@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, subtitle, content, creation_date, author, status FROM Blog_posts WHERE status='public_unified'""" )
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=post[0], subtitle=post[1], content=markdown(post[2]), creation_date=post[3], author=post[4], status=post[5])] + posts
return render_template('blog_rss.xml',
base_url=BASE_URL,
blog_name= TITLE_SERVER,
last_build_date=last_build,
blog_description=DESC_SERVER,
posts=posts)

View File

@ -174,6 +174,15 @@ def remove_publicFile(filename):
flash(u'Fichier {filename} inexistant.'.format(filename=filename), 'error')
return redirect(url_for('filesupload.list', _external=True))
@filesupload.route('/<author>/blog.css')
def blog_theme(author):
user = author
if os.path.isfile(DOSSIER_PERSO+ user +'/blog-theme.css'):
return send_file(DOSSIER_PERSO+ user +'blog-theme.css', mimetype='text/css')
else:
return send_file("static/blog.css", mimetype='text/css')
@filesupload.route('/theme.min.css')
def theme():
if 'username' in session:

View File

@ -327,8 +327,9 @@ def totp_qrcode():
os.path.join(DOSSIER_PERSO, user, "totp.png"), "totp.png")
@profil.route('/deltoken-password-lost/<token>', methods=['GET','POST'] )
@profil.route('/deltoken-password-lost/<token>', methods=['GET'] )
def deltoken_passwd_lost(token) :
token = escape(token)
if valid_token_register(token, "Lost password"):
user = get_user_by_token(token, "Lost password")
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée