Rework blog section

Wrok in bloc sectionn
This commit is contained in:
kitoy 2025-12-05 23:20:36 +01:00
parent 0e282894a6
commit 57241b843b
13 changed files with 339 additions and 158 deletions

View File

@ -0,0 +1,90 @@
.editor-toolbar a {
display: inline-block;
text-align: center;
text-decoration: none !important;
color: var(--pico-primary) !important;
width: 30px;
height: 30px;
margin: 0;
border: 1px solid transparent;
border-radius: 3px;
cursor: pointer;
}
.editor-toolbar.fullscreen {
width: 100%;
height: 50px;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
padding-top: 10px;
padding-bottom: 10px;
box-sizing: border-box;
background: var(--pico-background-color);
border: 0;
position: fixed;
top: 0;
left: 0;
opacity: 1;
z-index: 9;
}
.CodeMirror {
background-color: var(--pico-background-color);
color: var(--pico-color) !important;
}
.editor-preview-active-side {
background: var(--pico-background-color);
color: var(--pico-color) !important;
position: fixed;
bottom: 0;
width: 50%;
top: 50px;
right: 0;
z-index: 9;
border: 1px solid #ddd;
}
.CodeMirror .CodeMirror-code .cm-tag {
color: #63a35c;
}
.CodeMirror .CodeMirror-code .cm-attribute {
color: #795da3;
}
.CodeMirror .CodeMirror-code .cm-string {
color: #183691;
}
.CodeMirror .CodeMirror-selected {
background: var(--pico-text-selection-color) !important;
}
.CodeMirror .CodeMirror-code .cm-link {
color: #7f8c8d;
}
.CodeMirror .CodeMirror-code .cm-url {
color: #aab2b3;
}
.CodeMirror-cursor {
border-left-color: var(--pico-primary);
}
.editor-statusbar .lines:before {
color: var(--pico-primary) !important;
content: 'lignes: '
}
.editor-statusbar .words:before {
color: var(--pico-primary) !important;
content: 'Mots: '
}

View File

@ -1,4 +1,4 @@
<head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
@ -11,7 +11,5 @@
<link href="{{ url_for('static', filename='vendors/picocss/pico.colors.min.css') }}" rel="stylesheet"> <link href="{{ url_for('static', filename='vendors/picocss/pico.colors.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='pywallter.css') }}" rel="stylesheet"> <link href="{{ url_for('static', filename='pywallter.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='icons.css') }}" rel="stylesheet"> <link href="{{ url_for('static', filename='icons.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='vendors/simplemde/simplemde.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='vendors/glightbox/glightbox.min.css') }}" rel="stylesheet"> <link href="{{ url_for('static', filename='vendors/glightbox/glightbox.min.css') }}" rel="stylesheet">
</head>

View File

@ -21,13 +21,13 @@
</a> </a>
</li> </li>
<li> <li>
<a href="/myblog/personalize/" {% if request.path == "/myblog/personalize/" %} class="invert" {% endif %} ><span class="icons custom-blog"></span> <a href="/myblog/personnalize/" {% if request.path == "/myblog/personnalize/" %} class="invert" {% endif %} ><span class="icons custom-blog"></span>
Configurer mon site web Configurer mon site web
</a> </a>
</li> </li>
<li> <li>
<a href="/myblog/view/" {% if request.path == "/myblog/view/" %} class="invert" {% endif %} ><span class="icons view-blog" aria-hidden="true"></span> <a href="/private-blog/" {% if request.path == "/private-blog/" %} class="invert" {% endif %} ><span class="icons view-blog" aria-hidden="true"></span>
Voir mon blog Voir le blog
</a> </a>
</li> </li>
</ul> </ul>
@ -46,6 +46,7 @@
<li> <li>
<a href="/filesupload/" {% if request.path == "/filesupload/" %} class="invert" {% endif %}> <span class="icons send-files"></span> Envoyer des fichiers </a> <a href="/filesupload/" {% if request.path == "/filesupload/" %} class="invert" {% endif %}> <span class="icons send-files"></span> Envoyer des fichiers </a>
</li> </li>
</ul> </ul>
@ -66,7 +67,6 @@
Gerer mes alias Gerer mes alias
</a> </a>
</li> </li>
</ul> </ul>

