addition of an author's blog consultation
This commit is contained in:
parent
603c19de26
commit
1619a27cf7
@ -8,27 +8,34 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
{% if not(posts) %}
|
||||||
|
<h1 style="text-align: center;"> Désolé ce blog n'existe pas encore :/ </h1>
|
||||||
|
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
|
||||||
<div class="articles">
|
<div class="articles">
|
||||||
{% 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/{{user}}/{{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 }}
|
||||||
</time>
|
</time>
|
||||||
<br/>
|
<br/>
|
||||||
{% if post.last_updated %}
|
{% if post.last_updated %}
|
||||||
<time datetime="{{ post.last_updated }}">
|
<time datetime="{{ post.last_updated }}">
|
||||||
Mis à jour le {{ post.last_updated }}
|
Mis à jour le {{ post.last_updated }}
|
||||||
</time>
|
</time>
|
||||||
|
|
||||||
{% endif %}
|
{% 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/{{ post.status }}/{{post.author}}/{{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>
|
||||||
|
{% endif %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@ -49,9 +49,7 @@ def new_article():
|
|||||||
@login_required
|
@login_required
|
||||||
def edit(title):
|
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 = requrest.form['title']
|
||||||
subtitle = request.form['subtitle']
|
subtitle = request.form['subtitle']
|
||||||
@ -64,7 +62,6 @@ def edit(title):
|
|||||||
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))
|
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'))
|
||||||
else:
|
else:
|
||||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
@ -90,21 +87,22 @@ def list_articles_blog():
|
|||||||
nb_articles=0
|
nb_articles=0
|
||||||
for post in list_posts:
|
for post in list_posts:
|
||||||
posts = [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])] + posts
|
status=post[4])] + posts
|
||||||
nb_articles =+ 1
|
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):
|
||||||
|
title = escape(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/"
|
||||||
@ -131,7 +129,6 @@ def view_internal():
|
|||||||
conn.close()
|
conn.close()
|
||||||
posts=list()
|
posts=list()
|
||||||
id=0
|
id=0
|
||||||
|
|
||||||
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], content=post[2], creation_date=post[3], last_updated=post[4], author=post[5], status=post[6] )] + 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
|
||||||
@ -144,13 +141,11 @@ 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 FROM Blog_posts WHERE status='public'""" )
|
cursor.execute("""SELECT title, subtitle, creation_date, author, status FROM Blog_posts WHERE status='public'""" )
|
||||||
list_posts=cursor.fetchall()
|
list_posts=cursor.fetchall()
|
||||||
posts=list()
|
posts=list()
|
||||||
id=0
|
id=0
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
print (list_posts)
|
|
||||||
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
|
||||||
@ -160,19 +155,41 @@ def view():
|
|||||||
|
|
||||||
return render_template('index_blog.html', section='Blog', posts=posts)
|
return render_template('index_blog.html', section='Blog', posts=posts)
|
||||||
|
|
||||||
|
|
||||||
|
@blog.route('/blog/<author>/', methods=['GET'])
|
||||||
|
def viewuser(author):
|
||||||
|
author = escape(author)
|
||||||
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||||
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||||
|
cursor.execute("""SELECT title, subtitle, creation_date, last_updated, author FROM Blog_posts WHERE author=? AND status='public' """, (author,))
|
||||||
|
list_posts=cursor.fetchall()
|
||||||
|
posts=None
|
||||||
|
id=0
|
||||||
|
conn.close()
|
||||||
|
if list_posts != None:
|
||||||
|
posts=list()
|
||||||
|
for post in list_posts:
|
||||||
|
posts=[dict(title=post[0], subtitle=post[1], creation_date=post[2], author=post[3], status=post[4])] + posts
|
||||||
|
else:
|
||||||
|
return redirect(BASE_URL, code=404)
|
||||||
|
|
||||||
|
|
||||||
|
return render_template('index_blog.html', section='Blog', posts=posts)
|
||||||
|
|
||||||
|
|
||||||
@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):
|
||||||
user = username
|
user = escape(username)
|
||||||
|
title = escape(title)
|
||||||
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 author=? AND title=? AND status!='draft' """, (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], creation_date=post[3], last_updated=post[4],author=post[5]))
|
post_info = (dict(title=post[0], subtitle=post[1], creation_date=post[3], last_updated=post[4],author=post[5]))
|
||||||
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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user