示例#1
0
def super_put_user(id):
    data = request.json or {}
    data['id'] = id
    form = UserPutForm()
    form.validate_for_api()
    UserModel.put_user(id, data=data)
    return Success(msg='修改用户信息成功!')
示例#2
0
def get_sign(id):
    data = {'id': id}
    form = SignIdForm(data=data)
    form.validate_for_api()
    is_effective = form.is_effective
    sign = form.sign
    classrooms = []
    for room in sign['classroomIds']:
        classrooms.append({
            'id': str(room['id']),
            'name': room['name'],
            'stuNum': room['stuNum']
        })
    users = []
    for user in sign['signUsers']:
        users.append({
            'id': str(user['id']),
            'name': user['name'],
            'schoolId': user['schoolId'],
            'avatar': user['avatar']
        })
    res = {
        'id': str(sign['id']),
        'adminName': sign['adminId']['name'],
        'created_at': sign['created_at'],
        'name': sign['name'],
        'token': sign['token'],
        'classrooms': classrooms,
        'users': users,
        'is_effective': is_effective
    }
    return Success(msg='查询成功!', data=res)
示例#3
0
def post_user():
    data = request.json
    form = UserRegisterForm(data=data)
    form.validate_for_api()
    print(request.json)
    UserModel.add_user(data=data)
    return Success(msg="注册成功!")
示例#4
0
def user_post_sign():
    data = request.json or {}
    userId = g.user.id
    data['userId'] = userId
    UserPostSignForm(data=data).validate_for_api()
    SignModel.user_sign(token=data['token'], userId=userId)
    return Success(msg='签到成功')
示例#5
0
def put_share(id):
    data = request.json or {}
    data['id'] = id
    data['adminId'] = g.user.id
    PutShareForm(data=data).validate_for_api()
    ShareModel.put_share(id, data=data)
    return Success(msg='修改资源分享成功!')
示例#6
0
def get_share_list():
    form = UserGetListForm(data=request.args)
    form.validate_for_api()
    page = form.page.data
    size = form.size.data
    keyword = str(request.args['keyword']) or ''
    count = ShareModel.objects(title__contains=keyword).count()
    shares = ShareModel.objects(
        title__contains=keyword).order_by('-created_at').skip(
            (int(page) - 1) * int(size)).limit(int(size))
    list = []
    for share in shares:
        list.append({
            'id': str(share['id']),
            'title': share['title'],
            'created_at': share['created_at'],
            'adminName': share['adminId']['name']
        })
    data = {
        'pagination': {
            'count': count,
            'size': int(size),
            'page': int(page)
        },
        'list': list
    }
    return Success(msg='获取成功!', data=data)
示例#7
0
def put_topic(id):
    data = request.json or {}
    data['id'] = id
    data['adminId'] = g.user.id
    PutTopicForm(data=data).validate_for_api()
    TopicModel.put_topic(id, data=data)
    return Success(msg='修改话题成功!')
示例#8
0
def post_topic():
    data = request.json or {}
    data['adminId'] = g.user.id
    print(data)
    PostTopicForm().validate_for_api()
    TopicModel.add_topic(data=data)
    return Success(msg='创建话题成功!')
示例#9
0
def super_put_comment(id):
    data = request.json or {}
    data['id'] = id
    data['userId'] = g.user.id
    SuperPutCommentForm(data=data).validate_for_api()
    CommentModel.put_comment(data=data)
    return Success(msg='修改评论成功!')
示例#10
0
def get_sign_list():
    data = request.args
    form = GetSignListForm(data=data)
    form.validate_for_api()
    res = SignModel.get_sign_list(page=form.page.data,
                                  size=form.size.data,
                                  classId=form.classId.data)
    return Success(msg='获取成功!', data=res)
示例#11
0
def post_sign():
    data = request.json or {}
    data['adminId'] = g.user.id
    PostSignForm(data=data).validate_for_api()
    token = create_token(data=data).decode('ascii')
    data['token'] = token
    id = SignModel.add_sign(data=data)
    return Success(msg='创建签到表成功', data={'id': id})
示例#12
0
def super_delete_sign():
    data = request.json or {}
    print(data)
    form = SuperDeleteSignForm(data=data)
    form.validate_for_api()
    SignModel.super_delete_user_sign(signId=data['signId'],
                                     signUsers=form.signUsers)
    return Success(msg='删除成功')
示例#13
0
def put_user():
    data = request.json or {}
    id = g.user.id
    data['id'] = id
    form = UserPutForm()
    form.validate_for_api()
    UserModel.put_user(id, data=data)
    return Success(msg='修改个人信息成功!')
示例#14
0
def get_classroom():
    classrooms = ClassModel.objects().order_by('name')
    data = []
    for cls in classrooms:
        data.append({
            'id': str(cls['id']),
            'name': cls['name'],
            'stuNum': cls['stuNum']
        })
    return Success(msg='获取班级列表成功!', data=data)
示例#15
0
def get_comment_list():
    data = request.args
    form = GetCommentListForm(data=data)
    form.validate_for_api()
    data = {
        "topicId": form.topicId.data,
        'page': form.page.data,
        'size': form.size.data
    }
    data = CommentModel.get_comment_list(data)
    return Success(msg='获取成功!', data=data)