View File

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

View File

@ -0,0 +1,3 @@
<link href="{{ url_for('static', filename='vendors/simplemde/simplemde.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='simplemde-custom.css') }}" rel="stylesheet">

View File

@ -2,27 +2,40 @@
{% block main %} {% block main %}
<p>Vous pouvez modifier votre article. Actuellement seule la date de première édition sera publiée. Prochainement : intégration de la date de mise à jour dans la base de donnée.</p> <p>Vous pouvez modifier votre article. </p>
<h2> {{ oldpost[0] }}</h2><br /> <h2> {{ oldpost['title'] }}</h2><br />
<form action="" method="POST" id="postform" style="height: 15vw;"> <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="subtitle" id="subtitle" placeholder="Titre" class="form-control" value="{{ oldpost[1] }}"><br /> <input type="text" name="subtitle" id="subtitle" placeholder="sous-titre" class="form-control" value="{{ oldpost['subtitle'] }}"><br />
<textarea id="editeurMarkdown" class="form-control" form="postform" name="content" id="content" placeholder="Contenu" style="height:20vw;">{{ content }}</textarea><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 />
<h3> Visibilité </h3> <h3> Visibilité </h3>
<div class="center"> <div class="center">
{% if oldpost[2] == 'public' %} <p> Les articles brouillons ne sont visibles que par vous même</p>
<input type="radio" name="status" value="prive"> Privé <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 oldpost['status'] == 'public' %}
<input type="radio" name="status" value="draft"> Brouillon
<input type="radio" name="status" value="private"> Privé
<input type="radio" name="status" value="public" checked> Publique <input type="radio" name="status" value="public" checked> Publique
{% else %} {% elif oldpost['status'] == 'private' %}
<input type="radio" name="status" value="Privé" checked> Privé <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 <input type="radio" name="status" value="public"> Publique
{% else %}
<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
{% endif %} {% endif %}
</div> </div>
<br /> <br />
<button type="submit"> Mettre à jour </button> <button type="submit"> Mettre à jour </button>
</form> </form>
<br /> <br />
@ -30,3 +43,7 @@
{% endblock %} {% endblock %}
{% block js %}
{% include '_js_editor.html' %}
{% endblock %}

View File

@ -1,7 +1,7 @@
<!doctype html> <!doctype html>
<html> <html>
<head> <head>
<title> Blog de {{ user }} </title> <title> Le Blog du serveur </title>
<link rel="stylesheet" href="/static/blog.css" type="text/css"> <link rel="stylesheet" href="/static/blog.css" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
@ -14,12 +14,19 @@
<h2 class="index"><a href="/blog/{{user}}/{{post.title}}"> {{ post.title }}</a></h2> <h2 class="index"><a href="/blog/{{user}}/{{post.title}}"> {{ post.title }}</a></h2>
<small> <small>
<time datetime="{{ post.time }}"> <time datetime="{{ post.time }}">
Publié le {{ post.time }} Publié le {{ post.creation_date }}
</time> </time>
<br/>
{% if post.last_updated %}
<time datetime="{{ post.last_updated }}">
Mis à jour le {{ post.last_updated }}
</time>
{% endif %}
</small> </small>
<div class="slug"> <div class="slug">
<p> {{ post.subtitle }} </p> <p> {{ post.subtitle }} </p>
<p class="readmore"> <a style="margin-right:2rem;" href="/blog/{{user}}/{{post.title}}"> Lire la suite... </a></p> <p class="readmore"> <a style="margin-right:2rem;" href="/blog/{{ post.status }}/{{post.author}}/{{post.title}}"> Lire la suite... </a></p>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>

View File

