def commentWeb(): username=session.get("username") if username == None: return login(); global conn postid=int(session.get("postid")) posts=post.Post(conn) post_datas=posts.getPostsByPostid(postid) postJson=[post_datas[0][0],post_datas[0][1],postid] userid=session.get("userid") comments=comment.Comment(conn) comment_datas=comments.getCommentsByPostid(postid,userid) comment_data=[]; for item in comment_datas: datalist={ 'like':item[0], 'flag':item[1], 'commentid':item[2], 'username':item[3], 'comment':item[4] } comment_data.append(datalist) commentJson=json.dumps(comment_data) return render_template('comment.html',Musername=username,username=postJson[0],\ userpost=postJson[1],postid=postJson[2],commentjson=commentJson)
def dislikePost(): global conn userid=session.get("userid") data=json.loads(request.form.get('data')) postid=int(data["postid"]) posts=post.Post(conn); posts.dislikePost(postid,userid) return ""
def deletePosts(): global conn data=json.loads(request.form.get('data')) postid=int(data["postid"]) posts=post.Post(conn) posts.deletePost(postid) return mainWindow();
def modifypostdata(): global conn if request.method == "POST": blogs=request.form.get('myblog') postid=int(session.get("postid")) posts=post.Post(conn) print(postid) ressult=posts.modifyData(postid,blogs) return """<script>window.location.href="/mainWindow";</script>"""
def postdata(): global conn if request.method == "POST": blogs=request.form.get('myblog') posts=post.Post(conn) userid=session.get("userid") ressult=posts.insertData(userid,blogs) return """<script>window.location.href="/mainWindow";</script>"""
def modifypostweb(): username=session.get("username") if username == None: return login(); global conn postid=int(session.get("postid")) posts=post.Post(conn) post_datas=posts.getPostsByPostid(postid) userpost=post_datas[0][1] return render_template('modifypost.html',username=username,post=userpost)
def mainWindow(): global conn posts=post.Post(conn) userid=session.get("userid") if userid == None: return login(); else: allBlogs=posts.getAllPosts(userid) datas=[]; for item in allBlogs: datalist={ 'username':item[0], 'post':item[1], 'postid':item[2], 'like':item[3], 'flag':item[4] } datas.append(datalist) dataJson=json.dumps(datas) username=session.get("username") return render_template('mainWindow.html',username=username,json=dataJson)