Пример #1
0
def delete_message(id):
    mes = messages.mes_id(id)
    mes_id = mes[1]
    acc_id = accounts.account_id()
    if acc_id == mes_id:
        messages.delete_message(id)
        return redirect("/")      
    else:
        return redirect("/")
Пример #2
0
def delete_comment(id):
    comment = comments.comment_id(id)
    commented_by = comment[2]
    mes_id = comment[1]
    acc_id = accounts.account_id()
    if acc_id == commented_by:
        comments.delete_comment(id)
        return redirect("/message/"+str(mes_id))      
    else:
        return redirect("/message/"+str(mes_id))      
Пример #3
0
def tag(id):
    content = request.form["content"].lower()
    mes = messages.mes_id(id)
    mes_id = mes[1]
    acc_id = accounts.account_id()
    if acc_id == mes_id:
        messages.add_tag(content, id)
        return redirect("/message/"+str(id))
    else:
        return redirect("/message/"+str(id))
Пример #4
0
def send(topic, content):
    account_id = accounts.account_id()
    posted_by = session.get("username", 0)
    if account_id == 0:
        return False
    sql = "INSERT INTO messages (account_id, topic, content, posted_at, posted_by) VALUES (:account_id, :topic, :content, NOW(), :posted_by);"
    db.session.execute(
        sql, {
            "account_id": account_id,
            "topic": topic,
            "content": content,
            "posted_by": posted_by
        })
    db.session.commit()
    return True
Пример #5
0
def comment(content, message):
    account_id = accounts.account_id()
    posted_by = session.get("username", 0)
    message_id = message[0]
    if account_id == 0:
        return False
    sql = "INSERT INTO comments (message_id, account_id, content, posted_at, posted_by) VALUES (:message_id, :account_id, :content, NOW(), :posted_by);"
    db.session.execute(
        sql, {
            "message_id": message_id,
            "account_id": account_id,
            "content": content,
            "posted_by": posted_by
        })
    db.session.commit()
    return True
Пример #6
0
def like_comment(comment_id):
    account_id = accounts.account_id()
    if account_id == 0:
        return False
    else:
        sql = "SELECT id FROM likes WHERE comment_id=:comment_id AND account_id=:account_id;"
        result = db.session.execute(sql, {
            "comment_id": comment_id,
            "account_id": account_id
        })
        like = result.fetchone()
        if like == None:
            try:
                sql = "INSERT INTO likes (comment_id , account_id) VALUES (:comment_id,:account_id);"
                db.session.execute(sql, {
                    "comment_id": comment_id,
                    "account_id": account_id
                })
                db.session.commit()
                return True
            except:
                return False
        else:
            return False