@ -15,20 +15,31 @@
<br /> <br />
<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="category" id="category" placeholder="Catégorie" class="form-control"><br />-->
<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"><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"><br />
<input type="text" name="category" id="category" placeholder="Catégorie" class="form-control"><br />
<hr> <hr>
<textarea id="editeurMarkdown" class="form-control" form="postform" name="content" id="content" placeholder="Contenu" style="height:20vw;"></textarea><br /> <textarea id="editeurMarkdown" class="form-control" form="postform" name="content" id="content" placeholder="Contenu" style="height:20vw; margin-right:2vw;"></textarea><br />
<h3> Visibilité </h3>
<div class="center"> <div class="center">
<input type="radio" name="status" value="private" checked> Privé <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>
<input type="radio" name="status" value="private" checked> Privé
<input type="radio" name="status" value="public">Public<br> <input type="radio" name="status" value="public">Public<br>
</div> </div>
<br/> <br/>
<button id="tada" type="submit"> Créer l'article </button> <button type="submit"> Créer l'article </button>
</form> </form>
{% endblock %}
{% block js %}
{% include '_js_editor.html' %}
{% endblock %} {% endblock %}

View File

@ -0,0 +1,8 @@
{% extends 'up_squelette.html' %}
{% block main %}
<h2> Ça va venir dans la prochaine version ! </h2>
{% endblock %}

View File

@ -4,9 +4,7 @@
{% block main %} {% block main %}
<div> <div>
<h3> Mon profil </h3> <h3> Mon profil </h3>
<p> <p>
@ -15,8 +13,10 @@
cela vous convient. cela vous convient.
</p> </p>
<p> Pour votre mail de secours il sert à vous envoyer un mail pour changer de mot de passe en cas de perte de ce dernier. Il n'y a <p>
pas encore de validation de l'e-mail donc vérifiez bien ce que vous tapez. </p> Pour votre mail de secours il sert à vous envoyer un mail pour changer de mot de passe en cas de perte de ce dernier. Il n'y a
pas encore de validation de l'e-mail donc vérifiez bien ce que vous tapez.
</p>
<br/> <br/>
<br/> <br/>
@ -30,40 +30,40 @@
</div> </div>
<br /> <br />
<label for="theme">Theme</label> <label for="theme">Theme</label>
<select id="theme" name="theme" required> <select id="theme" name="theme" required>
<option value="" selected>Default</option> <option value="" selected>Default</option>
<option>amber</option> <option>amber</option>
<option>blue</option> <option>blue</option>
<option>cyan</option> <option>cyan</option>
<option>fuchsia</option> <option>fuchsia</option>
<option>green</option> <option>green</option>
<option>grey</option> <option>grey</option>
<option>indigo</option> <option>indigo</option>
<option>jade</option> <option>jade</option>
<option>orange</option> <option>orange</option>
<option>rose</option> <option>rose</option>
<option>pumpkin</option> <option>pumpkin</option>
<option>purple</option> <option>purple</option>
<option>red</option> <option>red</option>
<option>sand</option> <option>sand</option>
<option>slate</option> <option>slate</option>
<option>violet</option> <option>violet</option>
<option>yellow</option> <option>yellow</option>
<option>zinc</option> <option>zinc</option>
</select> </select>
<br /> <br />
<label>Nom </label> <label>Nom </label>
<input type="text" name="nom" id="nom" value="{% if profil['nom'] != None %}{{ profil['nom'] }}{%endif%}"><br /> <input type="text" name="nom" id="nom" value="{% if profil['nom'] != None %}{{ profil['nom'] }}{%endif%}"><br />
<label>Prenom </label> <label>Prenom </label>
<input type="text" name="prenom" id="prenom" value="{% if profil['nom'] != None %}{{ profil['prenom'] }}{%endif%}"><br /> <input type="text" name="prenom" id="prenom" value="{% if profil['nom'] != None %}{{ profil['prenom'] }}{%endif%}"><br />
<label> Age </label> <label> Age </label>
<input type="text" name="age" value="{% if profil['age'] != None %}{{ profil['age'] }}{%endif%}"><br /> <input type="text" name="age" value="{% if profil['age'] != None %}{{ profil['age'] }}{%endif%}"><br />
<label> Mail de secours </label> <label> Mail de secours </label>
<input type="text" name="mail_rescue" id="mail_rescue" value="{% if profil['mail_rescue'] != None %}{{ profil['mail_rescue'] }}{%endif%}"><br /> <input type="text" name="mail_rescue" id="mail_rescue" value="{% if profil['mail_rescue'] != None %}{{ profil['mail_rescue'] }}{%endif%}"><br />
<button id="tada" class="btn btn-default btn-primary" type="submit">Envoyer</button> <button id="tada" class="btn btn-default btn-primary" type="submit">Envoyer</button>
</form> </form>

