addition of an author's blog consultation
This commit is contained in:
parent
603c19de26
commit
1619a27cf7
@ -8,6 +8,12 @@
|
||||
</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 %}
|
||||
|
||||
@ -30,5 +36,6 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -49,9 +49,7 @@ def new_article():
|
||||
@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']
|
||||
@ -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))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
return redirect(url_for('blog.list_articles_blog'))
|
||||
else:
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
@ -105,6 +102,7 @@ def list_articles_blog():
|
||||
@blog.route('/myblog/delete/<title>')
|
||||
@login_required
|
||||
def delete(title):
|
||||
title = escape(title)
|
||||
user='%s'% escape(session['username'])
|
||||
folder_blog = DOSSIER_PERSO + user + "/blog/articles/"
|
||||
folder_blog_public = DOSSIER_PUBLIC + user + "/blog/articles/"
|
||||
@ -131,7 +129,6 @@ def view_internal():
|
||||
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
|
||||
@ -144,13 +141,11 @@ def view_internal():
|
||||
def view():
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||
cursor.execute("""SELECT title, subtitle, creation_date, author 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()
|
||||
posts=list()
|
||||
id=0
|
||||
|
||||
conn.close()
|
||||
print (list_posts)
|
||||
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
|
||||
@ -160,10 +155,33 @@ def view():
|
||||
|
||||
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'])
|
||||
@login_required
|
||||
def viewPrivateArticle(username, title):
|
||||
user = username
|
||||
user = escape(username)
|
||||
title = escape(title)
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||
cursor.execute("""SELECT title, subtitle, content, creation_date, last_updated, author, status FROM Blog_posts WHERE author=? AND title=? AND status!='draft' """, (user, title))
|
||||
@ -172,7 +190,6 @@ def viewPrivateArticle(username, title):
|
||||
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