Пример #1
0
def posts():
    postList = query.get_all_pids()
    #postList.reverse()
    postDict = []
    for pid in postList:
        title = query.get_post(pid)['title'] 
        content = query.get_post(pid)["content"]
        topComment = ""
        if len(query.get_comments_for_post(pid)) > 0:
            topCommentID = query.get_comments_for_post(pid)[0]["comment_id"]
            topComment = query.get_comment_contents(topCommentID)
        postDict.append({'pid':pid,'title':title,'topComment':topComment,'content':content})
    if request.method == "GET":
        #postDict format: {pid: {'title':, 'topComment':}, pid:{...}, ...}
        return render_template("allposts.html", POST_DICT = postDict)
    else:
        assert(request.method == "POST")
        if not session['logged_in']:
            return render_template("allposts.html", POST_DICT = postDict, error = "Please log in before you post!")
        else:
            print request.form
            if 'newpost' in request.form:
                query.addPost(session["UID"],request.form['title'], request.form['content'])
                return redirect(url_for("posts"))
            else:
                print("ERROR: NOT ADDED")
                return redirect(url_for("posts"))
Пример #2
0
def posts():
    postList = query.get_all_pids()
    postList.reverse()
    postDict = []
    for pid in postList:
        title = query.get_post(pid)["title"]
        content = query.get_post(pid)["content"]
        topComment = ""
        if len(query.get_comments_for_post(pid)) > 0:
            topCommentID = query.get_comments_for_post(pid)[0]["comment_id"]
            topComment = query.get_comment_contents(topCommentID)
        postDict.append({
            'pid': pid,
            'title': title,
            'topComment': topComment,
            'content': content
        })
    if request.method == "GET":
        #postDict format: {pid: {'title':, 'topComment':}, pid:{...}, ...}
        return render_template("allposts.html", POST_DICT=postDict)
    else:
        assert (request.method == "POST")
        if not session['logged_in']:
            return render_template("allposts.html",
                                   POST_DICT=postDict,
                                   error="Please log in before you post!")
        else:
            print request.form
            if 'newpost' in request.form:
                query.addPost(session["UID"], request.form['title'],
                              request.form['content'])
                return redirect(url_for("posts"))
            else:
                print("ERROR: NOT ADDED")
                return redirect(url_for("posts"))
Пример #3
0
 def get(self, post_id):
     cookie_user = self.cookie_check()
     if not cookie_user:
         return self.redirect('/sin')
     document = query.get_post(cookie_user, post_id)
     if cookie_user != document.user.get():
         return self.redirect('/error1')
     query.delete_post(document.key.urlsafe())
     time.sleep(.5)
     self.redirect('/userblog')
Пример #4
0
def onepost(pid=-1):
    pid = int(pid)
    if len(query.get_post(pid)) == 0:
        return redirect(url_for("posts"))
    if request.method == "GET":
        commentList = query.get_comments_for_post(pid)
        for comment in commentList:
            comment["contents"] = query.get_comment_contents(comment["comment_id"])
        return render_template("post.html", POST_CONTENT = query.get_post(pid), COMMENT_LIST = commentList)
    else:
        assert(request.method == "POST")
        if 'add_comment' in request.form:
            query.addComment(session['UID'], pid, request.form['comment_content'])
            return redirect(url_for("onepost", pid=pid))
        elif 'del_comment' in request.form:
            if session['UID'] == query.get_uid_from_post(pid):
                query.delPost(pid)
            return redirect(url_for("posts"))
        else:
            return redirect(url_for("posts"))
Пример #5
0
 def get(self, *args):
     cookie_user = self.cookie_check()
     if not cookie_user:
         return self.redirect('/sin')
     doc_id = self.request.GET['name']
     document = query.get_post(cookie_user, doc_id)
     if document and cookie_user != document.user.get():
         return self.redirect('/error1')
     return self.render('blogentry.html',
                        title=document.title,
                        content=document.post_text,
                        identifier=document.key.urlsafe())
Пример #6
0
def profile():
    postList = query.get_posts_by_user(session['UID']) #post ids
    postDict = []
    for post in postList:
        d = query.get_post(post) # {"title":-, "contents":-, "username":-,}
        title = d['title']
        listOfComments = query.get_comments_for_post(post)
        topComment = ""
        if len(listOfComments) > 0:
            topCommentID = listOfComments[-1]["comment_id"]
            topComment = query.get_comment_contents(topCommentID)
        postDict.append({'title':title, 'topComment':topComment})
    return render_template("userposts.html", POST_LIST = postDict)
Пример #7
0
def profile():
    postList = query.get_posts_by_user(session['UID'])  #post ids
    postDict = []
    for post in postList:
        d = query.get_post(post)  # {"title":-, "contents":-, "username":-,}
        title = d['title']
        listOfComments = query.get_comments_for_post(post)
        topComment = ""
        if len(listOfComments) > 0:
            topCommentID = listOfComments[-1]["comment_id"]
            topComment = query.get_comment_contents(topCommentID)
        postDict.append({'title': title, 'topComment': topComment})
    return render_template("userposts.html", POST_LIST=postDict)
Пример #8
0
def onepost(pid=-1):
    pid = int(pid)
    if len(query.get_post(pid)) == 0:
        return redirect(url_for("posts"))
    if request.method == "GET":
        commentList = query.get_comments_for_post(pid)
        for comment in commentList:
            comment["contents"] = query.get_comment_contents(
                comment["comment_id"])
        return render_template("post.html",
                               POST_CONTENT=query.get_post(pid),
                               COMMENT_LIST=commentList)
    else:
        assert (request.method == "POST")
        if 'add_comment' in request.form:
            query.addComment(session['UID'], pid,
                             request.form['comment_content'])
            return redirect(url_for("onepost", pid=pid))
        elif 'del_comment' in request.form:
            if session['UID'] == query.get_uid_from_post(pid):
                query.delPost(pid)
            return redirect(url_for("posts"))
        else:
            return redirect(url_for("posts"))
Пример #9
0
 def get(self, doc_id):
     cookie_user = self.cookie_check()
     if not cookie_user:
         return self.redirect('/sin')
     document = query.get_post(cookie_user, doc_id)
     comment_data = query.get_comments(doc_id, 'key', 'comment_content',
                                       'user')
     flag = self.set_like_flag(document, cookie_user)
     return self.render('post.html',
                        method='post/blogentry',
                        title=document.title,
                        content=document.post_text,
                        identifier=document.key.urlsafe(),
                        comments=comment_data.comment_content,
                        user=comment_data.user,
                        comment_identifier=comment_data.key,
                        count=len(document.likes),
                        flag=flag)