def post(self, id): # for topic reply content = self.get_argument('content', None) if not content: self.redirect('/topic/%s' % id) return topic = self.db.query(Topic).filter_by(id=id).first() if not topic: self.send_error(404) return if topic.status == 'close': self.send_error(403) return key = hashlib.md5(utf8(content)).hexdigest() url = self.cache.get(key) # avoid double submit if url: self.redirect(url) return reply = Reply(topic_id=id, user_id=self.current_user.id, content=content) # impact on topic topic.reply_count += 1 topic.impact += self._calc_impact(topic) # last reply topic.last_reply_by = self.current_user.id topic.last_reply_time = datetime.utcnow() #TODO impact on creator self.db.add(reply) self.db.add(topic) # notifications self.create_reply_notify(topic.user_id, topic, content) for username in set(find_mention(content)): self.create_mention(username, topic, content) self.db.commit() num = (topic.reply_count - 1) / 30 + 1 url = '/topic/%s' % str(id) if num > 1: url += '?p=%s' % num self.cache.set(key, url, 100) #TODO calculate page, delete the right cache self.cache.delete('ReplyListModule:%s:%s' % (str(id), num)) self.redirect("%s#reply%s" % (url, topic.reply_count)) # register social services content = "%s %s%s#reply-%s" % \ (content[:70], options.siteurl, url, topic.reply_count) networks = self.get_user_social(self.current_user.id) register_social(networks, content)
def post(self, id): # for topic reply content = self.get_argument('content', None) if not content: self.redirect('/topic/%s' % id) return topic = self.db.query(Topic).filter_by(id=id).first() if not topic: self.send_error(404) return key = hashlib.md5(utf8(content)).hexdigest() url = self.cache.get(key) # avoid double submit if url: self.redirect(url) return reply = Reply(topic_id=id, user_id=self.current_user.id, content=content) # impact on topic topic.reply_count += 1 topic.impact += self._calc_impact(topic) #TODO impact on creator self.db.add(reply) self.db.add(topic) # notifications self.create_notify(topic.user_id, topic, content) for username in set(find_mention(content)): self.create_mention(username, topic, content) self.db.commit() url = '/topic/%s' % str(id) self.cache.set(key, url, 100) #TODO calculate page, delete the right cache self.cache.delete('ReplyListModule:%s:1' % str(id)) self.redirect(url)