Amélioration des post-it Ajout supp son compte

This commit is contained in:
2023-07-06 05:07:34 +02:00
parent 2eb2d7fe98
commit 1ce6020bff
17 changed files with 486 additions and 130 deletions

View File

@@ -35,48 +35,55 @@ def racine_blog():
content = request.form['content']
#category = request.form['category']
status = request.form['status']
TIME=time.strftime("%A %d %B %Y %H:%M:%S")
post_date = time.strftime("%A %d %B %Y %H:%M:%S")
conn = sqlite3.connect(DATABASE) # Connexion la base de donne
cursor = conn.cursor() # Création de l'objet "curseur"
cursor.execute("""INSERT INTO posts(title, content, time, author, status) VALUES(?, ?, ?, ?, ?)""",
(title, content, TIME, UTILISATEUR, status)) # Insérer des valeurs
cursor.execute("""INSERT INTO posts(title, content, time, author, status) VALUES(?, ?, ?, ?, ?)""", (title, content, post_date, UTILISATEUR, status)) # Insérer des valeurs
conn.commit()
cursor.execute("""SELECT title, content, time, author, status, avatar, nom, prenom, age FROM posts INNER JOIN users ON author = name""")
posts = [dict(title=row[0], content=row[1], time=row[2], author=row[3],
status=row[4], avatar=row[5], nom=row[6], prenom=row[7], age=row[8])
for row in reversed(cursor.fetchall())]
cursor.execute("""SELECT avatar FROM users WHERE name=? """, (UTILISATEUR,))
user_info = cursor.fetchone()
cursor.execute("""SELECT title, content, time, author, status FROM posts where author=?""" , (UTILISATEUR,))
list_posts = cursor.fetchall()
conn.close()
posts=list()
id=0
for post in list_posts:
posts.append(dict(title=post[0], id_postit=id ,content=markdown(post[1]), time=post[2], author=post[3],status=post[4], avatar=user_info[0]))
id=id+1
return render_template('blog.html', posts=posts)
else:
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
cursor = conn.cursor() # Création de l'objet "curseur"
cursor.execute("""SELECT title, content, time, author, status, avatar, nom, prenom, age FROM posts INNER JOIN users ON author = name""")
posts = [dict(title=row[0], content=row[1], time=row[2], author=row[3],
status=row[4], avatar=row[5], nom=row[6], prenom=row[7], age=row[8])
for row in reversed(cursor.fetchall())]
cursor.execute("""SELECT avatar FROM users WHERE name=?""", (UTILISATEUR,))
user_info = cursor.fetchone()
cursor.execute("""SELECT title, content, time, author, status FROM posts WHERE author=?""" , (UTILISATEUR,))
list_posts = cursor.fetchall()
conn.close()
for post in posts:
post['content'] = markdown(post['content'])
posts=list()
id=0
for post in list_posts:
posts.append(dict(title=post[0], id_postit=id, content=markdown(post[1]), time=post[2], author=post[3],status=post[4], avatar=user_info[0]))
id=id+1
return render_template('blog.html', section='Post-it', posts=posts)
else:
return redirect(BASE_URL, code=401)
@postit.route('/delete/<post>')
def delete(post):
@postit.route('/delete/<title>/<time>')
def delete(title, time):
if 'username' in session :
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
cursor = conn.cursor() # Création de l'objet "curseur"
cursor.execute("""DELETE FROM posts WHERE title=?""", (post,))
cursor.execute("""DELETE FROM posts WHERE title=? AND time=?""", (title, time))
conn.commit()
conn.close()
return redirect(url_for('post-it.racine_blog'))
else:
return redirect(BASE_URL, code=401) # sinon on redirige vers login
@postit.route('/edit/<post>', methods=['GET', 'POST'])
def edit(post):
@postit.route('/edit/<title>/<time>', methods=['GET', 'POST'])
def edit(title, time):
if 'username' in session :
if request.method == 'POST' :
newtitle = request.form['title']
@@ -84,15 +91,15 @@ def edit(post):
newstatus = request.form['status']
conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
cursor.execute("""UPDATE posts SET title=?, content=?, status=? WHERE title=?""",
(newtitle, newcontent, newstatus, post,))
cursor.execute("""UPDATE posts SET title=?, content=?, status=? WHERE title=? AND time=?""",
(newtitle, newcontent, newstatus, title, time))
conn.commit()
conn.close()
return redirect(url_for('post-it.racine_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, content FROM posts WHERE title=?""", (post,))
cursor.execute("""SELECT title, content FROM posts WHERE title=? AND time =?""", (title, time))
oldpost = cursor.fetchone()
conn.close()
return render_template('postedit.html',
@@ -102,18 +109,31 @@ def edit(post):
return redirect(BASE_URL, code=401)
@postit.route('/postit/board', methods=['GET'])
def viewsheet():
if 'username' in session:
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
cursor = conn.cursor() # Création de l'objet "curseur"
cursor.execute("""SELECT title, content, time, author, status, avatar, nom, prenom, age FROM posts INNER JOIN users where status='public' """)
posts = [dict(title=row[0], content=row[1], time=row[2], author=row[3],
status=row[4], avatar=row[5], nom=row[6], prenom=row[7], age=row[8])
for row in reversed(cursor.fetchall())]
cursor.execute("""SELECT title, content, time, author, status FROM posts WHERE status='public' """)
list_posts=cursor.fetchall()
posts=list()
id=0
for post in list_posts:
author = post[3]
cursor.execute("""SELECT avatar FROM users WHERE name=?""", (author,))
tmp = cursor.fetchone()
if tmp != None :
author_avatar = tmp[0]
else:
author_avatar = tmp
posts.append(dict(title=post[0], id_postit=id, content=markdown(post[1]), time=post[2], author=post[3],status=post[4], avatar=author_avatar))
id=id+1
conn.close()
for post in posts:
post['content'] = markdown(post['content'])
return render_template('board.html', section='Post-it', posts=posts)
else:
return redirect(BASE_URL, code=401)