Beispiel #1
0
def new():
    form = ApplyForm()
		
    if request.method == 'GET':
		all_course = course.filter(course.c.status == True)
    		return {'form':form,'all_course':all_course}
    elif request.method == 'POST':
		flag = form.validate(request.params)
		if flag:
			n = Apply(**form.data)
			n.save()
			response.template = "new_ok.html"
			return {"id":n.id} 
		else:
    			return {"form":form}
Beispiel #2
0
def acquire_apply_list():
    """
    GET:获取申请列表
    POST:修改申请列表
    :return:
    """
    # 当 method 为 GET 时
    if request.method == 'GET':
        # 获取参数
        rev_json = request.args
        apply_status_type = rev_json.get('type')
        start_cursor, end_cursor = rev_json.get('start_cursor'), rev_json.get(
            'end_cursor')
        building = rev_json.get('building')
        if None in {apply_status_type, start_cursor, end_cursor}:
            return send_json(-101, '缺少必要参数')
        start_cursor, end_cursor = int(start_cursor), int(end_cursor)
        # 进行查询
        applies = Apply.query
        # 首先根据审核状态查询
        if apply_status_type == 'uncheck':
            applies = applies.filter(Apply.check_status == "待审核")
        elif apply_status_type == 'checked':
            applies = applies.filter(
                or_(Apply.check_status == "审核通过",
                    Apply.check_status == "审核失败"))
        else:
            return send_json(-101, "type 参数错误")
        if building is not None:
            applies = applies.filter(Apply.building == building)  # 根据教学楼查询
        apply_num = applies.count()
        applies = applies.order_by(Apply.apply_id.desc())  # 对所有查询进行倒序排序
        if start_cursor > apply_num:
            return send_json(0, [])
        end_cursor = end_cursor if end_cursor <= apply_num else apply_num  # 防止end_id越界
        applies = applies.offset(start_cursor - 1).limit(end_cursor -
                                                         start_cursor + 1)

        apply_records = applies.all()
        result_data = [{
            'activity': apply_record.activity_name,
            'organization': apply_record.applicant_name,
            'time': apply_record.apply_time.strftime('%Y-%m-%d'),
            'building': apply_record.building,
            'room_name': apply_record.room_name
        } for apply_record in apply_records]

        return send_json(0, result_data)

    # 当 method 为 POST 时
    else:
        rev_json = request.get_json(silent=True)
        if rev_json is None:
            return send_json(-101, '缺少必需参数')
        apply_list = rev_json.get('applys')
        if type(apply_list) is not list:
            return send_json(-101, '缺少必需参数')
        if len(apply_list) == 0:
            return send_json(0, '待修改列表数据为空')

        admin = Administrator.query.get(session.get('admin_login'))

        success_list = list()
        for one_apply in apply_list:
            activity_name = one_apply.get('activity_name')
            use_date = one_apply.get('date')
            begin_time = one_apply.get('begin_time')
            end_time = one_apply.get('end_time')
            room_name = one_apply.get('room_num', '不指定')
            building = one_apply.get('building', '不指定')
            floor = one_apply.get('floor', '不指定')
            applicant_name = one_apply.get('applicant_name')
            applicant_phone = one_apply.get('applicant_phone')
            if None in {
                    activity_name, use_date, begin_time, end_time,
                    applicant_phone, applicant_name
            }:
                return send_json(-101, '缺少必需参数')
            one_apply_record = Apply(apply_id=0,
                                     activity_name=activity_name,
                                     applicant_id='',
                                     applicant_name=applicant_name,
                                     applicant_phone=applicant_phone,
                                     apply_time=datetime.now(),
                                     use_date=use_date,
                                     begin_time=begin_time,
                                     end_time=end_time,
                                     people_count=-1,
                                     room_name=room_name,
                                     building=building,
                                     floor=floor,
                                     teacher_name='',
                                     check_status='审核通过',
                                     org=admin.org,
                                     verifier_name=admin.name)
            db.session.add(one_apply_record)
            try:
                db.session.commit()
                success_list.append(one_apply)
            except Exception as e:
                db.session.rollback()
                record_exception(e)
                return send_json(0, '数据库异常')
        return send_json(0, success_list)
