Work on blog
rewrite entire blog section
This commit is contained in:
parent
68d798845d
commit
a5ba0b90bb
@ -22,13 +22,20 @@
|
|||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="/myblog/personnalize/" {% if request.path == "/myblog/personnalize/" %} 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
|
Personnaliser mon blog
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="/private-blog/" {% if request.path == "/private-blog/" %} class="invert" {% endif %} ><span class="icons view-blog" aria-hidden="true"></span>
|
<a href="/myblog/" {% if request.path == "/myblog/" %} class="invert" {% endif %} ><span class="icons view-blog" aria-hidden="true"></span>
|
||||||
Voir le blog
|
Voir mon blog
|
||||||
</a>
|
</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>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
<h2 class="titre"> {{ post_info.title }} </h2>
|
<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 %}
|
{% if post_info.last_updated %}
|
||||||
<h5 class="titre">Mis à jour le : {{ post_info.last_updated }} </h5>
|
<h5 class="titre">Mis à jour le : {{ post_info.last_updated }} </h5>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
26
templates/blog_author.html
Normal file
26
templates/blog_author.html
Normal 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
35
templates/blog_rss.xml
Normal 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>
|
||||||
@ -1,17 +1,18 @@
|
|||||||
{% extends 'up_squelette.html' %}
|
{% extends 'up_squelette.html' %}
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
|
|
||||||
<p>Vous pouvez modifier votre article. </p>
|
|
||||||
|
|
||||||
|
|
||||||
<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="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="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 />
|
<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>
|
<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>
|
||||||
@ -34,15 +35,23 @@
|
|||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</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>
|
<button type="submit"> Mettre à jour </button>
|
||||||
</form>
|
</form>
|
||||||
<br />
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
{% block js %}
|
{% block js %}
|
||||||
{% include '_js_editor.html' %}
|
{% include '_js_editor.html' %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
41
templates/index_author_blog.html
Normal file
41
templates/index_author_blog.html
Normal 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>
|
||||||
@ -14,13 +14,15 @@
|
|||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
|
|
||||||
<div class="articles">
|
<div class="articles">
|
||||||
|
<a href="/blog/rss.xml"> S'abonner au flux RSS </a>
|
||||||
{% for post in posts %}
|
{% 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>
|
<small>
|
||||||
<time datetime="{{ post.time }}">
|
<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>
|
</time>
|
||||||
<br/>
|
<br/>
|
||||||
{% if post.last_updated %}
|
{% if post.last_updated %}
|
||||||
|
|||||||
@ -3,9 +3,10 @@
|
|||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
|
|
||||||
|
{% if nb_articles > 1 %}
|
||||||
<h2> Vos articles de blog </h2>
|
<h2> Vos {{ nb_articles }} articles de blog </h2>
|
||||||
|
{% endif %}
|
||||||
|
<br/>
|
||||||
|
|
||||||
{% for article in list_posts %}
|
{% for article in list_posts %}
|
||||||
<article>
|
<article>
|
||||||
@ -14,9 +15,25 @@
|
|||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
<small> Créé le : {{ article.time }} </small> <br/>
|
<small> Créé le : {{ article.time }} </small> <br/>
|
||||||
<small> Modifié le : {{ article.last_updated }}</small>
|
|
||||||
<p> Status : {{ article.status }}</p>
|
{% if article.last_updated == "private" %}
|
||||||
<br/>
|
<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.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>
|
<a href="{{ url_for('blog.delete', title=article.title) }}"><button type="button">Supprimer</button></a>
|
||||||
|
|||||||
@ -32,6 +32,18 @@
|
|||||||
<input type="radio" name="status" value="public">Public<br>
|
<input type="radio" name="status" value="public">Public<br>
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<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>
|
<button type="submit"> Créer l'article </button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,32 @@
|
|||||||
|
|
||||||
{% block main %}
|
{% 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 %}
|
{% endblock %}
|
||||||
|
|||||||
@ -45,7 +45,6 @@ def init_db(database):
|
|||||||
category TEXT,
|
category TEXT,
|
||||||
author TEXT,
|
author TEXT,
|
||||||
status TEXT,
|
status TEXT,
|
||||||
blog_theme TEXT,
|
|
||||||
PRIMARY KEY(title, author)
|
PRIMARY KEY(title, author)
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
@ -74,19 +73,22 @@ def check_directories(users_folder):
|
|||||||
print("Le dossier {} a été créé".format(users_folder))
|
print("Le dossier {} a été créé".format(users_folder))
|
||||||
|
|
||||||
def db_migrate(database):
|
def db_migrate(database):
|
||||||
|
|
||||||
|
|
||||||
|
invitations_col = False
|
||||||
|
lost_password_token_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)
|
conn = sqlite3.connect(database)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
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
|
|
||||||
lost_password_token_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]:
|
||||||
invitations_col = True
|
invitations_col = True
|
||||||
@ -94,12 +96,13 @@ def db_migrate(database):
|
|||||||
lost_password_token_col = True
|
lost_password_token_col = True
|
||||||
if "totp" == col[0]:
|
if "totp" == col[0]:
|
||||||
totp_col = True
|
totp_col = True
|
||||||
|
if "blog_theme" == col[0]:
|
||||||
|
blog_theme_col = True
|
||||||
|
|
||||||
|
|
||||||
cursor.execute("""SELECT name FROM PRAGMA_TABLE_INFO('Blog_posts');""")
|
cursor.execute("""SELECT name FROM PRAGMA_TABLE_INFO('Blog_posts');""")
|
||||||
db_columns = cursor.fetchall()
|
db_columns = cursor.fetchall()
|
||||||
for col in db_columns:
|
for col in db_columns:
|
||||||
if "blog_theme" == col[0]:
|
|
||||||
blog_theme_col = True
|
|
||||||
if "last_updated" == col[0]:
|
if "last_updated" == col[0]:
|
||||||
updated_col = True
|
updated_col = True
|
||||||
if "content" == col[0]:
|
if "content" == col[0]:
|
||||||
@ -125,8 +128,7 @@ def db_migrate(database):
|
|||||||
cursor.execute("""ALTER TABLE Users ADD COLUMN totp CHAR(40);""")
|
cursor.execute("""ALTER TABLE Users ADD COLUMN totp CHAR(40);""")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
print ("Ajout du champ totp dans la table Users")
|
print ("Ajout du champ totp dans la table Users")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if not(blog_theme_col):
|
if not(blog_theme_col):
|
||||||
cursor.execute("""ALTER TABLE Blog_posts ADD COLUMN blog_theme TEXT;""")
|
cursor.execute("""ALTER TABLE Blog_posts ADD COLUMN blog_theme TEXT;""")
|
||||||
|
|||||||
165
views/blog.py
165
views/blog.py
@ -7,6 +7,7 @@ import sqlite3
|
|||||||
from markdown import markdown
|
from markdown import markdown
|
||||||
from tools.filesutils import getFileSizeKo
|
from tools.filesutils import getFileSizeKo
|
||||||
import string
|
import string
|
||||||
|
from shutil import copy
|
||||||
from tools.utils import login_required
|
from tools.utils import login_required
|
||||||
|
|
||||||
blog = Blueprint('blog', __name__, template_folder='templates')
|
blog = Blueprint('blog', __name__, template_folder='templates')
|
||||||
@ -18,10 +19,11 @@ app.config.from_pyfile('config.py')
|
|||||||
########################### Variables Globales #################################
|
########################### Variables Globales #################################
|
||||||
extensionimg = app.config['EXT_IMG']
|
extensionimg = app.config['EXT_IMG']
|
||||||
DATABASE = app.config['DATABASE']
|
DATABASE = app.config['DATABASE']
|
||||||
BASE_URL= app.config['BASE_URL']
|
BASE_URL = app.config['BASE_URL']
|
||||||
DOSSIER_PERSO= app.config['DOSSIER_APP']+'/'
|
DOSSIER_PERSO = app.config['DOSSIER_APP']+'/'
|
||||||
DOSSIER_PUBLIC= app.config['DOSSIER_PUBLIC']+'/'
|
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'])
|
@blog.route('/myblog/new-article/', methods=['GET', 'POST'])
|
||||||
@ -30,12 +32,14 @@ def new_article():
|
|||||||
user = '%s'% escape(session['username'])
|
user = '%s'% escape(session['username'])
|
||||||
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']
|
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")
|
||||||
|
if 'blog-unified' in request.form.keys():
|
||||||
|
status = status+'_unified'
|
||||||
|
|
||||||
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, category, content, creation_date, author, status) VALUES(?, ?, ?, ?, ?, ?, ?)""", (title, subtitle, category, content, 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
|
||||||
@ -51,7 +55,7 @@ def edit(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/"
|
||||||
if request.method == 'POST' :
|
if request.method == 'POST' :
|
||||||
title = requrest.form['title']
|
title = request.form['title']
|
||||||
subtitle = request.form['subtitle']
|
subtitle = request.form['subtitle']
|
||||||
category = request.form['category']
|
category = request.form['category']
|
||||||
newcontent = request.form['content']
|
newcontent = request.form['content']
|
||||||
@ -59,7 +63,10 @@ def edit(title):
|
|||||||
updated = time.strftime("%d/%m/%Y %H:%M:%S")
|
updated = time.strftime("%d/%m/%Y %H:%M:%S")
|
||||||
conn = sqlite3.connect(DATABASE)
|
conn = sqlite3.connect(DATABASE)
|
||||||
cursor = conn.cursor()
|
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.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
return redirect(url_for('blog.list_articles_blog'))
|
return redirect(url_for('blog.list_articles_blog'))
|
||||||
@ -91,14 +98,13 @@ def list_articles_blog():
|
|||||||
time=post[2],
|
time=post[2],
|
||||||
last_updated=post[3],
|
last_updated=post[3],
|
||||||
status=post[4])] + posts
|
status=post[4])] + posts
|
||||||
nb_articles =+ 1
|
nb_articles = nb_articles + 1
|
||||||
|
|
||||||
return render_template('list_articles.html',
|
return render_template('list_articles.html',
|
||||||
section="Articles",
|
section="Articles",
|
||||||
list_posts=posts,
|
list_posts=posts,
|
||||||
nb_articles=nb_articles
|
nb_articles=nb_articles )
|
||||||
)
|
|
||||||
|
|
||||||
@blog.route('/myblog/delete/<title>')
|
@blog.route('/myblog/delete/<title>')
|
||||||
@login_required
|
@login_required
|
||||||
def delete(title):
|
def delete(title):
|
||||||
@ -114,17 +120,62 @@ def delete(title):
|
|||||||
return redirect(url_for('blog.list_articles_blog'))
|
return redirect(url_for('blog.list_articles_blog'))
|
||||||
|
|
||||||
|
|
||||||
@blog.route('/myblog/personnalize/', methods=['GET'])
|
@blog.route('/myblog/personnalize/', methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def personnalize_blog():
|
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'])
|
@blog.route('/private-blog/', methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
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, 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()
|
list_posts=cursor.fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
posts=list()
|
posts=list()
|
||||||
@ -141,17 +192,14 @@ 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, 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()
|
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=post[0], subtitle=post[1], creation_date=post[2], author=post[3], status=post[4])] + 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)
|
return render_template('index_blog.html', section='Blog', posts=posts)
|
||||||
|
|
||||||
@ -161,22 +209,46 @@ def viewuser(author):
|
|||||||
author = escape(author)
|
author = escape(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 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()
|
list_posts=cursor.fetchall()
|
||||||
posts=None
|
posts=None
|
||||||
id=0
|
id=0
|
||||||
conn.close()
|
conn.close()
|
||||||
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=post[0], subtitle=post[1], creation_date=post[2], author=post[3], status=post[4])] + posts
|
posts=[dict(title=post[0], subtitle=post[1], creation_date=post[2], last_updated=post[3], author=post[4], status=post[5])] + posts
|
||||||
else:
|
|
||||||
return redirect(BASE_URL, code=404)
|
|
||||||
|
|
||||||
|
|
||||||
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'])
|
@blog.route('/blog/private/<username>/<title>', methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
def viewPrivateArticle(username, title):
|
def viewPrivateArticle(username, title):
|
||||||
@ -192,17 +264,16 @@ def viewPrivateArticle(username, title):
|
|||||||
content= markdown(post[2])
|
content= markdown(post[2])
|
||||||
return render_template('blog.html', post_info=post_info, content=content)
|
return render_template('blog.html', post_info=post_info, content=content)
|
||||||
else:
|
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'])
|
@blog.route('/blog/public/<username>/<title>', methods=['GET'])
|
||||||
def viewArticle(username, title):
|
def viewArticle(username, title):
|
||||||
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, 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()
|
post = cursor.fetchone()
|
||||||
conn.close()
|
conn.close()
|
||||||
if post != None:
|
if post != None:
|
||||||
@ -211,5 +282,29 @@ def viewArticle(username, title):
|
|||||||
|
|
||||||
return render_template('blog.html', post_info=post_info, content=content)
|
return render_template('blog.html', post_info=post_info, content=content)
|
||||||
else:
|
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)
|
||||||
|
|
||||||
|
|||||||
@ -173,7 +173,16 @@ def remove_publicFile(filename):
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
flash(u'Fichier {filename} inexistant.'.format(filename=filename), 'error')
|
flash(u'Fichier {filename} inexistant.'.format(filename=filename), 'error')
|
||||||
return redirect(url_for('filesupload.list', _external=True))
|
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')
|
@filesupload.route('/theme.min.css')
|
||||||
def theme():
|
def theme():
|
||||||
if 'username' in session:
|
if 'username' in session:
|
||||||
|
|||||||
@ -327,8 +327,9 @@ def totp_qrcode():
|
|||||||
os.path.join(DOSSIER_PERSO, user, "totp.png"), "totp.png")
|
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) :
|
def deltoken_passwd_lost(token) :
|
||||||
|
token = escape(token)
|
||||||
if valid_token_register(token, "Lost password"):
|
if valid_token_register(token, "Lost password"):
|
||||||
user = get_user_by_token(token, "Lost password")
|
user = get_user_by_token(token, "Lost password")
|
||||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user