Exemple #1
0
 def post(self, slug):
     node = self.db.query(Node).filter_by(slug=slug).first()
     if not node:
         self.send_error(404)
         return
     title = self.get_argument("title", None)
     content = self.get_argument("content", None)
     if not (title and content):
         self.render("topic_form.html", message="Please Fill the form")
         return
     key = hashlib.md5(utf8(content)).hexdigest()
     url = self.cache.get(key)
     # avoid double submit
     if url:
         self.redirect(url)
         return
     topic = Topic(title=title, content=content)
     topic.node_id = node.id
     topic.user_id = self.current_user.id
     node.topic_count += 1
     self.db.add(topic)
     self.db.add(node)
     self.db.commit()
     url = "/topic/%d" % topic.id
     self.cache.set(key, url, 100)
     self.redirect(url)
Exemple #2
0
 def prepare_topic(self):
     node = Node(title='june', urlname='june')
     db.session.add(node)
     topic = Topic(title='june', content='june', account_id=1, node_id=1)
     db.session.add(topic)
     db.session.commit()
     return topic
Exemple #3
0
    def post(self, slug):
        node = self.db.query(Node).filter_by(slug=slug).first()
        if not node:
            self.send_error(404)
            return
        title = self.get_argument('title', None)
        content = self.get_argument('content', None)
        if not (title and content):
            self.create_message('Form Error', 'Please fill the required field')
            self.render('topic_form.html', topic=None, node=node)
            return
        if not self._check_permission(node):
            self.create_message(
                'Warning',
                "You have no permission to create a topic in this node")
            self.render('topic_form.html', topic=None, node=node)
            return

        key = hashlib.md5(utf8(content)).hexdigest()
        url = self.cache.get(key)
        # avoid double submit
        if url:
            self.redirect(url)
            return
        topic = Topic(title=title, content=content)
        topic.node_id = node.id
        topic.user_id = self.current_user.id
        node.topic_count += 1
        self.db.add(topic)
        self.db.add(node)
        self.db.commit()
        url = '/topic/%d' % topic.id
        self.cache.set(key, url, 100)
        key1 = 'TopicListModule:0:1:-impact'
        key2 = 'NodeTopicsModule:%s:1:-impact' % node.id
        key3 = 'UserTopicsModule:%s:1:-impact' % self.current_user.id
        self.cache.delete_multi(['status', key1, key2, key3])
        self.redirect(url)

        # social networks
        content = "%s %s%s" % (title[:70], options.siteurl, url)
        networks = self.get_user_social(self.current_user.id)
        register_social(networks, content)