Beispiel #1
0
    def post(self):
        node_name = self.get_argument('node_name')
        people_id = self.get_argument('people_id')
        node = Node.query.get_first(name=node_name)
        people = People.query.filter_by(id=people_id).first_or_404()
        if not node:
            self.send_error(404)
            return
        
        title = self.get_argument('title', None)
        content = self.get_argument('content', None)
        hidden =  self.get_argument('hidden', None)
        topic = Topic()
        if not title:
            self.flash_message('Please fill the title field', 'error')
            self.render('admin/topic/create_topic.html', topic=topic)
            return
        
        #: avoid double submit
         
        digest = hashlib.md5(utf8(title)).hexdigest()
        key = "r:%d:%s" % (people.id, digest)
        url = complex_cache.get(key)
        if url:
            self.redirect(url)
            return

        if hidden == 'on':
            hidden = "y"
        else:
            hidden = "n"

        topic.title = title
        topic.content = content
        topic.node_id = node.id
        topic.people_id = people.id
        topic.hidden = hidden
        node.topic_count += 1
        db.session.add(topic)
        db.session.add(node)
        db.session.commit()

        url = '/topic/%d' % topic.id
        complex_cache.set(key, url, 100)
        self.redirect(url)

        #: notification
        refer = '<a href="/topic/%s">%s</a>' % (topic.id, topic.title)
        for username in set(find_mention(title)):
            self.create_notification(username, title, refer,
                                     exception=topic.people_id)
        for username in set(find_mention(content)):
            self.create_notification(username, content, refer,
                                     exception=topic.people_id)
Beispiel #2
0
    def get(self, channel_id):
        channel = PushChannel.query.filter_by(id=channel_id).first_or_404()
        channel_data = complex_cache.get("web_"+channel.name)

        if(channel_data is not None):
            channel_data = json.loads(channel_data)
            if(channel_data['format'] == 'json'):
                data = channel_data['data']
                return self.render('wepusher/show_channel_template.html', channel=channel, data=data)

        btc_set = complex_cache.hgetall(channel.name)
        print btc_set
        btc_prices = dict()
        for price in btc_set:
            btc_prices[price] = json.loads(btc_set[price])

        self.render('wepusher/show_channel.html', channel=channel, btc_prices=btc_prices
            )
Beispiel #3
0
    def post(self, id):
        # for topic reply
        content = self.get_argument('content', None)
        hidden = self.get_argument('hidden', None)
        if not content:
            self.flash_message('Please fill the required fields', 'error')
            self.redirect('/topic/%s' % id)
            return

        topic = Topic.query.get_first(id=id)
        if not topic:
            self.send_error(404)
            return
        if topic.status == 'delete':
            self.send_error(404)
            return
        if topic.status == 'close':
            self.send_error(403)
            return
    
        digest = hashlib.md5(utf8(content)).hexdigest()
        key = "r:%d:%s" % (self.current_user.id, digest)
        url = complex_cache.get(key)
        # avoid double submit
        if url:
            self.redirect(url)
            self.flash_message("you send a same message", "message")
            return

        user = self.current_user

        index_key = 'topic:%d'%topic.id
        index_num = complex_cache.get(index_key)
        if index_num is None:
            index_num = topic.reply_count
            complex_cache.set(index_key, index_num)

        index_num = complex_cache.incr(index_key,1)
        #: create reply
        reply = TopicReply(topic_id=id, people_id=user.id, content=content)
        # if hidden == 'on':
        #     reply.hidden = 'y'
        # else:
        #     reply.hidden = 'n'

        # if topic.hidden == 'y' and topic.people_id == user.id:
        #     reply.hidden = 'y'
            
        #: impact on topic
        topic.reply_count = index_num
        reply.order = index_num
        #: update topic's last replyer
        topic.last_reply_by = self.current_user.id
        topic.last_reply_time = datetime.utcnow()

        db.session.add(reply)
        db.session.add(topic)
        db.session.commit()

        num = (topic.reply_count - 1) / 30 + 1
        url = '/topic/%s' % str(id)
        if num > 1:
            url += '?p=%s' % num
        complex_cache.set(key, url, 100)
        self.redirect("%s#reply%s" % (url, topic.reply_count))

        refer = '<a href="/topic/%s#reply-%s">%s</a>' % \
                (topic.id, topic.reply_count, topic.title)
        #: reply notification
        self.create_notification(topic.people_id, content, refer, type='reply')
        #: mention notification
        for username in set(find_mention(content)):
            self.create_notification(username, content, refer,
                                     exception=topic.people_id)

        db.session.commit()