View File

@ -1,8 +1,9 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html lang="fr">
<head>
{% include '_head.html' %} {% include '_head.html' %}
{% include 'css/simple_editor.html' %}
</head>
<body> <body>
@ -20,9 +21,13 @@
{% include '_footer.html' %} {% include '_footer.html' %}
{% include '_js-core.html' %}
{% include '_js-gallery.html' %}
</body> </body>
{% include '_js-core.html' %}
{% block js %} {% endblock %}
</html> </html>

View File

@ -32,36 +32,25 @@ def init_db(database):
Mail_rescue TEXT ) Mail_rescue TEXT )
""") """)
conn.commit() conn.commit()
print ('table users Ok') print ("table users Ok")
cursor.execute("""
CREATE TABLE IF NOT EXISTS posts(
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
title TEXT,
content TEXT,
time TEXT,
category TEXT,
author TEXT,
status TEXT
)
""")
cursor.execute(""" cursor.execute("""
CREATE TABLE IF NOT EXISTS Blog_posts( CREATE TABLE IF NOT EXISTS Blog_posts(
title TEXT NOT NULL, title TEXT NOT NULL,
subtitle TEXT, subtitle TEXT,
comments TEXT, comments TEXT,
filename TEXT, content TEXT,
time TEXT, creation_date TEXT,
last_updated TEXT, last_updated TEXT,
category TEXT, category TEXT,
author TEXT, author TEXT,
status TEXT, status TEXT,
blog_theme TEXT,
PRIMARY KEY(title, author) PRIMARY KEY(title, author)
) )
""") """)
conn.commit() conn.commit()
print ("Table Blog_posts Ok !")
cursor.execute("""select * from users""") cursor.execute("""select * from users""")
accounts = cursor.fetchall() accounts = cursor.fetchall()
@ -91,10 +80,12 @@ def db_migrate(database):
cursor.execute("""SELECT name FROM PRAGMA_TABLE_INFO('users');""") cursor.execute("""SELECT name FROM PRAGMA_TABLE_INFO('users');""")
db_columns = cursor.fetchall() db_columns = cursor.fetchall()
invitations_col = False invitations_col = False
blog_theme_col = False
updated_col = False
lost_password_token_col = False lost_password_token_col = False
totp_col = False totp_col = False
blog_theme_col = False
updated_col = False
creation_date_col = False
content_col = False
for col in db_columns: for col in db_columns:
if "invitations" == col[0]: if "invitations" == col[0]:
@ -111,7 +102,12 @@ def db_migrate(database):
blog_theme_col = True blog_theme_col = True
if "last_updated" == col[0]: if "last_updated" == col[0]:
updated_col = True updated_col = True
if "content" == col[0]:
content_col = True
if "creation_date" == col[0]:
creation_date_col= True
if "category" == col[0]:
category_col= True
if not(invitations_col): if not(invitations_col):
@ -143,5 +139,20 @@ def db_migrate(database):
print ("Ajout du champ updated dans la table BLog") print ("Ajout du champ updated dans la table BLog")
if not(content_col):
cursor.execute("""ALTER TABLE Blog_posts RENAME COLUMN filename TO content;""")
conn.commit()
print ("Filename renomé en content")
if not(creation_date_col):
cursor.execute("""ALTER TABLE Blog_posts RENAME COLUMN time TO creation_date;""")
conn.commit()
print ("Time renomé en creation_date")
if not(category_col):
cursor.execute("""ALTER TABLE Blog_posts ADD COLUMN category TEXT;""")
conn.commit()
print ("Ajout de la colono category")
conn.close() conn.close()

View File

