Пример #1
0
    def post(self):
        topic = Topic.get_by_id(int(self.request.get('id')))
        if not topic:
            self.response.out.write('莫有找到台词~~~')
            return

        user = users.get_current_user()
        if topic.answer == self.request.get('answer'):
            if user:
                ua = UserAnswer()
                ua.user = user
                ua.topic = topic
                ua.put()

                uac = UserAnswerCount()
                uac.add(user)

                memcache.delete('topic_list::latest'+user.user_id())

            if not topic.answered_count:
                topic.answered_count = 1
            else:
                topic.answered_count += 1
            topic.put()

            self.response.out.write(json_output('ok', {'message': '答对了,不错哦'}))
            return
        else:
            if not topic.failed_count:
                topic.failed_count = 1
            else:
                topic.failed_count += 1
            topic.put()
        self.response.out.write(json_output('fail', {'message': '再想想?'}))
Пример #2
0
    def post(self):
        topic = Topic.get_by_id(int(self.request.get('id')))
        if not topic:
            self.response.out.write('莫有找到台词~~~')
            return

        user = users.get_current_user()
        if topic.answer == self.request.get('answer'):
            if user:
                ua = UserAnswer()
                ua.user = user
                ua.topic = topic
                ua.put()

                uac = UserAnswerCount()
                uac.add(user)

                memcache.delete('topic_list::latest' + user.user_id())

            if not topic.answered_count:
                topic.answered_count = 1
            else:
                topic.answered_count += 1
            topic.put()

            self.response.out.write(json_output('ok', {'message': '答对了,不错哦'}))
            return
        else:
            if not topic.failed_count:
                topic.failed_count = 1
            else:
                topic.failed_count += 1
            topic.put()
        self.response.out.write(json_output('fail', {'message': '再想想?'}))
Пример #3
0
    def get_render_top_user(self):
        cache = memcache.get('top_user')
        if not cache:
            uac = UserAnswerCount()
            result = uac.getTop()

            topuser = []
            for item in result:
                topuser.append({
                    'gravatar': get_gravatar(item.user.email()),
                    'name': item.user.nickname(),
                    'count': item.count,
                })

            data = {'topuser': topuser }
            cache = self.get_render('top_user', data)
            memcache.set('top_user', cache, 60)
        return cache
Пример #4
0
    def get_render_top_user(self):
        cache = memcache.get('top_user')
        if not cache:
            uac = UserAnswerCount()
            result = uac.getTop()

            topuser = []
            for item in result:
                topuser.append({
                    'gravatar': get_gravatar(item.user.email()),
                    'name': item.user.nickname(),
                    'count': item.count,
                })

            data = {'topuser': topuser}
            cache = self.get_render('top_user', data)
            memcache.set('top_user', cache, 60)
        return cache