Example #1
0
def register(id):
    """
    # 社团管理员注册
    # status: OVER
    :param id: 管理员身份编号
    """
    if Admin.query.get(id):
        raise RegisterFailed(u'该社团已注册管理员')
    form = AdminRegisterForm(data=request.json).validate_or_error()
    Admin.register(id, form.account.data, form.password.data)
    return RegisterSuccess(msg=u'账号注册成功')
Example #2
0
def append_society():
    """
    # 添加社团
    :return:
    """
    count = 0
    data = request.json
    if not data:
        raise EmptyError()
    for value in data.values():
        if not Society.query.filter_by(name=value).first():
            Society.insert(value)
            count += 1
    return RegisterSuccess(msg='社团添加成功', data={'count': count})
Example #3
0
def user_apply():
    """
    # 用户报名
    # status: OVER
    """
    data = request.json
    if not data:
        raise EmptyError()
    ApplyFrom(data=data).validate_or_error()
    if Apply.query.filter_by(student_id=data.get('student_id'),
                             society_id=data.get('society_id')).first():
        # Apply.update(data)
        # return UpdateSuccess(msg=u'报名信息更新成功')
        raise RepeatError()
    Apply.insert(data)
    return RegisterSuccess(msg=u'报名成功')
Example #4
0
def append_brief():
    """
    # 添加社团简介
    # status: OVER
    :return:
    """
    data = request.json
    if not data:
        raise EmptyError()
    rich_text = RichText.query.filter_by(id=g.society_id).first()
    if rich_text:
        rich_text.delete()
        RichText.insert(g.society_id, data)
        return UpdateSuccess(msg=u'社团简介更新成功')
    else:
        RichText.insert(g.society_id, data)
        return RegisterSuccess(msg=u'社团简介添加成功')
Example #5
0
def append_section():
    """
    # 社团管理员添加部门
    # status: OVER
    :return:
    """
    count = 0
    data = request.json
    if not data:
        raise EmptyError()
    society = Society.query.get_or_404(g.society_id)
    for value in data.values():
        if not Section.query.filter_by(society_id=g.society_id,
                                       name=value).first():
            Section.insert(society, value)
            count += 1
    return RegisterSuccess(msg=u'部门添加成功', data={'count': count})
Example #6
0
def user():
    """
    # 收集微信用户信息
    # status:
    :return:
    """
    data = request.json
    app_id = current_app.config.get('APP_ID')
    app_secret = current_app.config.get('APP_SECRET')
    code = data.get('code')
    if not code:
        raise AuthFailed()
    response = request_wx_api(app_id, app_secret, code)
    user = User.query.filter_by(openid=response['openid']).first()
    if not user:
        User.insert(response['openid'], data)
        return RegisterSuccess(msg=u'用户信息保存成功')
    else:
        user.update(data)
        return UpdateSuccess(msg=u'用户信息更新成功')
Example #7
0
def file_upload():
    """
    # 文件上传
    # status: OVER
    :return:
    """
    success_count = 0
    file = request.files['file']
    if file and allowed_file(file.filename):
        data = xlrd.open_workbook(file_contents=file.read())
        if data.sheet_loaded(data.sheet_names()[-1]):
            table = data.sheets()[0]
            if not isinstance(table.cell_value(0, 1), str):
                raise FormError(u'文件上传失败,请检查表中格式是否正确')
            if '社团' not in table.cell_value(0, 1):
                raise FormError(u'文件上传失败,请检查表中格式是否正确')
            for num in range(1, table.nrows):
                count = 1  # 第一列
                for row in table.row_values(num):
                    # id = None
                    if count == 1: pass  # 序号列
                    elif count == 2:  # 社团列
                        id = generate_id(row)
                        if not Society.query.filter_by(name=row).first():
                            Society.insert(row)
                    else:
                        if not row:
                            continue
                        society = Society.query.get(id)
                        if not Section.query.filter_by(name=row,
                                                       society_id=id).first():
                            Section.insert(society, row)
                            success_count += 1
                    count += 1
    else:
        raise FormError(msg=u'文件上传失败,文件后缀错误')
    return RegisterSuccess(msg=u'数据导入成功', data={'count': success_count})