def update2(message_id, user_search, topic_search, text_search): login_id = users.login_id() if login_id == 0: return render_template("index.html", login="******") else: user_search = user_search.strip() topic_search = topic_search.strip() text_search = text_search.strip() content = request.form["content"] if isBlank(content): return render_template("error.html", message="Tyhjä kenttä, syötä viesti") if messages.update(message_id, content): user_rights = users.get_userrights(login_id) mlist = messages.find_messages(user_rights, user_search, topic_search, text_search) if user_search == "": user_search = "%20" if text_search == "": text_search = "%20" if topic_search == "": topic_search = "%20" return render_template("findmsg.html", login_id=login_id, user_rights=user_rights, count=len(mlist), messages=mlist, user_search=user_search, topic_search=topic_search, text_search=text_search) else: return render_template("error.html", message="Viestin talletus ei onnistunut")
def deletem2(message_id, user_search, topic_search, text_search): login_id = users.login_id() if login_id == 0: return render_template("index.html", login="******") else: user_search = user_search.strip() topic_search = topic_search.strip() text_search = text_search.strip() topic_id = messages.get_topic_id(message_id) if messages.delete(message_id): user_rights = users.get_userrights(login_id) mlist = messages.find_messages(user_rights, user_search, topic_search, text_search) if user_search == "": user_search = "%20" if topic_search == "": topic_search = "%20" if text_search == "": text_search = "%20" return render_template("findmsg.html", login_id=login_id, user_rights=user_rights, count=len(mlist), messages=mlist, user_search=user_search, topic_search=topic_search, text_search=text_search) else: return render_template("error.html", message="Viestin poisto ei onnistunut")
def findmsg(): login_id = users.login_id() if login_id == 0: return render_template("index.html", login="******") else: user_rights = users.get_userrights(login_id) user_search = request.form["user_search"].strip() topic_search = request.form["topic_search"].strip() text_search = request.form["text_search"].strip() if isBlank(user_search) and isBlank(topic_search) and isBlank( text_search): return render_template("find.html", error="Täytä hakukentät") mlist = messages.find_messages(user_rights, user_search, topic_search, text_search) if user_search == "": user_search = "%20" if topic_search == "": topic_search = "%20" if text_search == "": text_search = "%20" return render_template("findmsg.html", login_id=login_id, user_rights=user_rights, count=len(mlist), messages=mlist, user_search=user_search, topic_search=topic_search, text_search=text_search)
def update(message_id, content): login_id = users.login_id() if login_id == 0: return False sql = "UPDATE messages SET CONTENT = :content WHERE id = :message_id" db.session.execute(sql, {"content": content, "message_id": message_id}) db.session.commit() return True
def modify(message_id): if users.login_id() == 0: return render_template("index.html", login="******") else: content = messages.read_message(message_id) return render_template("modify.html", message_id=message_id, content=content)
def list_areas(): login_id = users.login_id() if login_id == 0: return render_template("index.html", login="******") else: user_rights = users.get_userrights(login_id) alist = areas.get_areas(user_rights) return render_template("areas.html", areas=alist)
def delete(message_id): login_id = users.login_id() if login_id == 0: return False sql = "UPDATE messages SET visible = false WHERE id = :message_id" # sql = "DELETE FROM messages WHERE id=:message_id" db.session.execute(sql, {"message_id": message_id}) db.session.commit() return True
def deletem(message_id): if users.login_id() == 0: return render_template("index.html", login="******") else: topic_id = messages.get_topic_id(message_id) if messages.delete(message_id): return redirect("/messages/" + str(topic_id)) else: return render_template("error.html", message="Viestin poisto ei onnistunut")
def list_topics(area_id): if users.login_id() == 0: return render_template("index.html", login="******") else: area_name = areas.get_areaname(area_id) tlist = topics.get_topics(area_id) return render_template("topics.html", area_id=area_id, area_name=area_name, topics=tlist)
def reply(message_id): if users.login_id() == 0: return render_template("index.html", login="******") else: user_id = messages.get_user_id(message_id) author = users.get_useralias(user_id) message = messages.read_message(message_id) topic_id = messages.get_topic_id(message_id) return render_template("reply.html", content="", message_id=message_id, author=author, message=message)
def insert(topic_id, content, ref_msg): login_id = users.login_id() if login_id == 0: return False sql = "INSERT INTO messages (content, topic_id, user_id, sent_at, visible, ref_message) VALUES (:content, :topic_id, :user_id, NOW(), true, :ref_msg)" db.session.execute( sql, { "content": content, "topic_id": topic_id, "user_id": login_id, "ref_msg": ref_msg }) db.session.commit() return True
def update(message_id): if users.login_id() == 0: return render_template("index.html", login="******") else: topic_id = messages.get_topic_id(message_id) content = request.form["content"] if isBlank(content): return render_template( "error.html", message="Tyhjä kenttä, viestin talletus ei onnistunut") if messages.update(message_id, content): return redirect("/messages/" + str(topic_id)) else: return render_template("error.html", message="Viestin talletus ei onnistunut")
def send(topic_id): if users.login_id() == 0: return render_template("index.html", login="******") else: content = request.form["content"] if isBlank(content): return render_template("new.html", topic_id=topic_id, content="", error="Tyhjä kenttä, viestiä ei talletettu") if messages.insert(topic_id, content, None): return redirect("/messages/" + str(topic_id)) else: return render_template("error.html", message="Viestin talletus ei onnistunut")
def list_messages(topic_id): login_id = users.login_id() if login_id == 0: return render_template("index.html", login="******") else: user_rights = users.get_userrights(login_id) topic_name = topics.get_topicname(topic_id) area_id = topics.get_area_id(topic_id) area_name = areas.get_areaname(area_id) mlist = messages.get_messages(topic_id) return render_template("messages.html", login_id=login_id, user_rights=user_rights, area_id=area_id, area_name=area_name, topic_id=topic_id, topic_name=topic_name, count=len(mlist), messages=mlist)
def modify2(message_id, user_search, topic_search, text_search): if users.login_id() == 0: return render_template("index.html", login="******") else: user_search = user_search.strip() topic_search = topic_search.strip() text_search = text_search.strip() content = messages.read_message(message_id) if user_search == "": user_search = "%20" if topic_search == "": topic_search = "%20" if text_search == "": text_search = "%20" return render_template("modify2.html", message_id=message_id, content=content, user_search=user_search, topic_search=topic_search, text_search=text_search)
def send_reply(message_id): if users.login_id() == 0: return render_template("index.html", login="******") else: author_id = messages.get_user_id(message_id) topic_id = messages.get_topic_id(message_id) author = users.get_useralias(author_id) message = messages.read_message(message_id) ref_msg = author + " kirjoitti: \n" + message content = request.form["content"] if isBlank(content): return render_template("reply.html", content="", message_id=message_id, author=author, message=message, error="Tyhjä kenttä, viestiä ei talletettu") if messages.insert(topic_id, content, ref_msg): return redirect("/messages/" + str(topic_id)) else: return render_template("error.html", message="Viestin talletus ei onnistunut")
def topicsend(area_id): if users.login_id() == 0: return render_template("index.html", login="******") else: topic_name = request.form["topicname"] content = request.form["content"] if isBlank(topic_name): return render_template("newtopic.html", area_id=area_id, content=content, error="Syötä uuden viestiketjun otsikko") if isBlank(content): return render_template("newtopic.html", area_id=area_id, topicname=topic_name, error="Syötä viesti") if topics.sendtopic(area_id, topic_name): topic_id = topics.get_newtopic() messages.insert(topic_id, content, None) return redirect("/messages/" + str(topic_id)) else: return render_template("newtopic.html", area_id=area_id, error="Viestiketjun aloitus ei onnistunut")
def find(): if users.login_id() == 0: return render_template("index.html", login="******") else: return render_template("find.html")
def newtopic(area_id): if users.login_id() == 0: return render_template("index.html", login="******") else: return render_template("newtopic.html", area_id=area_id)
def new(topic_id): if users.login_id() == 0: return render_template("index.html", login="******") else: return render_template("new.html", topic_id=topic_id, content="")