Пример #1
0
 def format_retweet_date(self, user):
     followeder_ids = user.get_followeder_ids()
     retweet_relationships =\
         db.query(m.Retweet).order_by(sa.desc(m.Retweet.created_at)).filter(sa.and_(m.Retweet.post_id ==\
                 self.id, m.Retweet.user_id.in_(followeder_ids))).all()
     if retweet_relationships != []:
         return formatDate(retweet_relationships[0].created_at)
     else:
         return formatDate(self.created_at)
Пример #2
0
 def post(self, post_id):
     user = self.current_user
     post_id = int(post_id)
     post = db.query(Post).get(post_id)
     if not post:
         raise tornado.web.HTTPError(404)
     else:
         origin_content = self.get_argument("comment-content", "")
         content = md(origin_content)
         if origin_content == "":
             self.redirect(self.next_url)
             return
         comment = Comment(post_id=post_id, user_id=user.id, content=content, origin_content=origin_content)
         db.add(comment)
         db.commit()
         the_comment = (
             db.query(Comment).order_by(sa.desc(Comment.created_at)).filter(Comment.user_id == user.id).first()
         )
         if self.is_ajax():
             self.write(
                 tornado.escape.json_encode(
                     {
                         "username": user.name,
                         "avatar": user.get_avatar(size=24),
                         "time": formatDate(int(time.time())),
                         "content": content,
                     }
                 )
             )
         if post.user_id != user.id:
             db.add(Notifier(post_id=post_id, who_id=user.id, whom_id=post.user_id, comment_id=the_comment.id))
             db.commit()
         if content.find("@") != -1:
             put_notifier(comment=comment, post=post)
Пример #3
0
 def post(self, post_id):
     post_id = int(post_id)
     origin_content = self.get_argument("content", '')
     if origin_content != '':
         content = md(origin_content)
         user = self.current_user
         post = db.query(Post).get(post_id)
         post.origin_content = origin_content
         post.content = content
         db.commit()
         if self.is_ajax():
             self.write(
                 tornado.escape.json_encode({
                     'username':
                     user.name,
                     'avatar':
                     user.get_avatar(),
                     'time':
                     formatDate(int(time.time())),
                     'content':
                     content
                 }))
         else:
             self.redirect(self.next_url)
     else:
         self.redirect(self.next_url)
         return
Пример #4
0
 def post(self):
     user = self.current_user
     origin_content = self.get_argument("content", '')
     content = md(origin_content)
     if origin_content != '':
         post = Post(user_id=user.id,
                     content=content,
                     origin_content=origin_content)
         db.add(post)
         db.commit()
         if self.is_ajax():
             self.write(
                 tornado.escape.json_encode({
                     'username':
                     user.name,
                     'avatar':
                     user.get_avatar(),
                     'time':
                     formatDate(int(time.time())),
                     'content':
                     content,
                     'id':
                     post.id
                 }))
             '''
             self.render('site/ajaxpage.html', posts = [post])
             '''
         else:
             self.redirect(self.next_url)
         if post.content.find('@') != -1:
             post_put_notifier(post)
     else:
         self.redirect(self.next_url)
     return
Пример #5
0
 def post(self, post_id):
     user = self.current_user
     post_id = int(post_id)
     post = db.query(Post).get(post_id)
     if not post:
         raise tornado.web.HTTPError(404)
     else:
         origin_content = self.get_argument("comment-content", '')
         content = md(origin_content)
         if origin_content == '':
             self.redirect(self.next_url)
             return
         comment = Comment(post_id=post_id,
                           user_id=user.id,
                           content=content,
                           origin_content=origin_content)
         db.add(comment)
         db.commit()
         the_comment = db.query(Comment).order_by(
             sa.desc(Comment.created_at)).filter(
                 Comment.user_id == user.id).first()
         if self.is_ajax():
             self.write(
                 tornado.escape.json_encode({
                     'username':
                     user.name,
                     'avatar':
                     user.get_avatar(size=24),
                     'time':
                     formatDate(int(time.time())),
                     'content':
                     content
                 }))
         if post.user_id != user.id:
             db.add(
                 Notifier(post_id=post_id,
                          who_id=user.id,
                          whom_id=post.user_id,
                          comment_id=the_comment.id))
             db.commit()
         if content.find('@') != -1:
             put_notifier(comment=comment, post=post)
Пример #6
0
 def format_date(self):
     return formatDate(self.created_at)
Пример #7
0
 def format_date(self):
     return formatDate(self.created_at)