예제 #1
0
파일: tweet.py 프로젝트: wbbim/collipa
 def put(self, tweet_id):
     tweet_id = int(tweet_id)
     tweet = Tweet.get(id=tweet_id)
     if not tweet:
         raise tornado.web.HTTPError(404)
     action = self.get_argument('action', None)
     user = self.current_user
     if not action:
         result = {'status': 'error', 'message':
                   '缺少参数'}
         return self.send_result(result)
     if action == 'up':
         if tweet.user_id != user.id:
             result = user.up(tweet_id=tweet.id)
         else:
             result = {'status': 'info', 'message':
                       '不能为自己的推文投票'}
     if action == 'down':
         if tweet.user_id != user.id:
             result = user.down(tweet_id=tweet.id)
         else:
             result = {'status': 'info', 'message':
                       '不能为自己的推文投票'}
     if action == 'collect':
         result = user.collect(tweet_id=tweet.id)
     if action == 'thank':
         result = user.thank(tweet_id=tweet.id)
     if action == 'report':
         result = user.report(tweet_id=tweet.id)
     return self.send_result(result)
예제 #2
0
 def put(self, tweet_id):
     tweet_id = int(tweet_id)
     tweet = Tweet.get(id=tweet_id)
     if not tweet:
         raise tornado.web.HTTPError(404)
     action = self.get_argument('action', None)
     user = self.current_user
     if action and user:
         if action == 'up':
             if tweet.user_id != user.id:
                 result = user.up(tweet_id=tweet.id)
             else:
                 result = {'status': 'info', 'message':
                           '不能为自己的推文投票'}
         if action == 'down':
             if tweet.user_id != user.id:
                 result = user.down(tweet_id=tweet.id)
             else:
                 result = {'status': 'info', 'message':
                           '不能为自己的推文投票'}
         if action == 'collect':
             result = user.collect(tweet_id=tweet.id)
         if action == 'thank':
             result = user.thank(tweet_id=tweet.id)
         if action == 'report':
             result = user.report(tweet_id=tweet.id)
         if self.is_ajax:
             return self.write(result)
         self.flash_message(**result)
         return self.redirect_next_url()
예제 #3
0
파일: tweet.py 프로젝트: iselu/collipa
 def put(self, tweet_id):
     tweet_id = int(tweet_id)
     tweet = Tweet.get(id=tweet_id)
     if not tweet:
         raise tornado.web.HTTPError(404)
     action = self.get_argument('action', None)
     user = self.current_user
     if not action:
         result = {'status': 'error', 'message': '缺少参数'}
         return self.send_result(result)
     if action == 'up':
         if tweet.user_id != user.id:
             result = user.up(tweet_id=tweet.id)
         else:
             result = {'status': 'info', 'message': '不能为自己的推文投票'}
     if action == 'down':
         if tweet.user_id != user.id:
             result = user.down(tweet_id=tweet.id)
         else:
             result = {'status': 'info', 'message': '不能为自己的推文投票'}
     if action == 'collect':
         result = user.collect(tweet_id=tweet.id)
     if action == 'thank':
         result = user.thank(tweet_id=tweet.id)
     if action == 'report':
         result = user.report(tweet_id=tweet.id)
     return self.send_result(result)
예제 #4
0
파일: site.py 프로젝트: iselu/collipa
 def get(self):
     page = self.get_int('page', 1)
     from_id = self.get_int('from_id', 0)
     tweets = Tweet.get_timeline(page=page, from_id=from_id, user_id=self.current_user.id)
     return self.render("site/timeline.html",
                        tweets=tweets,
                        cate='me',
                        page=page)
예제 #5
0
 def get(self):
     page = self.get_int('page', 1)
     from_id = self.get_int('from_id', 0)
     tweets = Tweet.get_timeline(page=page, from_id=from_id)
     return self.render("site/timeline.html",
                        tweets=tweets,
                        cate='public',
                        page=page)
