Example #1
0
 def post(self, tag):
     group = Group.objects(tag=tag)[0]
     title = self.get_argument('title')
     content = self.get_argument('content')
     now = datetime.datetime.now()
     mode = self.get_argument('type').decode()
     if mode == 'new':
         try:
             if not title:
                 raise Exception('title is none')
             post = Post(group=group,
                         author=self.get_curent_user_model(),
                         title=title,
                         content=content,
                         create_at=now,
                         update_at=now
             )
             post.save()
             return self.redirect("/group/" + tag + "/" + str(post.id))
         except Exception as ex:
             app_log.error(ex)
             return self.redirect("/group/" + tag)
     elif mode == 'update':
         id = self.get_argument('id')
         try:
             app_log.debug(id)
             app_log.debug(title)
             app_log.debug(content)
             post = Post.objects(id=id)[0]
             post.title = title
             post.content = content
             post.save()
         except Exception as ex:
             app_log.error(ex)
         return self.redirect("/group/" + tag + "/" + id)
Example #2
0
 def post(self, tag):
     group = Group.objects(tag=tag)[0]
     title = self.get_argument('title')
     content = self.get_argument('content')
     now = datetime.datetime.now()
     mode = self.get_argument('type').decode()
     if mode == 'new':
         try:
             if not title:
                 raise Exception('title is none')
             post = Post(group=group,
                         author=self.get_curent_user_model(),
                         title=title,
                         content=content,
                         create_at=now,
                         update_at=now)
             post.save()
             return self.redirect("/group/" + tag + "/" + str(post.id))
         except Exception as ex:
             app_log.error(ex)
             return self.redirect("/group/" + tag)
     elif mode == 'update':
         id = self.get_argument('id')
         try:
             app_log.debug(id)
             app_log.debug(title)
             app_log.debug(content)
             post = Post.objects(id=id)[0]
             post.title = title
             post.content = content
             post.save()
         except Exception as ex:
             app_log.error(ex)
         return self.redirect("/group/" + tag + "/" + id)
Example #3
0
 def get(self, tag):
     group = Group.objects(tag=tag)[0]
     posts = Post.objects(group=group)
     self.render("group/_groups.html",
                 page_heading=group.name,
                 _group=group,
                 posts=posts,
                 groups=self.get_groups())
Example #4
0
def social():
    user = Friend.objects(username=session["token"]).first()
    friends = user.friend
    friend_post = []
    posts = Post.objects()
    for post in posts:
        if post.user in friends:
            friend_post.append(post)
    return render_template("social.html", posts=friend_post)
Example #5
0
 def get(self, tag):
     group = Group.objects(tag=tag)[0]
     posts = Post.objects(group=group)
     self.render(
         "group/_groups.html",
         page_heading=group.name,
         _group=group,
         posts=posts,
         groups=self.get_groups()
     )
Example #6
0
 def post(self, tag, uuid):
     content = self.get_argument('content')
     now = datetime.datetime.now()
     comment = Comment(content=content,
                       author=self.get_curent_user_model(),
                       create_at=now,
                       update_at=now)
     post = Post.objects(id=uuid)[0]
     post.comments.append(comment)
     post.save()
     self.redirect("/group/" + tag + "/" + uuid)
Example #7
0
 def get(self, tag, uuid):
     try:
         post = Post.objects(id=uuid)[0]
         self.render(
             "group/_post.html",
             page_heading=post.title,
             post=post,
             groups=self.get_groups()
         )
     except Exception as ex:
         app_log.error(ex)
         self.redirect('/group/' + tag)
Example #8
0
def social():
    user = Friend.objects(username=session["token"]).first()
    us = User.objects(username=session["token"]).first()
    friends = user.friend
    friend_post = []
    posts = Post.objects()
    # commentss = []
    for post in posts:
        if post.user in friends or post.user == session["token"]:
            friend_post.append(post)
    print(friend_post)
    # for post in friend_post:
    #     commentss.append(post.comments)
    if request.method == "GET":
        return render_template("social.html",
                               posts=friend_post,
                               avt=us.avt,
                               name=session["token"])
    else:
        form = request.form
        for i in form:
            if "like" in i:
                like = form[i]
                if like != None:
                    for j in range(len(friend_post)):
                        if str(j + 1) in i:
                            p = friend_post[j]
                            print(p.like)
                            if session["token"] not in p.wholike:
                                p.like += 1
                                p.wholike.append(session["token"])
                            else:
                                p.like -= 1
                                p.wholike.remove(session["token"])

            else:
                comments = []
                comment = {}
                comment["contain"] = form[i]
                comment["owner"] = session["token"]
                if comment["contain"] != None:
                    for j in range(len(friend_post)):
                        if str(j + 1) in i:
                            p = friend_post[int(j)]
                            p.comments.append(comment)
            p.save()
    return redirect(url_for("social"))
def social():
    user = Friend.objects(username=session["token"]).first()
    friends = user.friend
    friend_post = []
    posts = Post.objects()
    who_like  = [] 
    for post in posts:
        if post.user in friends:
            friend_post.append(post)
    if request.method == "GET":
        return render_template("social.html",posts=friend_post) 
    else:
        form = request.form
        print(form) 
        for i in form: 
            if "like" in i:
                like = form[i]
                if like != None:
                    for j in range(len(friend_post)): 
                        if str(j+1) in i: 
                            p = friend_post[j] 
                            if session["token"] not in p.wholike:
                                p.like += 1 
                                p.wholike.append(session["token"])
                            else:
                                p.like -= 1 
                                p.wholike.remove(session["token"])
                                
            else:
                comment = form[i]
                if comment != None:
                    for j in range(len(friend_post)): 
                        if str(j+1) in i: 
                            p = friend_post[int(j)] 
                            p.comment.append(comment)
            p.save()
    return redirect(url_for("social"))
Example #10
0
 def delete(self, tag, uuid):
     post = Post.objects(id=uuid)[0]
     post.delete()
     self.write('success')