예제 #1
0
파일: handler.py 프로젝트: anstones/yong
    def get_sidebar_arguments(self):
        '''得到两侧栏的render变量'''

        user_id = self.current_user['_id']

        status_number = yield StatusDocument.get_status_number(user_id)
        topic_number = yield TopicDocument.get_topic_number_by_someone(
            user_id, visitor_id=user_id)

        user_setting = yield UserSettingDocument.find_one({
            'user':
            DBRef(UserDocument.meta['collection'], ObjectId(user_id))
        })
        login_reward_fetched_today = yield UserActivityDocument.login_reward_fetched(
            user_id)
        continuous_login_days = yield UserDocument.get_continuous_login_days(
            user_id)

        kwargs = {
            'status_number': status_number,
            'topic_number': topic_number,
            'MessageTopic': MessageTopic,
            'user_setting': user_setting,
            'login_reward_fetched_today': login_reward_fetched_today,
            'continuous_login_days': continuous_login_days,
            'HOME_SETTINGS': HOME_SETTINGS
        }

        raise gen.Return(kwargs)
예제 #2
0
    def post(self):
        response_data = {}

        login_reward_fetched = yield UserActivityDocument.login_reward_fetched(
            self.current_user['_id']
        )

        if login_reward_fetched:
            response_data.update({'error': '你已经领取了今日的登录奖励!'})
        else:
            now = datetime.now()

            document = {
                'user': DBRef(
                    UserDocument.meta['collection'],
                    ObjectId(self.current_user['_id'])
                ),
                'activity_type': UserActivityDocument.FETCH_LOGIN_REWARD,
                'time': now
            }
            activity_id = yield UserActivityDocument.insert(document)

            continuous_login_days = yield UserDocument.get_continuous_login_days(
                self.current_user['_id']
            )
            quantity = (1 + continuous_login_days / 7) * 5

            document = {
                'user': DBRef(
                    UserDocument.meta['collection'],
                    ObjectId(self.current_user['_id'])
                ),
                'activity': DBRef(
                    UserActivityDocument.meta['collection'],
                    ObjectId(activity_id)
                ),
                'in_out_type': WealthRecordDocument.IN,
                'quantity': quantity,
                'time': now
            }
            yield WealthRecordDocument.insert(document)

            yield UserDocument.update_wealth(
                self.current_user['_id'], quantity
            )
            yield UserDocument.update(
                {'_id': ObjectId(self.current_user['_id'])},
                {'$inc': {'continuous_login_days': 1}}
            )

            continuous_login_days = yield UserDocument.get_continuous_login_days(
                self.current_user['_id']
            )

            response_data.update({
                'wealth': self.current_user['wealth'] + quantity,
                'continuous_login_days': continuous_login_days
            })

        self.write_json(response_data)
예제 #3
0
    def get_sidebar_arguments(self):
        '''得到两侧栏的render变量'''

        user_id = self.current_user['_id']

        status_number = yield StatusDocument.get_status_number(user_id)
        topic_number = yield TopicDocument.get_topic_number_by_someone(
            user_id, visitor_id=user_id
        )

        user_setting = yield UserSettingDocument.find_one({
            'user': DBRef(UserDocument.meta['collection'], ObjectId(user_id))
        })
        login_reward_fetched_today = yield UserActivityDocument.login_reward_fetched(
            user_id
        )
        continuous_login_days = yield UserDocument.get_continuous_login_days(
            user_id
        )

        kwargs = {
            'status_number': status_number,
            'topic_number': topic_number,
            'MessageTopic': MessageTopic,
            'user_setting': user_setting,
            'login_reward_fetched_today': login_reward_fetched_today,
            'continuous_login_days': continuous_login_days,
            'HOME_SETTINGS': HOME_SETTINGS
        }

        raise gen.Return(kwargs)
예제 #4
0
    def post(self):
        response_data = {}

        login_reward_fetched = yield UserActivityDocument.login_reward_fetched(
            self.current_user['_id'])

        if login_reward_fetched:
            response_data.update({'error': '你已经领取了今日的登录奖励!'})
        else:
            now = datetime.now()

            document = {
                'user':
                DBRef(UserDocument.meta['collection'],
                      ObjectId(self.current_user['_id'])),
                'activity_type':
                UserActivityDocument.FETCH_LOGIN_REWARD,
                'time':
                now
            }
            activity_id = yield UserActivityDocument.insert(document)

            continuous_login_days = yield UserDocument.get_continuous_login_days(
                self.current_user['_id'])
            quantity = (1 + continuous_login_days / 7) * 5

            document = {
                'user':
                DBRef(UserDocument.meta['collection'],
                      ObjectId(self.current_user['_id'])),
                'activity':
                DBRef(UserActivityDocument.meta['collection'],
                      ObjectId(activity_id)),
                'in_out_type':
                WealthRecordDocument.IN,
                'quantity':
                quantity,
                'time':
                now
            }
            yield WealthRecordDocument.insert(document)

            yield UserDocument.update_wealth(self.current_user['_id'],
                                             quantity)
            yield UserDocument.update(
                {'_id': ObjectId(self.current_user['_id'])},
                {'$inc': {
                    'continuous_login_days': 1
                }})

            continuous_login_days = yield UserDocument.get_continuous_login_days(
                self.current_user['_id'])

            response_data.update({
                'wealth': self.current_user['wealth'] + quantity,
                'continuous_login_days': continuous_login_days
            })

        self.finish(json.dumps(response_data))