예제 #6
0
파일: tweet.py 프로젝트: wbbim/collipa
 def post(self):
     user = self.current_user
     content = self.get_argument('content', None)
     image_ids = self.get_argument('image_ids', None)
     images = []
     if not (content and len(strip_tags(content)) >= 3):
         result = {
             'status': 'error',
             'message': '推文内容至少 3 字符'
         }
         return self.send_result(result, '/timeline')
     tweet = Tweet(content=strip_xss_tags(content), user_id=user.id).save()
     tweet.put_notifier()
     if image_ids:
         image_ids = image_ids.split(',')
         for image_id in image_ids:
             image_id = int(image_id)
             image = Image.get(id=image_id)
             if not image:
                 continue
             image.tweet_id = tweet.id
             images.append({
                 'id': image.id,
                 'path': image.path,
                 'width': image.width,
                 'height': image.height,
             })
     if images:
         tweet.has_img = 'true'
     result = {
         'status': 'success',
         'message': '推文创建成功',
         'content': tweet.content,
         'name': tweet.author.name,
         'nickname': tweet.author.nickname,
         'author_avatar': tweet.author.get_avatar(size=48),
         'author_url': tweet.author.url,
         'author_name': tweet.author.name,
         'author_nickname': tweet.author.nickname,
         'tweet_url': tweet.url,
         'created': tweet.created,
         'id': tweet.id,
         'images': images,
     }
     return self.send_result(result, '/timeline')
예제 #7
0
 def delete(self, tweet_id):
     if not self.current_user.is_admin:
         return self.redirect_next_url()
     tweet = Tweet.get(id=tweet_id)
     if not tweet:
         return self.redirect_next_url()
     tweet.delete()
     result = {'status': 'success', 'message': '已成功删除'}
     return self.write(result)
예제 #8
0
파일: tweet.py 프로젝트: iselu/collipa
 def post(self):
     user = self.current_user
     content = self.get_argument('content', None)
     image_ids = self.get_argument('image_ids', None)
     images = []
     if not (content and len(strip_tags(content)) >= 3):
         result = {'status': 'error', 'message': '推文内容至少 3 字符'}
         return self.send_result(result, '/timeline')
     tweet = Tweet(content=strip_xss_tags(content), user_id=user.id).save()
     tweet.put_notifier()
     if image_ids:
         image_ids = image_ids.split(',')
         for image_id in image_ids:
             image_id = int(image_id)
             image = Image.get(id=image_id)
             if not image:
                 continue
             image.tweet_id = tweet.id
             images.append({
                 'id': image.id,
                 'path': image.path,
                 'width': image.width,
                 'height': image.height,
             })
     if images:
         tweet.has_img = 'true'
     result = {
         'status': 'success',
         'message': '推文创建成功',
         'content': tweet.content,
         'name': tweet.author.name,
         'nickname': tweet.author.nickname,
         'author_avatar': tweet.author.get_avatar(size=48),
         'author_url': tweet.author.url,
         'author_name': tweet.author.name,
         'author_nickname': tweet.author.nickname,
         'tweet_url': tweet.url,
         'created': tweet.created,
         'id': tweet.id,
         'images': images,
     }
     return self.send_result(result, '/timeline')
예제 #9
0
 def get(self):
     page = self.get_int('page', 1)
     from_id = self.get_int('from_id', 0)
     tweets = Tweet.get_timeline(page=page, from_id=from_id)
     return self.send_success_json(object_list=[tweet.to_dict() for tweet in tweets])
예제 #10
0
파일: tweet.py 프로젝트: wbbim/collipa
 def get(self, tweet_id):
     tweet_id = int(tweet_id)
     tweet = Tweet.get(id=tweet_id)
     if not tweet:
         raise tornado.web.HTTPError(404)
     return self.render("tweet/index.html", tweet=tweet)
예제 #11
0
파일: tweet.py 프로젝트: iselu/collipa
 def get(self, tweet_id):
     tweet_id = int(tweet_id)
     tweet = Tweet.get(id=tweet_id)
     if not tweet:
         raise tornado.web.HTTPError(404)
     return self.render("tweet/index.html", tweet=tweet)
예제 #12
0
파일: tweet.py 프로젝트: zky001/collipa
 def get(self):
     page = self.get_int('page', 1)
     from_id = self.get_int('from_id', 0)
     tweets = Tweet.get_timeline(page=page, from_id=from_id)
     return self.send_success_json(
         object_list=[tweet.to_dict() for tweet in tweets])