コード例 #1
0
ファイル: routes.py プロジェクト: Saukka/Uutissovellus
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)
コード例 #2
0
ファイル: routes.py プロジェクト: Saukka/Uutissovellus
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="")
コード例 #3
0
ファイル: routes.py プロジェクト: Saukka/Uutissovellus
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:")
コード例 #4
0
ファイル: routes.py プロジェクト: Saukka/Uutissovellus
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))
コード例 #5
0
ファイル: routes.py プロジェクト: Saukka/Uutissovellus
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: ")
コード例 #6
0
ファイル: routes.py プロジェクト: Saukka/Uutissovellus
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))
コード例 #7
0
ファイル: routes.py プロジェクト: Saukka/Uutissovellus
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())
コード例 #8
0
ファイル: routes.py プロジェクト: Saukka/Uutissovellus
def newpiece():
    return render_template("newpiece.html",
                           topics=actions.gettopics(),
                           amount=actions.getbookmarks())