@ -28,43 +28,72 @@ DOSSIER_PUBLIC= app.config['DOSSIER_PUBLIC']+'/'
@login_required @login_required
def new_article(): def new_article():
user = '%s'% escape(session['username']) user = '%s'% escape(session['username'])
folder_blog = DOSSIER_PERSO + user + "/blog/articles/"
if request.method == 'POST': if request.method == 'POST':
title = request.form['title'] title = request.form['title']
subtitle = request.form['subtitle'] subtitle = request.form['subtitle']
category = request.form['category']
content = request.form['content'] content = request.form['content']
status = request.form['status'] status = request.form['status']
post_date = time.strftime("%d/%m/%Y %H:%M:%S") post_date = time.strftime("%d/%m/%Y %H:%M:%S")
filename = title.replace(" ", "_") + ".md"
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, subtitle, filename, time, author, status) VALUES(?, ?, ?, ?, ?, ?)""", (title, subtitle, filename, post_date, user, status)) # Insérer des valeurs cursor.execute("""INSERT INTO Blog_posts(title, subtitle, category, content, creation_date, author, status) VALUES(?, ?, ?, ?, ?, ?, ?)""", (title, subtitle, category, content, post_date, user, status)) # Insérer des valeurs
conn.commit() conn.commit()
## On génère le fichiers markdown
with open(folder_blog + filename, 'w') as f:
f.write(content)
return redirect(url_for('blog.list_articles_blog')) return redirect(url_for('blog.list_articles_blog'))
else: else:
return render_template('new_article_blog.html') return render_template('new_article_blog.html')
@blog.route('/myblog/edit/<title>', methods=['GET', 'POST'])
@login_required
def edit(title):
user='%s'% escape(session['username'])
folder_blog = DOSSIER_PERSO + user + "/blog/articles/"
if request.method == 'POST' :
title = requrest.form['title']
subtitle = request.form['subtitle']
category = request.form['category']
newcontent = request.form['content']
newstatus = request.form['status']
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))
conn.commit()
conn.close()
return redirect(url_for('blog.list_articles_blog'))
else:
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
cursor = conn.cursor() # Création de l'objet "curseur"
cursor.execute("""SELECT title, subtitle, category, content, status FROM Blog_posts WHERE title=? AND author=?""", (title, user))
oldpost = cursor.fetchone()
conn.close()
post = dict(title=oldpost[0], subtitle=oldpost[1], categoory=oldpost[2], content=oldpost[3], status=oldpost[4])
return render_template('edit_article.html',
section='Post-it',
oldpost=post)
@blog.route('/myblog/list-articles/', methods=['GET']) @blog.route('/myblog/list-articles/', methods=['GET'])
@login_required @login_required
def list_articles_blog(): 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, subtitle, time, last_updated, status FROM Blog_posts WHERE author=? """, (user,) ) cursor.execute("""SELECT title, subtitle, creation_date, last_updated, status FROM Blog_posts WHERE author=? """, (user,) )
list_posts=cursor.fetchall() list_posts=cursor.fetchall()
posts=list() posts=list()
nb_articles=0 nb_articles=0
for post in list_posts: for post in list_posts:
posts.append(dict(title=post[0], posts = [dict(title=post[0],
subtitle=post[1], subtitle=post[1],
time=post[2], time=post[2],
last_updated=post[3], last_updated=post[3],
status=post[4])) status=post[4])] + posts
nb_articles =+ 1 nb_articles =+ 1
return render_template('list_articles.html', return render_template('list_articles.html',
@ -79,60 +108,43 @@ def delete(title):
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/"
filename = title.replace(" ", "_")
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("""DELETE FROM Blog_posts WHERE title=? AND author=?""", (title, user)) cursor.execute("""DELETE FROM Blog_posts WHERE title=? AND author=?""", (title, user))
conn.commit() conn.commit()
conn.close() conn.close()
os.remove(folder_blog+filename+".md")
os.remove(folder_blog_public+filename+".html")
return redirect(url_for('blog.list_articles_blog')) return redirect(url_for('blog.list_articles_blog'))
@blog.route('/myblog/edit/<title>', methods=['GET', 'POST'])
@blog.route('/myblog/personnalize/', methods=['GET'])
@login_required @login_required
def edit(title): def personnalize_blog():
user='%s'% escape(session['username']) return render_template('personnalize_blog.html')
filename = title.replace(" ", "_") + ".md"
folder_blog = DOSSIER_PERSO + user + "/blog/articles/"
if request.method == 'POST' :
subtitle = request.form['subtitle']
newcontent = request.form['content']
newstatus = request.form['status']
updated = time.strftime("%d/%m/%Y %H:%M:%S")
conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
cursor.execute("""UPDATE Blog_posts SET subtitle=?, last_updated=?, status=? WHERE title=? AND author=?""", (subtitle, updated, newstatus, title, user))
conn.commit()
conn.close()
with open(folder_blog + filename, 'w') as f:
f.write(newcontent)
return redirect(url_for('blog.list_articles_blog'))
else:
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
cursor = conn.cursor() # Création de l'objet "curseur"
cursor.execute("""SELECT title, subtitle, status FROM Blog_posts WHERE title=? AND author=?""", (title, user))
oldpost = cursor.fetchone()
conn.close()
with open(folder_blog + filename, 'r') as f:
content = f.read()
return render_template('edit_article.html',
section='Post-it',
oldpost=oldpost,
content=content)
@blog.route('/blog/<username>/', methods=['GET']) @blog.route('/private-blog/', methods=['GET'])
def view(username): @login_required
user = username 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, subtitle, time, author FROM Blog_posts WHERE status='public' AND author=? """, (user,) ) cursor.execute("""SELECT title, subtitle, content, creation_date, last_updated, author, status FROM Blog_posts WHERE status!='draft' """ )
list_posts=cursor.fetchall()
conn.close()
posts=list()
id=0
if list_posts != None:
for post in list_posts:
posts = [dict(title=post[0], subtitle=post[1], content=post[2], creation_date=post[3], last_updated=post[4], author=post[5], status=post[6] )] + posts
else:
return redirect(BASE_URL, code=404)
return render_template('index_blog.html', section='Blog', posts=posts)
@blog.route('/blog/', methods=['GET'])
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 FROM Blog_posts WHERE status='public'""" )
list_posts=cursor.fetchall() list_posts=cursor.fetchall()
posts=list() posts=list()
id=0 id=0
@ -141,29 +153,46 @@ def view(username):
print (list_posts) print (list_posts)
if list_posts != None: if list_posts != None:
for post in list_posts: for post in list_posts:
posts.append(dict(title=post[0], subtitle=post[1], time=post[2], author=post[3])) posts=[dict(title=post[0], subtitle=post[1], creation_date=post[2], author=post[3], status=post[4])] + posts
else: else:
return redirect(BASE_URL, code=404) return redirect(BASE_URL, code=404)
return render_template('index_blog.html', section='Blog', posts=posts, user=user) return render_template('index_blog.html', section='Blog', posts=posts)
@blog.route('/blog/<username>/<title>', methods=['GET']) @blog.route('/blog/private/<username>/<title>', methods=['GET'])
def viewArticle(username, title): @login_required
folder_blog = DOSSIER_PERSO + username + "/blog/articles/" def viewPrivateArticle(username, title):
filename = title.replace(" ", "_") + ".md"
user = username user = 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, subtitle, time, author FROM Blog_posts WHERE author=? AND title=? """, (user, title) ) cursor.execute("""SELECT title, subtitle, content, creation_date, last_updated, author, status FROM Blog_posts WHERE author=? AND title=? AND status!='draft' """, (user, title) )
post = cursor.fetchone() post = cursor.fetchone()
conn.close() conn.close()
if post != None: if post != None:
post_info = (dict(title=post[0], subtitle=post[1], time=post[2], author=post[3])) post_info = (dict(title=post[0], subtitle=post[1], creation_date=post[3], last_updated=post[4],author=post[5]))
with open(folder_blog + filename, 'r') as f: content= markdown(post[2])
content_md = f.read()
content = markdown(content_md)
return render_template('blog.html', post_info=post_info, content=content) return render_template('blog.html', post_info=post_info, content=content)
else: else:
flash(u"Cet article n'existe pas", 'error'); return redirect(url_for('blog'), code=404);
@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) )
post = cursor.fetchone()
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])
return render_template('blog.html', post_info=post_info, content=content)
else:
return redirect(url_for('blog'), code=404);