Fix landing-page css
This commit is contained in:
167
views/blog.py
167
views/blog.py
@@ -32,97 +32,93 @@ MARKDOWN_EXT=["extra", "toc", "codehilite",
|
||||
@blog.route('/myblog/new-article/', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def new_article():
|
||||
user = '%s'% escape(session['username'])
|
||||
user = '%s' % escape(session['username'])
|
||||
|
||||
if request.method == 'POST':
|
||||
title = strOB(request.form['title'].rstrip())
|
||||
subtitle = str(request.form['subtitle'])
|
||||
category = str(request.form['category'])
|
||||
content = str(request.form['content'])
|
||||
status = str(request.form['status'])
|
||||
title_id = escape(request.form['title'].rstrip())
|
||||
title = request.form['title'].rstrip()
|
||||
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")
|
||||
if 'blog-unified' in request.form.keys():
|
||||
status = status+'_unified'
|
||||
|
||||
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, 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_id, title, subtitle, category, content, creation_date, author, status) VALUES(?, ?, ?, ?, ?, ?, ?, ?)""", (title_id, title, subtitle, category, content, post_date, user, status)) # Insérer des valeurs
|
||||
conn.commit()
|
||||
|
||||
return redirect(url_for('blog.list_articles_blog'))
|
||||
else:
|
||||
return render_template('new_article_blog.html')
|
||||
|
||||
@blog.route('/myblog/edit/<title>', methods=['GET', 'POST'])
|
||||
@blog.route('/myblog/edit/<title_id>', methods=['GET'])
|
||||
@login_required
|
||||
def edit(title):
|
||||
user='%s'% escape(session['username'])
|
||||
folder_blog = DOSSIER_PERSO + user + "/blog/articles/"
|
||||
if request.method == 'POST' :
|
||||
newtitle = str(request.form['title'].rstrip())
|
||||
subtitle = str(request.form['subtitle'])
|
||||
category = str(request.form['category'])
|
||||
newcontent = str(request.form['content'])
|
||||
newstatus = str(request.form['status'])
|
||||
updated = time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
conn = sqlite3.connect(DATABASE)
|
||||
cursor = conn.cursor()
|
||||
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=?""", (newtitle, 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], category=oldpost[2], content=oldpost[3], status=oldpost[4])
|
||||
return render_template('edit_article.html',
|
||||
def edit(title_id):
|
||||
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_id, title, subtitle, creation_date, category, content, status FROM Blog_posts WHERE title_id=? AND author=?""", (title_id, user))
|
||||
oldpost = cursor.fetchone()
|
||||
post = dict(title_id=oldpost[0], title=oldpost[1], subtitle=oldpost[2], creation_date=oldpost[3], category=oldpost[4], content=oldpost[5], status=oldpost[6])
|
||||
|
||||
conn.close()
|
||||
|
||||
return render_template('edit_article.html',
|
||||
section='Post-it',
|
||||
oldpost=post)
|
||||
|
||||
|
||||
@blog.route('/myblog/update/<title>', methods=['POST'])
|
||||
@blog.route('/myblog/update_blogpost', methods=['POST'])
|
||||
@login_required
|
||||
def update(title):
|
||||
user='%s'% escape(session['username'])
|
||||
folder_blog = DOSSIER_PERSO + user + "/blog/articles/"
|
||||
newtitle = str(request.form['title']).encode()
|
||||
def update():
|
||||
user = '%s' % escape(session['username'])
|
||||
title_id = str(request.form['title_id'])
|
||||
title = str(request.form['title'])
|
||||
subtitle = str(request.form['subtitle'])
|
||||
creation_date = str(request.form['creation_date'])
|
||||
category = str(request.form['category'])
|
||||
newcontent = str(request.form['content'])
|
||||
newstatus = str(request.form['status'])
|
||||
updated = time.strftime("%d/%m/%Y à %H:%M:%S")
|
||||
content = str(request.form['content'])
|
||||
status = str(request.form['status'])
|
||||
updated = time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
conn = sqlite3.connect(DATABASE)
|
||||
cursor = conn.cursor()
|
||||
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=?""", (newtitle, subtitle, category, updated, newstatus, newcontent, title, user))
|
||||
status = status+'_unified'
|
||||
|
||||
cursor.execute("""DELETE FROM Blog_posts WHERE title_id=? AND author=?""", (title_id, user))
|
||||
cursor.execute("""INSERT INTO Blog_posts(title_id, title, subtitle, category, content, creation_date, last_updated, author, status)VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
(title_id, title, subtitle, category, content, creation_date, updated, user, status))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
response = """ <p class="center success" >Article mis à jour le """+ updated +""" .</p>"""
|
||||
return response
|
||||
|
||||
post = dict(title_id=title_id, title=title, subtitle=subtitle, category=category, content=content, status=status)
|
||||
flash(u'Article mis à jour avec succès le: '+ updated , 'success' )
|
||||
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'])
|
||||
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, last_updated, status FROM Blog_posts WHERE author=? """, (user,) )
|
||||
cursor.execute("""SELECT title_id, 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 = [dict(title=post[0],
|
||||
subtitle=post[1],
|
||||
time=post[2],
|
||||
last_updated=post[3],
|
||||
status=post[4])] + posts
|
||||
posts = [dict(title_id=post[0],
|
||||
title=post[1],
|
||||
subtitle=post[2],
|
||||
time=post[3],
|
||||
last_updated=post[4],
|
||||
status=post[5])] + posts
|
||||
nb_articles = nb_articles + 1
|
||||
|
||||
return render_template('list_articles.html',
|
||||
@@ -130,16 +126,16 @@ def list_articles_blog():
|
||||
list_posts=posts,
|
||||
nb_articles=nb_articles )
|
||||
|
||||
@blog.route('/myblog/delete/<title>')
|
||||
@blog.route('/myblog/delete/<title_id>')
|
||||
@login_required
|
||||
def delete(title):
|
||||
title = escape(title)
|
||||
def delete(title_id):
|
||||
title_id = '%s' % str(title_id).rstrip()
|
||||
user='%s'% escape(session['username'])
|
||||
folder_blog = DOSSIER_PERSO + user + "/blog/articles/"
|
||||
folder_blog_public = DOSSIER_PUBLIC + user + "/blog/articles/"
|
||||
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))
|
||||
cursor.execute("""DELETE FROM Blog_posts WHERE title_id=? AND author=?""", (title_id, user))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return redirect(url_for('blog.list_articles_blog'))
|
||||
@@ -183,14 +179,14 @@ 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,))
|
||||
cursor.execute("""SELECT title_id, 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
|
||||
posts=[dict(title_id=post[0], title=post[1], subtitle=post[2], creation_date=post[3], author=post[4], status=post[5])] + posts
|
||||
|
||||
return render_template('index_blog.html', section='Blog', posts=posts, author=user)
|
||||
|
||||
@@ -200,14 +196,14 @@ def viewmyblog():
|
||||
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, content, creation_date, last_updated, author, status FROM Blog_posts WHERE status='private_unified' OR status='public_unified' """ )
|
||||
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, last_updated, author, status FROM Blog_posts WHERE status='private_unified' OR status='public_unified' """ )
|
||||
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
|
||||
posts = [dict(title_id=[0], title=post[1], subtitle=post[2], content=post[3], creation_date=post[4], last_updated=post[5], author=post[6], status=post[7] )] + posts
|
||||
else:
|
||||
return redirect(BASE_URL, code=404)
|
||||
|
||||
@@ -224,7 +220,7 @@ def view():
|
||||
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
|
||||
posts=[dict(title_id=post[0], title=post[1], subtitle=post[2], creation_date=post[3], author=post[4], status=post[5])] + posts
|
||||
|
||||
return render_template('index_blog.html', section='Blog', posts=posts)
|
||||
|
||||
@@ -235,9 +231,9 @@ def viewuser(author):
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||
if 'username' in session :
|
||||
cursor.execute("""SELECT title, subtitle, creation_date, last_updated, author, status FROM Blog_posts WHERE author=? AND status != 'draft' """, (author,))
|
||||
cursor.execute("""SELECT title_id, 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,))
|
||||
cursor.execute("""SELECT title_id, 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()
|
||||
posts=None
|
||||
id=0
|
||||
@@ -245,7 +241,7 @@ def viewuser(author):
|
||||
if list_posts != None:
|
||||
posts=list()
|
||||
for post in list_posts:
|
||||
posts=[dict(title=post[0], subtitle=post[1], creation_date=post[2], last_updated=post[3], author=post[4], status=post[5])] + posts
|
||||
posts=[dict(title_id=post[0], title=post[1], subtitle=post[2], creation_date=post[3], last_updated=post[4], author=post[5], status=post[6])] + posts
|
||||
|
||||
|
||||
return render_template('index_blog.html', section='Blog', posts=posts, author=author)
|
||||
@@ -264,7 +260,8 @@ def viewauthorrss(author):
|
||||
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], extensions=MARKDOWN_EXT), creation_date=post[3], author=post[4], status=post[5])] + posts
|
||||
posts=[dict(title_id[0], title=post[1], subtitle=post[2], content=markdown(post[3], extensions=MARKDOWN_EXT), creation_date=post[4],
|
||||
author=post[5], status=post[6])] + posts
|
||||
|
||||
return render_template('blog_rss.xml',
|
||||
base_url=BASE_URL,
|
||||
@@ -273,37 +270,36 @@ def viewauthorrss(author):
|
||||
posts=posts)
|
||||
|
||||
|
||||
@blog.route('/blog/private_unified/<username>/<title>', methods=['GET'])
|
||||
@blog.route('/blog/private/<username>/<title>', methods=['GET'])
|
||||
@blog.route('/blog/private_unified/<username>/<title_id>', methods=['GET'])
|
||||
@blog.route('/blog/private/<username>/<title_id>', methods=['GET'])
|
||||
@login_required
|
||||
def viewPrivateArticle(username, title):
|
||||
user = escape(username)
|
||||
title = escape(title)
|
||||
def viewPrivateArticle(username, title_id):
|
||||
user = '%s' % escape(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, status FROM Blog_posts WHERE author=? AND title=? AND status!='draft' """, (user, title))
|
||||
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, last_updated, author, status FROM Blog_posts WHERE author=? AND title_id=? AND status!='draft' """, (user, title_id))
|
||||
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], extensions=MARKDOWN_EXT)
|
||||
post_info = (dict(title_id=post[0], title=post[1], subtitle=post[2], creation_date=post[4], last_updated=post[5],author=post[6]))
|
||||
content = markdown(post[3], extensions=MARKDOWN_EXT)
|
||||
return render_template('blog.html', post_info=post_info, content=content)
|
||||
else:
|
||||
return redirect(url_for('blog'), code=404)
|
||||
|
||||
|
||||
@blog.route('/blog/public_unified/<username>/<title>', methods=['GET'])
|
||||
@blog.route('/blog/public/<username>/<title>', methods=['GET'])
|
||||
def viewArticle(username, title):
|
||||
user = username
|
||||
@blog.route('/blog/public_unified/<username>/<title_id>', methods=['GET'])
|
||||
@blog.route('/blog/public/<username>/<title_id>', methods=['GET'])
|
||||
def viewArticle(username, title_id):
|
||||
user = '%s' % escape(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_unified' """, (user, title) )
|
||||
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, last_updated, author FROM Blog_posts WHERE author=? AND title=? AND status='public_unified' """, (user, title_id) )
|
||||
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], extensions=MARKDOWN_EXT)
|
||||
post_info = (dict(title_id=post[0], title=post[1], subtitle=post[2], creation_date=post[4], last_updated=post[5],author=post[6]))
|
||||
content= markdown(post[3], extensions=MARKDOWN_EXT)
|
||||
|
||||
return render_template('blog.html', post_info=post_info, content=content)
|
||||
else:
|
||||
@@ -316,7 +312,7 @@ def viewrss():
|
||||
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'""" )
|
||||
cursor.execute("""SELECT title_id, title, subtitle, content, creation_date, author, status FROM Blog_posts WHERE status='public_unified'""" )
|
||||
list_posts=cursor.fetchall()
|
||||
posts=list()
|
||||
id=0
|
||||
@@ -324,7 +320,8 @@ def viewrss():
|
||||
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], extensions=MARKDOWN_EXT), creation_date=post[3], author=post[4], status=post[5])] + posts
|
||||
posts=[dict(title_id=post[0], title=post[1], subtitle=post[2], content=markdown(post[3], extensions=MARKDOWN_EXT), creation_date=post[4],
|
||||
author=post[5], status=post[6])] + posts
|
||||
|
||||
return render_template('blog_rss.xml',
|
||||
base_url=BASE_URL,
|
||||
|
||||
Reference in New Issue
Block a user