예제 #1
0
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('uid', type=str)
        parser.add_argument('info', type=str, action='append', required=True)
        args = parser.parse_args()

        if 'uid' not in args or not args['uid']:  # 参数中没有uid
            if login.current_user.is_authenticated:  # 该用户已登录
                args['uid'] = login.current_user.uid  # uid加到参数中
            else:
                raise UserInfoNotFound("UID is not provided")

        user_info = models.UserInfo.query.get(args['uid'])  # 把uid参数加入到用户信息中
        if not user_info:
            raise UserInfoNotFound("This user hasn't provided any information")

        result = {}

        for info in args["info"]:
            if info not in [
                    'student_id', 'department', 'school', 'introduction'
            ]:
                continue
            result[info] = getattr(user_info, info)  # 用户信息放到result中

        return result
예제 #2
0
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('uid', type=str)

        args = parser.parse_args()

        if 'uid' not in args or not args['uid']:
            if login.current_user.is_authenticated:
                args['uid'] = login.current_user.uid
            else:
                raise UserInfoNotFound("UID is not provided")

        user_info = models.UserInfo.query.get(args['uid'])
        if not user_info and args['uid'] != login.current_user.uid:
            raise UserInfoNotFound("This user hasn't provided any information")

        result = {}

        for info in [
                'student_id', 'grade', 'department', 'school', 'major', 'qq',
                'introduction'
        ]:
            result[info] = getattr(
                user_info, info)  # 用户信息放到result中即result[info] = user_info.info

        return result
예제 #3
0
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('name')

        args = parser.parse_args()

        if 'name' not in args or not args['name']:
            raise UserInfoNotFound("Name is not provided")

        contacts_info = models.Credential.query.filter_by(
            cred_type='name', cred_value=args['name']).first()
        if not contacts_info:
            raise UserInfoNotFound("This user hasn't provided any information")

        uid = contacts_info.uid
        contacts_info = models.UserInfo.query.get(uid)

        result = {}

        for info in [
                'student_id', 'grade', 'department', 'school', 'major', 'qq',
                'introduction'
        ]:
            result[info] = getattr(contacts_info, info)

        return result
예제 #4
0
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('id', type=int)
        args = parser.parse_args()

        mission = models.Mission.query.filter_by\
        (id=args['id']).order_by(models.Mission.cred_at).first()
        if mission is None:
            raise UserInfoNotFound("No missions posted.")

        result = dict()
        result['act_name'] = mission.act_name
        result['act_date'] = mission.act_date
        names = []
        contents = []
        remarks = []
        members = models.MnMember.query.filter_by(id=args['id']).all()
        for member in members:
            names.append(getattr(member, 'name'))
            contents.append(getattr(member, 'act_content'))
            remarks.append(getattr(member, 'remarks'))
        result['names'] = names
        result['contents'] = contents
        result['remarks'] = remarks

        return result  # dict中含list
예제 #5
0
    def get(self):

        notification = models.NotiMember.query.filter_by\
         (uid=login.current_user.uid).order_by(models.NotiMember.cred_at).all()
        if notification is None:
            raise UserInfoNotFound("No notifications posted.")

        result = {}
        for noti in notification:
            title = getattr(noti, 'title')
            result[title] = []
            nt = models.Notification.query.filter_by(title=title).first()
            for info in ['title', 'content']:
                result[info].append(getattr(nt, info))

        return result  # dict中包含list
예제 #6
0
    def get(self):

        mission = models.MnMember.query.filter_by\
        (uid=login.current_user.uid).order_by(models.MnMember.id).all()
        if mission is None:
            raise UserInfoNotFound("No missions posted.")

        result = {}
        end_mn = []
        last_mn = []
        for mn in mission:
            id = getattr(mn, 'id')
            this_mn = models.Mission.query.get(id)
            if getattr(this_mn, 'end') is False:
                last_mn.append(getattr(this_mn, 'act_name'))
            else:
                end_mn.append(getattr(this_mn, 'act_name'))
        result['end'] = end_mn
        result['last'] = last_mn

        return result