示例#1
0
文件: main.py 项目: jaykizhou/iguess
    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
文件: main.py 项目: llzhi001/iguess
    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
文件: main.py 项目: jaykizhou/iguess
    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
文件: main.py 项目: llzhi001/iguess
    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