Beispiel #3
0
def Stu_Apply():
    global result_data
    if request.method == 'POST':
        # 学生提交申请
        json_data = request.get_json(silent=True)

        if json_data is None:
            return jsonify(code=-101, data=None)

        if not json_data.get('activity_name'):
            return jsonify(code=-101, data={'tip': '缺少活动名称参数'})

        '''
        if not json_data.get('applicant_id'):
            return jsonify(code=-101, data={'tip': '缺少申请人学号参数'})
        '''

        if not json_data.get('applicant_name'):
            return jsonify(code=-101, data={'tip': '缺少申请人姓名参数'})

        if not json_data.get('applicant_phone'):
            return jsonify(code=-101, data={'tip': '缺少申请人联系方式参数'})

        if not json_data.get('use_date'):
            return jsonify(code=-101, data={'tip': '缺少活动使用日期参数'})

        if not json_data.get('begin_time'):
            return jsonify(code=-101, data={'tip': '缺少教室开始使用时间参数'})

        if not json_data.get('end_time'):
            return jsonify(code=-101, data={'tip': '缺少教室结束使用时间参数'})

        if not json_data.get('people_count'):
            return jsonify(code=-101, data={'tip': '缺少参加人数参数'})

        if not json_data.get('teacher_name'):
            return jsonify(code=-101, data={'tip': '缺少负责教师姓名参数'})

        if not json_data.get('building'):
            return jsonify(code=-101, data={'tip': '缺少教室所在教学楼的参数'})

        if not json_data.get('floor'):
            return jsonify(code=-101, data={'tip': '缺少教室所在楼层参数'})

        if not json_data.get('room'):
            return jsonify(code=-101, data={'tip': '缺少教室名字参数'})

        request_flag = material_flag = 1  # 如果为0,表示post传递的json不含有request_或material字段

        if not json_data.get('request'):
            request_flag = 0
        if not json_data.get('material'):
            material_flag = 0

        building_posted = json_data.get('building')
        floor_posted = json_data.get('floor')
        room_posted = json_data.get('room')
        exist = Room.query.filter(
            Room.room_name == room_posted and Room.floor == floor_posted and Room.building == building_posted).first()
        if exist is None:
            return jsonify(code=-102, data={'tip': '未查询到该教室'})

        room = Apply()
        time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        apply_id = str(0)
        room.apply_id = apply_id
        room.activity_name = json_data.get('activity_name')
        room.applicant_id = from_session_get_applicant_id()
        room.applicant_name = json_data.get('applicant_name')
        room.applicant_phone = json_data.get('applicant_phone')
        room.apply_time = time
        room.use_date = json_data.get('use_date')
        room.begin_time = json_data.get('begin_time')
        room.end_time = json_data.get('end_time')
        room.people_count = json_data.get('people_count')
        if request_flag:
            room.request = json_data.get('request')
        room.teacher_name = json_data.get('teacher_name')
        if material_flag:
            room.material = json_data.get('material')
        room.check_status = '待审核'
        room.building = json_data.get('building')
        room.floor = json_data.get('floor')
        room.room_name = json_data.get('room')

        db.session.add(room)
        db.session.commit()
        try:
            db.session.commit()
        except:
            db.session.rollback()
            return jsonify(code=101, data={'tip': '数据库异常'})

        return jsonify(code=0, data={'tip': '正常'})

    elif request.method == 'GET':
        # 获取所有申请列表
        records = Apply.query.all()
        result_data = list()

        status_map = {
            '待审核': 0,
            '审核通过': 1,
            '审核失败': 2,
        }

        for record in records:
            result_data.append(dict(
                apply_id=record.apply_id,
                building=record.building,
                floor=record.floor,
                room=record.room_name,
                date=record.use_date,
                begin_time=record.begin_time,
                end_time=record.end_time,
                check_status=status_map.get(record.check_status)
            ))

    return jsonify(code=0, data=result_data)
Beispiel #4
0
def showapply():
    all= Apply.filter(Apply.c.status == True)	
    return {"all":all}