Rework blog section
Wrok in bloc sectionn
This commit is contained in:
parent
0e282894a6
commit
57241b843b
90
static/simplemde-custom.css
Normal file
90
static/simplemde-custom.css
Normal 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: '
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<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='pywallter.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">
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
@ -21,13 +21,13 @@
|
||||
</a>
|
||||
</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
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/myblog/view/" {% if request.path == "/myblog/view/" %} class="invert" {% endif %} ><span class="icons view-blog" aria-hidden="true"></span>
|
||||
Voir mon blog
|
||||
<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>
|
||||
</li>
|
||||
</ul>
|
||||
@ -46,6 +46,7 @@
|
||||
<li>
|
||||
<a href="/filesupload/" {% if request.path == "/filesupload/" %} class="invert" {% endif %}> <span class="icons send-files"></span> Envoyer des fichiers </a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
@ -66,7 +67,6 @@
|
||||
Gerer mes alias
|
||||
</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title> Blog de {{ user }} </title>
|
||||
<title> Article de {{ post_info.author }} </title>
|
||||
<link rel="stylesheet" href="/static/blog.css" type="text/css">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
@ -12,9 +12,11 @@
|
||||
|
||||
<h2 class="titre"> {{ post_info.title }} </h2>
|
||||
|
||||
<h5 class="titre">Publié le {{ post_info.time }} </h5>
|
||||
|
||||
<h2 class="description titre"> {{ post_info.subtitle }} </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 }}
|
||||
|
||||
|
||||
3
templates/css/simple_editor.html
Normal file
3
templates/css/simple_editor.html
Normal 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">
|
||||
@ -2,27 +2,40 @@
|
||||
|
||||
{% 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;">
|
||||
|
||||
<input type="text" name="subtitle" id="subtitle" placeholder="Titre" class="form-control" value="{{ oldpost[1] }}"><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="subtitle" id="subtitle" placeholder="sous-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 />
|
||||
<h3> Visibilité </h3>
|
||||
<div class="center">
|
||||
{% if oldpost[2] == 'public' %}
|
||||
<input type="radio" name="status" value="prive"> 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>
|
||||
|
||||
|
||||
{% 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
|
||||
|
||||
{% else %}
|
||||
<input type="radio" name="status" value="Privé" checked> Privé
|
||||
{% elif oldpost['status'] == 'private' %}
|
||||
<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"> Brouillon
|
||||
<input type="radio" name="status" value="private" checked> Privé
|
||||
<input type="radio" name="status" value="public"> Publique
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
<br />
|
||||
|
||||
<button type="submit"> Mettre à jour </button>
|
||||
</form>
|
||||
<br />
|
||||
@ -30,3 +43,7 @@
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block js %}
|
||||
{% include '_js_editor.html' %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title> Blog de {{ user }} </title>
|
||||
<title> Le Blog du serveur </title>
|
||||
<link rel="stylesheet" href="/static/blog.css" type="text/css">
|
||||
<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>
|
||||
<small>
|
||||
<time datetime="{{ post.time }}">
|
||||
Publié le {{ 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">
|
||||
<div class="slug">
|
||||
<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>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
@ -15,20 +15,31 @@
|
||||
<br />
|
||||
|
||||
<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="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>
|
||||
<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">
|
||||
<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>
|
||||
</div>
|
||||
<br/>
|
||||
<button id="tada" type="submit"> Créer l'article </button>
|
||||
<button type="submit"> Créer l'article </button>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{% include '_js_editor.html' %}
|
||||
{% endblock %}
|
||||
|
||||
8
templates/personnalize_blog.html
Normal file
8
templates/personnalize_blog.html
Normal file
@ -0,0 +1,8 @@
|
||||
{% extends 'up_squelette.html' %}
|
||||
|
||||
|
||||
{% block main %}
|
||||
|
||||
<h2> Ça va venir dans la prochaine version ! </h2>
|
||||
|
||||
{% endblock %}
|
||||
@ -4,9 +4,7 @@
|
||||
{% block main %}
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
<h3> Mon profil </h3>
|
||||
<p>
|
||||
@ -15,8 +13,10 @@
|
||||
cela vous convient.
|
||||
</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
|
||||
pas encore de validation de l'e-mail donc vérifiez bien ce que vous tapez. </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
|
||||
pas encore de validation de l'e-mail donc vérifiez bien ce que vous tapez.
|
||||
</p>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
@ -30,40 +30,40 @@
|
||||
</div>
|
||||
<br />
|
||||
|
||||
<label for="theme">Theme</label>
|
||||
<select id="theme" name="theme" required>
|
||||
<option value="" selected>Default</option>
|
||||
<option>amber</option>
|
||||
<option>blue</option>
|
||||
<option>cyan</option>
|
||||
<option>fuchsia</option>
|
||||
<option>green</option>
|
||||
<option>grey</option>
|
||||
<option>indigo</option>
|
||||
<option>jade</option>
|
||||
<option>orange</option>
|
||||
<option>rose</option>
|
||||
<option>pumpkin</option>
|
||||
<option>purple</option>
|
||||
<option>red</option>
|
||||
<option>sand</option>
|
||||
<option>slate</option>
|
||||
<option>violet</option>
|
||||
<option>yellow</option>
|
||||
<option>zinc</option>
|
||||
</select>
|
||||
<label for="theme">Theme</label>
|
||||
<select id="theme" name="theme" required>
|
||||
<option value="" selected>Default</option>
|
||||
<option>amber</option>
|
||||
<option>blue</option>
|
||||
<option>cyan</option>
|
||||
<option>fuchsia</option>
|
||||
<option>green</option>
|
||||
<option>grey</option>
|
||||
<option>indigo</option>
|
||||
<option>jade</option>
|
||||
<option>orange</option>
|
||||
<option>rose</option>
|
||||
<option>pumpkin</option>
|
||||
<option>purple</option>
|
||||
<option>red</option>
|
||||
<option>sand</option>
|
||||
<option>slate</option>
|
||||
<option>violet</option>
|
||||
<option>yellow</option>
|
||||
<option>zinc</option>
|
||||
</select>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<label>Nom </label>
|
||||
<input type="text" name="nom" id="nom" value="{% if profil['nom'] != None %}{{ profil['nom'] }}{%endif%}"><br />
|
||||
<label>Prenom </label>
|
||||
<input type="text" name="prenom" id="prenom" value="{% if profil['nom'] != None %}{{ profil['prenom'] }}{%endif%}"><br />
|
||||
<label> Age </label>
|
||||
<input type="text" name="age" value="{% if profil['age'] != None %}{{ profil['age'] }}{%endif%}"><br />
|
||||
<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 />
|
||||
<button id="tada" class="btn btn-default btn-primary" type="submit">Envoyer</button>
|
||||
<label>Nom </label>
|
||||
<input type="text" name="nom" id="nom" value="{% if profil['nom'] != None %}{{ profil['nom'] }}{%endif%}"><br />
|
||||
<label>Prenom </label>
|
||||
<input type="text" name="prenom" id="prenom" value="{% if profil['nom'] != None %}{{ profil['prenom'] }}{%endif%}"><br />
|
||||
<label> Age </label>
|
||||
<input type="text" name="age" value="{% if profil['age'] != None %}{{ profil['age'] }}{%endif%}"><br />
|
||||
<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 />
|
||||
<button id="tada" class="btn btn-default btn-primary" type="submit">Envoyer</button>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
|
||||
{% include '_head.html' %}
|
||||
|
||||
<head>
|
||||
{% include '_head.html' %}
|
||||
{% include 'css/simple_editor.html' %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@ -20,9 +21,13 @@
|
||||
|
||||
|
||||
{% include '_footer.html' %}
|
||||
{% include '_js-core.html' %}
|
||||
{% include '_js-gallery.html' %}
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
{% include '_js-core.html' %}
|
||||
|
||||
|
||||
{% block js %} {% endblock %}
|
||||
</html>
|
||||
|
||||
@ -32,36 +32,25 @@ def init_db(database):
|
||||
Mail_rescue TEXT )
|
||||
""")
|
||||
conn.commit()
|
||||
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
|
||||
)
|
||||
""")
|
||||
print ("table users Ok")
|
||||
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS Blog_posts(
|
||||
title TEXT NOT NULL,
|
||||
subtitle TEXT,
|
||||
comments TEXT,
|
||||
filename TEXT,
|
||||
time TEXT,
|
||||
content TEXT,
|
||||
creation_date TEXT,
|
||||
last_updated TEXT,
|
||||
category TEXT,
|
||||
author TEXT,
|
||||
status TEXT,
|
||||
blog_theme TEXT,
|
||||
PRIMARY KEY(title, author)
|
||||
)
|
||||
""")
|
||||
conn.commit()
|
||||
|
||||
print ("Table Blog_posts Ok !")
|
||||
|
||||
cursor.execute("""select * from users""")
|
||||
accounts = cursor.fetchall()
|
||||
@ -91,10 +80,12 @@ def db_migrate(database):
|
||||
cursor.execute("""SELECT name FROM PRAGMA_TABLE_INFO('users');""")
|
||||
db_columns = cursor.fetchall()
|
||||
invitations_col = False
|
||||
blog_theme_col = False
|
||||
updated_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:
|
||||
if "invitations" == col[0]:
|
||||
@ -111,7 +102,12 @@ def db_migrate(database):
|
||||
blog_theme_col = True
|
||||
if "last_updated" == col[0]:
|
||||
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):
|
||||
@ -143,5 +139,20 @@ def db_migrate(database):
|
||||
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()
|
||||
|
||||
163
views/blog.py
163
views/blog.py
@ -28,43 +28,72 @@ DOSSIER_PUBLIC= app.config['DOSSIER_PUBLIC']+'/'
|
||||
@login_required
|
||||
def new_article():
|
||||
user = '%s'% escape(session['username'])
|
||||
folder_blog = DOSSIER_PERSO + user + "/blog/articles/"
|
||||
if request.method == 'POST':
|
||||
title = request.form['title']
|
||||
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")
|
||||
filename = title.replace(" ", "_") + ".md"
|
||||
|
||||
|
||||
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, 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()
|
||||
## 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'))
|
||||
else:
|
||||
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'])
|
||||
@login_required
|
||||
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, 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()
|
||||
posts=list()
|
||||
nb_articles=0
|
||||
for post in list_posts:
|
||||
posts.append(dict(title=post[0],
|
||||
posts = [dict(title=post[0],
|
||||
subtitle=post[1],
|
||||
time=post[2],
|
||||
last_updated=post[3],
|
||||
status=post[4]))
|
||||
status=post[4])] + posts
|
||||
nb_articles =+ 1
|
||||
|
||||
return render_template('list_articles.html',
|
||||
@ -79,60 +108,43 @@ def delete(title):
|
||||
user='%s'% escape(session['username'])
|
||||
folder_blog = DOSSIER_PERSO + user + "/blog/articles/"
|
||||
folder_blog_public = DOSSIER_PUBLIC + user + "/blog/articles/"
|
||||
filename = title.replace(" ", "_")
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||
cursor.execute("""DELETE FROM Blog_posts WHERE title=? AND author=?""", (title, user))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
os.remove(folder_blog+filename+".md")
|
||||
os.remove(folder_blog_public+filename+".html")
|
||||
return redirect(url_for('blog.list_articles_blog'))
|
||||
|
||||
@blog.route('/myblog/edit/<title>', methods=['GET', 'POST'])
|
||||
|
||||
@blog.route('/myblog/personnalize/', methods=['GET'])
|
||||
@login_required
|
||||
def edit(title):
|
||||
user='%s'% escape(session['username'])
|
||||
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)
|
||||
def personnalize_blog():
|
||||
return render_template('personnalize_blog.html')
|
||||
|
||||
@blog.route('/blog/<username>/', methods=['GET'])
|
||||
def view(username):
|
||||
user = username
|
||||
@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, 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()
|
||||
posts=list()
|
||||
id=0
|
||||
@ -141,29 +153,46 @@ def view(username):
|
||||
print (list_posts)
|
||||
if list_posts != None:
|
||||
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:
|
||||
return redirect(BASE_URL, code=404)
|
||||
|
||||
|
||||
return render_template('index_blog.html', section='Blog', posts=posts, user=user)
|
||||
|
||||
@blog.route('/blog/<username>/<title>', methods=['GET'])
|
||||
def viewArticle(username, title):
|
||||
folder_blog = DOSSIER_PERSO + username + "/blog/articles/"
|
||||
filename = title.replace(" ", "_") + ".md"
|
||||
return render_template('index_blog.html', section='Blog', posts=posts)
|
||||
|
||||
@blog.route('/blog/private/<username>/<title>', methods=['GET'])
|
||||
@login_required
|
||||
def viewPrivateArticle(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, 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()
|
||||
conn.close()
|
||||
if post != None:
|
||||
post_info = (dict(title=post[0], subtitle=post[1], time=post[2], author=post[3]))
|
||||
with open(folder_blog + filename, 'r') as f:
|
||||
content_md = f.read()
|
||||
content = markdown(content_md)
|
||||
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:
|
||||
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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user