コード例 #1
0
def respond_array(struct_type):
    if struct_type == "array":
        array = request.get_array(field_name='file')
        return jsonify({"result": array})
    elif struct_type == "dict":
        adict = request.get_dict(field_name='file')
        return jsonify({"result": adict})
    elif struct_type == "records":
        records = request.get_records(field_name='file')
        return jsonify({"result": records})
    elif struct_type == "book":
        book = request.get_book(field_name='file')
        return jsonify({"result": book.to_dict()})
    elif struct_type == "book_dict":
        book_dict = request.get_book_dict(field_name='file')
        return jsonify({"result": book_dict})
コード例 #2
0
def upload_array(struct_type):
    if struct_type == "array":
        array = request.get_array(field_name='file')
        return excel.make_response_from_array(array, 'xls')
    elif struct_type == "dict":
        adict = request.get_dict(field_name='file')
        return excel.make_response_from_dict(adict, 'xls')
    elif struct_type == "records":
        records = request.get_records(field_name='file')
        return excel.make_response_from_records(records, 'xls')
    elif struct_type == "book":
        book = request.get_book(field_name='file')
        return excel.make_response(book, 'xls')
    elif struct_type == "book_dict":
        book_dict = request.get_book_dict(field_name='file')
        return excel.make_response_from_book_dict(book_dict, 'xls')
コード例 #3
0
def upload_array(struct_type):
    if struct_type == "array":
        array = request.get_array(field_name="file")
        return excel.make_response_from_array(array,
                                              "xls",
                                              sheet_name="test_array")
    elif struct_type == "dict":
        adict = request.get_dict(field_name="file")
        return excel.make_response_from_dict(adict,
                                             "xls",
                                             sheet_name="test_array")
    elif struct_type == "records":
        records = request.get_records(field_name="file")
        return excel.make_response_from_records(records,
                                                "xls",
                                                sheet_name="test_array")
    elif struct_type == "book":
        book = request.get_book(field_name="file")
        return excel.make_response(book, "xls")
    elif struct_type == "book_dict":
        book_dict = request.get_book_dict(field_name="file")
        return excel.make_response_from_book_dict(book_dict, "xls")
コード例 #4
0
def import_students(rfile):
    try:
        log.info('Import students from : {}'.format(rfile))
        #rrf = pyexcel.book(file_name = rfile.filename)
        rrf = request.get_book(field_name='upload_students')

        #read and store the series information
        #first row contains the headers...
        try:
            rrf.reeksen.name_columns_by_row(0)
            series_dict = {}
            for i in range(rrf.reeksen.number_of_rows()):
                if rrf.reeksen[i, 'NAAM'] != '' and rrf.reeksen[i, 'VOLGORDE'] != '' and rrf.reeksen[i, 'NUMMER'] != '':
                    find_series = Series.query.filter(Series.name == rrf.reeksen[i, 'NAAM']).first()
                    if find_series:
                        series_dict[rrf.reeksen[i, 'NUMMER']] = find_series
                    else:
                        ns = Series(name=rrf.reeksen[i, 'NAAM'], sequence=rrf.reeksen[i, 'VOLGORDE'])
                        series_dict[rrf.reeksen[i, 'NUMMER']] = ns
                        db.session.add(ns)
            db.session.commit()
        except Exception as e:
            flash('Kan blad \'reeksen\' niet vinden')
            log.warning('cannot find sheet reeksen: {}'.format(e))

        #read and store the student information
        #first row contains the headers...
        try:
            rrf.studenten.name_columns_by_row(0)
            empty_rfid_ctr = 0
            find_student = Registration.query.filter(Registration.rfidcode.like('LEEG#%')).order_by(Registration.rfidcode.desc()).first()
            if find_student:
                empty_rfid_ctr = int(find_student.rfidcode.split('#')[-1]) + 1
            nbr_students = 0
            for i in range(rrf.studenten.number_of_rows()):
                if rrf.studenten[i, 'VOORNAAM'] != '' and rrf.studenten[i, 'NAAM'] != '' and \
                    rrf.studenten[i, 'KLAS'] != '' and rrf.studenten[i, 'LEERLINGNUMMER'] != '' and \
                    rrf.studenten[i, 'REEKS'] != '' and rrf.studenten[i, 'GESLACHT'] != '':
                    find_student = Registration.query.filter(Registration.studentcode == rrf.studenten[i, 'LEERLINGNUMMER']).first()
                    if not find_student:
                        if rrf.studenten[i, 'RFID'] == '':
                            rfidcode = 'LEEG#{}'.format(empty_rfid_ctr)
                            empty_rfid_ctr += 1
                        else:
                            rfidcode = rrf.studenten[i, 'RFID']
                        nr = Registration(first_name = rrf.studenten[i, 'VOORNAAM'], last_name=rrf.studenten[i, 'NAAM'], \
                                        gender = rrf.studenten[i, 'GESLACHT'],
                                        classgroup = rrf.studenten[i, 'KLAS'],
                                        studentcode = rrf.studenten[i, 'LEERLINGNUMMER'],
                                        rfidcode = rfidcode,
                                        series=series_dict[int(rrf.studenten[i, 'REEKS'])])
                        db.session.add(nr)
                        nbr_students += 1
                    else:
                        log.warning('student with code {} already present, skip'.format(rrf.studenten[i, 'LEERLINGNUMMER']))
                else:
                    log.warning('could not add student : {}'.format(i))
            db.session.commit()
            log.info('import: added {} students'.format(nbr_students))
            flash('{} leerlingen zijn geimporteerd'.format(nbr_students))
        except Exception as e:
            flash('Probleem met excel-blad \'studenten\'')
            log.warning('cannot find sheet studenten: {}'.format(e))

    except Exception as e:
        flash('Kan bestand niet importeren')
        log.warning('cannot import: {}'.format(e))