def news(id): sql = "SELECT * FROM news WHERE id=:id AND visible=1" result = db.session.execute(sql, {"id": id}) sql2 = "SELECT * FROM comments WHERE news_id=:id AND visible=1 " result2 = db.session.execute(sql2, {"id": id}) news = result.fetchall() comments = result2.fetchall() actions.addview(id) bookmarked = actions.isbookmarked(id) sqlcheck = "SELECT COUNT(*) FROM images WHERE news_id=:id" resultcheck = db.session.execute(sqlcheck, {"id": id}) amount = resultcheck.fetchone()[0] if amount == 0: return render_template("piece.html", news=news, comments=comments, topics=actions.gettopics(), amount=actions.getbookmarks(), bookmarked=bookmarked) sql3 = "SELECT data FROM images WHERE news_id=:id" result3 = db.session.execute(sql3, {"id": id}) image = result3.fetchone()[0] image64 = base64.b64encode(image) return render_template("piece.html", news=news, comments=comments, image=image64.decode('utf-8'), topics=actions.gettopics(), amount=actions.getbookmarks(), bookmarked=bookmarked)
def index(): sql = "SELECT * FROM news WHERE visible=1 ORDER BY id DESC" result = db.session.execute(sql) news = result.fetchall() return render_template("news.html", news=news, topics=actions.gettopics(), amount=actions.getbookmarks(), message="")
def mostviewed(): sql = "SELECT * FROM news WHERE visible=1 ORDER BY views DESC" result = db.session.execute(sql) news = result.fetchall() return render_template("news.html", news=news, topics=actions.gettopics(), amount=actions.getbookmarks(), message="Luetuimmat uutiset:")
def topics(topic): sql = "SELECT * FROM news WHERE topic=:topic AND visible=1" result = db.session.execute(sql, {"topic": topic}) news = result.fetchall() return render_template("news.html", news=news, topics=actions.gettopics(), topic=topic, amount=actions.getbookmarks(), message="aiheen {} uutiset:".format(topic))
def viewbookmarks(): username = session["username"] sql = "SELECT * FROM NEWS WHERE visible=1 AND id IN (SELECT news_id FROM bookmarks WHERE username=:username AND visible=1)" result = db.session.execute(sql, {"username": username}) news = result.fetchall() return render_template("news.html", news=news, topics=actions.gettopics(), amount=actions.getbookmarks(), message="Lukulistasi uutiset: ")
def result(): search = request.args["search"] sql = "SELECT * FROM news WHERE (LOWER(title) LIKE LOWER(:search) OR LOWER(body) LIKE LOWER(:search) OR LOWER(topic) LIKE LOWER(:search)) AND visible=1" result = db.session.execute(sql, {"search": "%" + search + "%"}) news = result.fetchall() return render_template("news.html", news=news, search=search, topics=actions.gettopics(), amount=actions.getbookmarks(), message="Tulokset haulle '{}':".format(search))
def editpiece(): id = request.form["id"] title = request.form["title"] body = request.form["body"] topic = request.form["topic"] return render_template("editpiece.html", id=id, title=title, body=body, topic=topic, topics=actions.gettopics(), amount=actions.getbookmarks())
def newpiece(): return render_template("newpiece.html", topics=actions.gettopics(), amount=actions.getbookmarks())