示例#16
0
def get_user_list():
    data = request.args or {}
    form = UserGetListForm(data=data)
    form.validate_for_api()
    page = form.page.data
    size = form.size.data
    userName = data['userName'] or ''
    schoolId = data['schoolId'] or ''
    classroom = data['classroom'] or ''
    if classroom != '':
        try:
            classroom = ObjectId(classroom)
        except:
            return FormValidateError(msg='班级id有误')
        cls = ClassModel.objects(id=classroom).first()
        if cls is None:
            return FormValidateError(msg='班级id有误')
        count = UserModel.objects(name__contains=userName,
                                  schoolId__contains=schoolId,
                                  classId=cls).count()
        users = UserModel.objects(
            name__contains=userName, schoolId__contains=schoolId,
            classId=cls).order_by('classId', 'schoolId').skip(
                (int(page) - 1) * int(size)).limit(int(size))
    else:
        count = UserModel.objects(name__contains=userName,
                                  schoolId__contains=schoolId).count()
        users = UserModel.objects(
            name__contains=userName,
            schoolId__contains=schoolId).order_by('classId', 'schoolId').skip(
                (int(page) - 1) * int(size)).limit(int(size))

    list = []
    for user in users:
        list.append({
            'id': str(user['id']),
            'name': user['name'],
            'classId': str(user['classId']['id']),
            'classname': str(user['classId']['name']),
            'schoolId': user['schoolId'],
            'avatar': user['avatar']
        })
    data = {
        'pagination': {
            'count': count,
            'size': int(size),
            'page': int(page)
        },
        'list': list
    }
    return Success(msg='获取成功!', data=data)
示例#17
0
def get_token():
    data = request.json
    form = ClientForm(data=data)
    form.validate_for_api()
    # 账号和密码获取token 和 wxId 获取token
    promise = {
        ClientTypeEnum.USER_ACCOUNT: GetTokenByAccount,
        ClientTypeEnum.USER_MINA: GetTokenByMine
    }
    form = promise[form.type.data]()
    form.validate_for_api()
    token = create_token(form.userInfo).decode('ascii')
    data = {
        'id': form.userInfo['id'],
        'name': form.userInfo['name'],
        'token': token
    }
    return Success(msg='获取token成功', data=data)
示例#18
0
def post_classroom():
    data = request.json
    ClassRoomForm(data=data).validate_for_api()
    ClassModel.add_classroom(name=data['name'])
    return Success(msg='添加班级成功!')
示例#19
0
def delete_topic(id):
    data = {'id': id}
    form = TopicIdForm(data=data)
    form.validate_for_api()
    TopicModel.delete_topic(id)
    return Success(msg='删除话题成功!')
示例#20
0
def delete_share(id):
    data = {'id': id}
    form = ShareIdForm(data=data)
    form.validate_for_api()
    ShareModel.delete_share(id)
    return Success(msg='删除资源分享成功!')
示例#21
0
def super_post_sign():
    data = request.json or {}
    form = SuperPostSignForm(data=data)
    form.validate_for_api()
    SignModel.super_user_sign(signId=data['signId'], signUsers=form.signUsers)
    return Success(msg='签到成功')
示例#22
0
def post_share():
    data = request.json or {}
    data['adminId'] = g.user.id
    PostShareForm().validate_for_api()
    ShareModel.add_share(data=data)
    return Success(msg='添加资源分享成功!')
示例#23
0
def get_share(id):
    data = {'id': id}
    form = ShareIdForm(data=data)
    form.validate_for_api()
    return Success(msg='获取成功!', data=form.share)
示例#24
0
def delete_sign(id):
    data = {'id': id}
    SignIdForm(data=data).validate_for_api()
    SignModel.delete_sign(signId=id)
    return Success(msg='删除签到表成功')
示例#25
0
def put_classroom(id):
    data = request.json or {}
    data['id'] = id
    ClassRoomPutForm(data=data).validate_for_api()
    ClassModel.put_classroom(id=id, name=data['name'])
    return Success(msg='修改班级成功!')
示例#26
0
def get_topic(id):
    data = {'id': id}
    form = TopicIdForm(data=data)
    form.validate_for_api()
    return Success(msg='获取成功!', data=form.topic)
示例#27
0
def super_delete_comment(id):
    data = {"id": id}
    SuperDeleteCommentForm(data=data).validate_for_api()
    CommentModel.delete_comment(id)
    return Success(msg='删除评论成功!')
示例#28
0
def delete_comment(id):
    data = {"id": id, "userId": g.user.id}
    DeleteCommentForm(data=data).validate_for_api()
    CommentModel.delete_comment(id)
    return Success(msg='删除评论成功!')
示例#29
0
def delete_classroom(id):
    data = {'id': id}
    ClassRoomDeleteForm(data=data).validate_for_api()
    ClassModel.delete_classroom(id=id)
    return Success(msg='删除班级成功!')
示例#30
0
def post_comment():
    data = request.json or {}
    data['userId'] = g.user.id
    PostCommentForm(data=data).validate_for_api()
    CommentModel.add_comment(data=data)
    return Success(msg='添加评论成功!')