def import_checklist(): importForm = ImportChecklist() if importForm.validate_on_submit(): CheckResult.query.delete() def checkResult_init_func(row): cl = CheckResult() #cl.id = row['id'] cl.checkcode = row['checkcode'] cl.checkitemname = row['checkitemname'] cl.checklevel = row['checklevel'] cl.checktable = row['checktable'] cl.checktablename = row['checktablename'] cl.checktableterm = row['checktableterm'] cl.checksucflag = row['checksucflag'] cl.dmbegdate = row['dmbegdate'] cl.dmenddate = row['dmenddate'] cl.comcode = row['comcode'] return cl request.save_book_to_database(field_name='filechecklist', session=db.session, tables=[CheckResult], initializers=[checkResult_init_func]) return redirect(url_for('.handson_table'), code=302) return render_template('task/import_checklist.html', form=importForm)
def library_import(library): if library == 'Section': tables = [Section] elif library == 'Office': tables = [Office] elif library == 'Salary': tables = [Salary] elif library == 'Position': tables = [Position] elif library == 'Plantilla': tables = [Plantilla] elif library == 'Employee': tables = [Employee] title = 'Import to ' + library form = UploadForm() if form.validate_on_submit(): filename = secure_filename(form.filename.data.filename) request.save_book_to_database( field_name='filename', session=db.session, tables=tables, ) flash("You have successfully imported '{}' to {}".format( filename, library)) return redirect(url_for('admin.index')) else: filename = None return MyView().render("fadmin/import_library.html", form=form, title=title)
def doimport(): if request.method == 'POST': metrics = Metric.query.all() def metric_init_func(row): user_id=current_user.id m = Metric( row['service_name'], row['service_element_name'], row['service_level_detail'], row['target'], row['service_provider_steward_1'], row['metric_name'], row['metric_description'], row['metric_rationale'], row['metric_value_display_format'], row['threshold_target'], row['threshold_target_rationale'], row['threshold_target_direction'], row['threshold_trigger'], row['threshold_trigger_rationale'], row['threshold_trigger_direction'], row['data_source'], row['data_update_frequency'], row['metric_owner_primary'], row['vantage_control_id'], user_id) return m request.save_book_to_database( field_name='file', session=db.session, tables=[Metric], initializers=[metric_init_func]) return redirect(url_for('list_metrics')) return render_template('metrics_import.html', title="Metrics")
def index(self): form = UploadForm() messages = '' if form.validate_on_submit(): filename = secure_filename(form.filename.data.filename) try: request.save_book_to_database( field_name='filename', session=db.session, tables=[SalaryGrade]) flash("You have successfully imported '{}' to {}".format( filename, 'Salary Grade')) return redirect(url_for('admin.index')) except exc.SQLAlchemyError as e: db.session.rollback() # do this immediately for SQLAlchemy messages = e.message if hasattr(e, 'message') else str(e) if (messages.find('not-null constraint') != -1): messages = """Some or all required columns were not found from the source file.<br> <b>Ensure that the following columns are present:<br> sg, step, salary, group_name</b>""" except Exception as e: db.session.rollback() messages = e.message if hasattr(e, 'message') else str(e) if (messages.find('Sheet') != -1): messages = """Failed to import from '{}'.<br> <b>Ensure that the sheet name is set to 'salary_grade'.</b>"""\ .format(filename) # else: catchall function return self.render( 'fadmin/import_data.html', form=form, messages=messages)
def doimport(): if request.method == 'POST': def post_init_func(row): p = Post(row['id'], row['name'], row['middlegrade'], row['finalgrade'], row['grade']) return p request.save_book_to_database(field_name='file', session=db.session, tables=[Post], initializers=[post_init_func]) return redirect(url_for('grades')) return render_template('upload.html')
def doimport(self): if request.method == 'POST': players = Player.query.all() for player in players: print "Deleting %s" % player db.session.delete(player) db.session.commit() def player_init_func(row): p = Player(row['First Name'], row['Last Name'], row['Position'], row['FPPG'], row['Played'], row['Salary'], row['Injury Indicator'], row['Injury Details'], row['Play'], row['Team'], row['Human']) return p request.save_book_to_database(field_name='file', session=db.session, tables=[Player], initializers=([player_init_func])) return self.render('success.html')
def upload_all(): def category_init_func(row): c = Category(row['name']) c.id = row['id'] return c def post_init_func(row): # this is lessons learned that relation needs an object not a string c = Category.query.filter_by(name=row['category']).first() p = Post(row['title'], row['body'], c, row['pub_date']) return p request.save_book_to_database(field_name='file', session=db.session, tables=[Category, Post], initializers=[category_init_func, post_init_func]) return excel.make_response_from_tables(db.session, [Category, Post], "xls")
def import_service(): if request.method == 'POST': def service_init_func(row): c = Service() c.name = row['nom'] c.description = row['description'] return c request.save_book_to_database(field_name='file', session=db.session, tables=[Service], initializers=[service_init_func]) return redirect(url_for('admin.service'), code=302) return render_template('admin/service/import.html', service=service)
def import_slot(): if request.method == 'POST': def triage_init_func(row): t = Triage() t.location = row['LOCATION'] t.description = row['DESCRIPTION'] t.capacity = row['CAPACITY'] t.available = row['CAPACITY'] return t request.save_book_to_database(field_name='file', session=db.session, \ tables=[Triage], \ initializers=([triage_init_func])) flash('HTMB timeslot created') return render_template('acknowledge.html') return render_template('import.html', title='Import Parkway Timeslot')
def import_case(): if request.method == 'POST': def ref_init_func(row): r = Reference() r.case_id = row['CASE_ID'] r.booking_ref = row['BOOKING_REF'] r.expire_on = datetime.datetime.strptime(row['EXPIRE_ON'], \ "%Y-%m-%d %H:%M:%S") return r request.save_book_to_database(field_name='file', session=db.session, \ tables=[Reference], \ initializers=([ref_init_func])) flash('HTMB cases created') return render_template('acknowledge.html') return render_template('import.html', title='Import Pre-IPPT')
def import_label(): if request.method == 'POST': def label_init_func(row): c = Label(id=row['id'], name=row['nom'], description=row['description']) return c request.save_book_to_database(field_name='file', session=db.session, tables=[Label], initializers=[label_init_func]) return redirect(url_for('admin.label'), code=302) return render_template('admin/label/import.html', label=label)
def doimport(): if request.method == 'POST': def category_init_func(row): c = Category(row['name']) c.id = row['id'] return c def post_init_func(row): c = Category.query.filter_by(name=row['category']).first() p = Post(row['title'], row['body'], c, row['pub_date']) return p request.save_book_to_database(field_name='file', session=db.session, tables=[Category, Post], initializers=[category_init_func,post_init_func]) return "Saved" return '''
def import_category(): if request.method == 'POST': def category_init_func(row): c = Category(id=row['id'], name=row['nom'], description=row['description']) return c request.save_book_to_database(field_name='file', session=db.session, tables=[Category], initializers=[category_init_func]) return redirect(url_for('admin.category')) return render_template('admin/category/import.html', category=category)
def doimport(): if request.method == 'POST': def category_init_func(row): c = Category() c.id = row['id'] c.name = row['name'] c.description = row['description'] return c request.save_book_to_database(field_name='file', session=db.session, tables=[Category], initializers=[category_init_func]) return redirect(url_for('.handson_table'), code=302) return '''
def import_data(): if request.method == 'POST': def sample_nature_init_func(row): p = SampleNature(name=row['Nom'], siggle=row['Siggle'], volume=row['Volume'], description=row['Description']) return p request.save_book_to_database(field_name='file', session=db.session, tables=[SampleNature], initializers=[sample_nature_init_func]) return redirect(url_for('.handson_table'), code=302) return render_template('sample_nature/import.html')
def setup(): if request.method == 'POST': def department_init_func(row): d = Department(name=row['name'], description=row['description']) return d def unit_init_func(row): d = Department.query.filter_by(name=row['department']).first() u = Unit(name=row['name'], description=row['description'], department=d) return u def level_init_func(row): l = Level(name=row['name'], description=row['description']) return l def spinneret_init_func(row): s = Spinneret(name=row['name'], description=row['description']) return s def trainee_init_func(row): level = Level.query.filter_by(name=row['level']).first() unit = Unit.query.filter_by(name=row['unit']).first() spinneret = Spinneret.query.filter_by(name=row['spinneret']).first() c = Trainee() c.image_filename = 'default.png' c.image_url = os.path.join(basedir, 'app/static/img/trainee_default.png') c.registration_number = row['registration_number'] c.first_name = row['first_name'] c.last_name = row['last_name'] c.level = level c.unit_id = unit c.spinneret = spinneret c.school = row['school'] c.email = row['email'] c.phone = row['phone'] c.theme = row['theme'] print( row ) request.save_book_to_database( field_name='file', session=db.session, tables=[Department, Unit, Level, Spinneret, Trainee], initializers=[department_init_func, unit_init_func, level_init_func, spinneret_init_func, trainee_init_func]) return redirect(url_for('.handson_table'), code=302) return render_template('home/setup.html')
def doimport(): if request.method == 'POST': def area_init_func(row): a = Area(row['nome_area']) a.id = row['id'] return a def docente_init_func(row): a = Area.query.filter_by(nome_area=row['area_docente']).first() d = Docente(row['nome_docente'], a, row['qualifica_docente']) return d def uc_init_func(row): u = Uc(row['nome_uc']) u.id = row['id'] return u def tipo_init_func(row): t = Tipo(row['tipo_curso']) t.id = row['id'] return t def curso_init_func(row): t = Tipo.query.filter_by(tipo_curso=row['tipo_curso']).first() c = Curso(row['nome_curso'], t, row['duracao_curso'], row['provas_ingresso'], row['classificacao_minima']) return c def plano_init_func(row): u = Uc.query.filter_by(nome_uc=row['plano_uc']).first() p = Plano(row['ano'], row['semestre'], row['plano_area'], u, row['plano_ects'], row['plano_docente'], row['plano_curso'], row['plano_tipo']) return p request.save_book_to_database( field_name='file', session=db.session, tables=[Area, Docente, Tipo, Curso, Uc, Plano], initializers=[ area_init_func, docente_init_func, tipo_init_func, curso_init_func, uc_init_func, plano_init_func ]) return redirect(url_for('.handson_table'), code=302) return '''
def check_for_conflict(): if request.method == 'POST': def student_init_func(row): name = row['First Name'] + " " + row['Last Name'] s = models.Student(name) s.gender = row['Gender'] s.years_in_choir = row['Years in Choir'] s.allergies = row['Allergies'] s.member = current_user.president return s request.save_book_to_database(field_name='file', session=db.session, tables=[models.Student], initializers=[student_init_func]) choir = current_user.president students = models.Student.query.filter_by(member=choir).all() return render_template('president_students.html', students=students, choir_name=choir.choir_name)
def doimport(): if request.method == 'POST': def category_init_func(row): c = Category(row['name']) c.id = row['id'] return c def post_init_func(row): c = Category.query.filter_by(name=row['category']).first() p = Post(row['title'], row['body'], c, row['pub_date']) return p request.save_book_to_database( field_name='file', session=db.session, tables=[Category, Post], initializers=[category_init_func, post_init_func]) return "Saved" return '''
def import_data(): if request.method == 'POST': # if request.form.get('is_delete') is True: Sample.query.delete() def sample_init_func(row): p = Sample(code=row['code'], date=row['date'], jonc_type_id=row['jonc_type_id'], mesure_id=row['mesure_id'], parent_id=row['parent_id'], patient_id=row['patient_id'], sample_nature_id=row['sample_nature_id'], sample_type_id=row['sample_type_id'], status=row['status'], technique=row['technique'], support_id=row['support_id'], volume=row['volume'], origin_id=row['origin_id'], ) return p request.save_book_to_database( field_name='file', session=db.session, tables=[Sample], initializers=[sample_init_func]) return redirect(url_for('.search')) return render_template('sample/import.html')
def import_data(): if request.method == 'POST': def process_init_func(row): c = Category.query.filter_by(name=row['category']).first() p = Process(category=c, display_as=row['display_as'], firstname=row['firstname'], lastname=row['lastname'], adresse=row['adresse'], telephone=row['telephone'], email=row['email']) return p request.save_book_to_database(field_name='file', session=db.session, tables=[Process], initializers=[process_init_func]) return redirect(url_for('.handson_table'), code=302) return render_template('process/import.html')
def doimport(): if request.method == "POST": def category_init_func(row): c = Category(row["name"]) c.id = row["id"] return c def post_init_func(row): c = Category.query.filter_by(name=row["category"]).first() p = Post(row["title"], row["body"], c, row["pub_date"]) return p request.save_book_to_database( field_name="file", session=db.session, tables=[Category, Post], initializers=[category_init_func, post_init_func], ) return redirect(url_for(".handson_table"), code=302) return """
def uploadUserExcel(): companyId = session.get("companyId") if not companyId: return jsonify({"code":301, "result":"회사정보가 없습니다."}) jobClass_row = db_session.query(Company.categoryId).filter(Company.companyId==companyId).first() if jobClass_row : jobClass = jobClass_row[0] else : jobClass = None def user_init_func(row): if len(row['name'])==0: return None group_row = db_session.query(Group.groupId).filter(Group.companyId==companyId).filter(Group.name==row['groupName']).first() if group_row: groupId = group_row[0] elif len(row['groupName']) > 0 : newGroup = Group(companyId, row['groupName']) db_session.add(newGroup) try: db_session.commit() except exc.IntegrityError as e: db_session.rollback() if(newGroup.groupId==None): return None else: groupId = newGroup.groupId else : groupId = None # companyId, jobClass, groupId, email, accessKey, name, gender, birth, jobType, workYear, workMonth, jobTitle, jobTitleNo u = User(companyId, jobClass, groupId, row['email'], row['accessKey'], row['name'], row['gender'], row['birth'], row['jobType'], row['workYear'], row['workMonth'], row['jobTitle'], row['jobTitleNo']) return u request.save_book_to_database(field_name='file', session=db_session, tables=[User], initializers=[user_init_func]) return jsonify({"code":200, "result":"saved"})
def index(self): if request.method == 'POST': select_game_name = request.form.get('game_select') from app.models import Game, Hero, Quotation from app import db def hero_init_func(row): g = Game.query.filter_by(name=select_game_name).first() hero_name = row.get('name') if g is not None and hero_name is not None: hero = Hero(name=hero_name, game_id=g.id) return hero return None def quotation_init_func(row): hero = Hero.query.filter_by(name=row.get('hero_name')).first() q_content = row.get('content') q_audio_url = row.get('audio_url', '') if hero is not None and q_content is not None: quotation = Quotation(content=q_content, audio_url=q_audio_url, hero_id=hero.id) return quotation return None request.save_book_to_database( field_name='file', session=db.session, tables=[Hero, Quotation], initializers=[hero_init_func, quotation_init_func]) flash(u'导入成功!', 'success') return redirect(url_for('manage.index')) else: from app.models import Game options = [] games = Game.query.all() if games: for game in games: options.append(game.name) return self.render('admin/manage.html', options=options)
def import_speakerlist(): importForm = ImportForm() if importForm.validate_on_submit(): #CheckResult.query.delete() def speaker_init_func(row): c1 = Speakers() c1.brand = row['brand '] c1.area = row['area '] c1.code = row['code '] c1.flag_1 = row['flag_1 '] c1.username = row['username '] c1.speaker_name = row['speaker_name '] c1.speaker_level = row['speaker_level '] c1.city = row['city '] c1.zip_code = row['zip_code '] c1.hospital_name = row['hospital_name '] c1.section_office = row['section_office '] c1.speaker_name2 = row['speaker_name2 '] c1.flag_2 = row['flag_2 '] c1.mobile_phone = row['mobile_phone '] c1.identify_number = row['identify_number '] c1.bank_information = row['bank_information '] c1.bank_city = row['bank_city '] c1.account_code = row['account_code '] c1.address = row['address '] c1.bank_code = row['bank_code '] c1.deal_date = row['deal_date'] c1.remark = row['remark'] c1.id_type = row['id_type'] return c1 request.save_book_to_database(field_name='filespeakerlist', session=db.session, tables=[Speakers], initializers=[speaker_init_func]) flash('导入成功', 'success') return redirect(url_for('task.speaker_list')) return render_template('task/import_speakerlist.html', form=importForm)
def import_equipment(): if request.method == 'POST': def equipment_init_func(row): c = Equipment() c.category_id = row['category_id'] c.label_id = row['label_id'] c.service_id = row['service_id'] c.model = row['model'] c.serial = row['serial'] c.name = row['name'] c.arrived_at = row['arrived_at'] c.description = row['description'] c.created_at = datetime.utcnow() c.created_by = current_user.id return c request.save_book_to_database(field_name='file', session=db.session, tables=[Equipment], initializers=[equipment_init_func]) return redirect(url_for('home.equipment'), code=302) return render_template('home/equipment/import.html', equipment=equipment)
def import_data(): if request.method == 'POST': # if request.form.get('is_delete') is True: Patient.query.delete() def patient_init_func(row): p = Patient(age=row['age'], bio_code=row['bio_code'], birthday=row['birthday'], clinical_data=row['clinical_data'], code=row['code'], id=row['id'], order_id=row['order_id'], origin_id=row['origin_id'], sexe=row['sexe']) return p request.save_book_to_database(field_name='file', session=db.session, tables=[Patient], initializers=[patient_init_func]) return redirect(url_for('.index')) return render_template('patient/import.html')
def doimport(): if request.method == 'POST': def category_init(row): category = Category() num = Category.query.filter_by(name=row['Nom']).count() if num > 0: Category.query.delete() category.name = row['Nom'] category.description = row['Description'] return category def study_init(row): study = Study() num = Study.query.filter_by(name=row['Nom']).count() if num > 0: Study.query.delete() study.name = row['Nom'] study.description = row['Description'] return study def subject_init(row): subject = Subject() num = Subject.query.filter_by(name=row['Nom']).count() if num > 0: Subject.query.delete() study = Study.query.filter_by(name=row['Etude']).first() subject.name = row['Nom'] subject.description = row['Description'] subject.study = study return subject def program_init(row): program = Program() num = Program.query.filter_by(name=row['Nom']).count() if num > 0: Program.query.delete() subject = Subject.query.filter_by(name=row['Thematique']).first() program.name = row['Nom'] program.description = row['Description'] program.subject = subject return program def origin_init(row): origin = Origin() num = Origin.query.filter_by(name=row['Nom']).count() if num > 0: Origin.query.delete() origin.name = row['Nom'] origin.siggle = row['Siggle'] origin.description = row['Description'] return origin def sample_nature_init(row): sample_nature = SampleNature() num = SampleNature.query.filter_by(name=row['Nom']).count() if num > 0: SampleNature.query.delete() sample_nature.name = row['Nom'] sample_nature.siggle = row['Siggle'] sample_nature.description = row['Description'] return sample_nature def sample_type_init(row): sample_type = SampleType() num = SampleType.query.filter_by(name=row['Nom']).count() if num > 0: SampleType.query.delete() sample_type.name = row['Nom'] sample_type.siggle = row['Siggle'] sample_type.description = row['Description'] return sample_type def mesure_init(row): mesure = Mesure() num = Mesure.query.filter_by(name=row['Nom']).count() if num > 0: Mesure.query.delete() mesure.name = row['Nom'] mesure.siggle = row['Siggle'] mesure.description = row['Description'] return mesure def jonc_type_init(row): jonc_type = JoncType() num = JoncType.query.filter_by(name=row['Nom']).count() if num > 0: JoncType.query.delete() jonc_type.name = row['Nom'] jonc_type.siggle = row['Siggle'] jonc_type.description = row['Description'] return jonc_type def support_init(row): support = Support() num = Support.query.filter_by(name=row['Nom']).count() if num > 0: Support.query.delete() support.name = row['Nom'] support.volume = row['Volume'] support.siggle = row['Siggle'] support.description = row['Description'] return support def temperature_init(row): temperature = Temperature() num = Temperature.query.filter_by(name=row['Nom']).count() if num > 0: Temperature.query.delete() temperature.id = row['Id'] temperature.name = row['Nom'] return temperature def equipment_type_init(row): equipment_type = EquipmentType() num = EquipmentType.query.filter_by(name=row['Nom']).count() if num > 0: EquipmentType.query.delete() equipment_type.name = row['Nom'] equipment_type.description = row['Description'] return equipment_type def box_type_init(row): box_type = BoxType() num = BoxType.query.filter_by(name=row['Nom']).count() if num > 0: BoxType.query.delete() box_type.name = row['Nom'] box_type.max_number = row['Espace total'] box_type.description = row['Description'] return box_type def room_init(row): room = Room() num = Room.query.filter_by(name=row['Nom']).count() if num > 0: Room.query.delete() room.name = row['Nom'] room.max_number = row['Espace total'] room.description = row['Description'] return room def equipment_init(row): equipment = Equipment() num = Equipment.query.filter_by(name=row['Nom']).count() if num > 0: Equipment.query.delete() room = Room.query.filter_by(name=row['Salle']).first() equipment_type = EquipmentType.query.filter_by(name=row['Type Equipement']).first() equipment.room = room equipment.equipment_type = equipment_type equipment.name = row['Nom'] equipment.horizontal = row['Horizontale'] equipment.vertical = row['Verticale'] equipment.status = 0 print(row['Nom']) equipment.max_number = int(equipment.horizontal) * int(equipment.vertical) equipment.description = row['Description'] return equipment def rack_init(row): rack = Rack() num = Rack.query.filter_by(name=row['Nom']).count() if num > 0: Rack.query.delete() equipment = Equipment.query.filter_by(name=row['Equipement']).first() rack.equipment = equipment rack.name = row['Nom'] rack.horizontal = row['Horizontale'] rack.vertical = row['Verticale'] rack.status = 0 rack.max_number = int(rack.horizontal) * int(rack.vertical) rack.description = row['Description'] return rack def box_init(row): box = Box() num = Box.query.filter_by(name=row['Nom']).count() if num > 0: Box.query.delete() rack = Rack.query.filter_by(name=row['Rack']).first() box_type = BoxType.query.filter_by(name=row['Type Boite']).first() box.box_type = box_type box.rack = rack box.name = row['Nom'] box.horizontal = row['Horizontale'] box.vertical = row['Verticale'] box.status = 0 box.max_number = int(box.horizontal) * int(box.vertical) box.description = row['Description'] return rack def customer_init(row): category = Category.query.filter_by(name=row['Categorie']).first() customer = Customer() customer.id = row['Id'] customer.category = category customer.display_as = row['Raison Sociale'] customer.firstname = row['Nom'] customer.lastname = row['Prénoms'] customer.adresse = row['Adresse'] customer.telephone = row['Téléphone'] customer.email = row['Email'] return customer def project_init(row): c = Project.query.filter_by(name=row['Categorie']).first() customer = Customer() customer.id = row['Id'] customer.category = c customer.display_as = row['Raison Sociale'] customer.firstname = row['Nom'] customer.lastname = row['Prénoms'] customer.adresse = row['Adresse'] customer.telephone = row['Téléphone'] customer.email = row['Email'] return customer request.save_book_to_database( field_name='file', session=db.session, tables=[Category, Study, Subject, Program, Origin, SampleNature, SampleType, Mesure, JoncType, Support, Temperature, EquipmentType, BoxType, Room, Equipment, Rack, Box], initializers=[category_init, study_init, subject_init, program_init, origin_init, sample_nature_init, sample_type_init, mesure_init, jonc_type_init, support_init, temperature_init, equipment_type_init, box_type_init, room_init, equipment_init, rack_init, box_init]) flash(_('Initialisation terminé avec succèss.')) return redirect(url_for('main.index')) return render_template('setup/import.html')
def doimport(): #get query param campus = request.args.get('campus', 1, type=int) if campus == 1: campus = "libingroad" else: campus = "huankeroad" if request.method == 'POST': #first delete all bus and stations if (campus == "libingroad"): print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!') stations = mStation.query.all() for item in stations: print('delete station:'+ str(item.name)) db.session.delete(item) db.session.commit() buses = mBus.query.all() for item in buses: print('delete bus:'+ str(item.name)) db.session.delete(item) db.session.commit() def mbus_init_func(row): #input check if row['名称'] == "" or row['名称'] is None \ or row['编号']=="" or row['编号'] is None: return None b = mBus.query.filter_by(name=row['名称'], number=row['编号']).first() if b is not None: b.name = row['名称'] b.number = row['编号'] b.cz_name = row['车长'] b.cz_phone = row['车长手机'] b.sj_name = row['司机'] b.sj_phone = row['司机手机'] b.seat_num = row['座位数'] b.campus = campus else: b = mBus(name=row['名称'], number=row['编号'], cz_name=row['车长'], cz_phone=row['车长手机'], sj_name=row['司机'],sj_phone=row['司机手机'], seat_num=row['座位数'], campus=campus) return b def station_init_func(row): s = None #input check if row['站点'] == "" or row['站点'] is None or \ row['计划发车时间']=="" or row['计划发车时间'] is None: return None print('station:'+row['站点']) if row['站点描述'] is not None: print('desc: '+row['站点描述']) timestr = str(row['计划发车时间']) datetimeobj = datetime.strptime(timestr.strip(), '%H:%M:%S').time() latlon = row['站点经纬度信息'] lat = None lon = None direction = row['direction'] if latlon is not "" and latlon is not None: lon = latlon.strip().split(',')[0] if lon is not None: lon = float(lon) lat = latlon.strip().split(',')[1] if lat is not None: lat = float(lat) #transfer from google coordinate to baidu from ..gpsutil import gcj02tobd09 lon, lat = gcj02tobd09(lon, lat) else: lat = 0.0 lon = 0.0 b = mBus.query.filter_by(name=row['名称'], number=row['编号']).first() if b is not None: s = mStation.query.filter_by(name=row['站点'], bus_id=b.id, dirtocompany=direction).first() if s is not None: s.name = row['站点'] s.description = row['站点描述'] s.time = datetimeobj s.dirtocompany = True s.lat = lat s.lon = lon s.campus = campus s.bus_id = b.id s.dirtocompany = direction else: s = mStation(name=row['站点'], description=row['站点描述'], time=datetimeobj, dirtocompany=direction, lat=lat, lon=lon, campus=campus, bus_id=b.id) return s request.save_book_to_database( field_name='file', session=db.session, tables=[mBus, mStation], initializers=[mbus_init_func, station_init_func]) return redirect(url_for('.doimport'), code=302) return '''
def import_in(): if request.method == 'POST': def level_init(row): l = Level() num = Level.query.filter_by(name=row['Nom']).count() if num == 0: l.name = row['Nom'] l.description = row['Description'] return l def spinneret_init(row): s = Spinneret() num = Spinneret.query.filter_by(name=row['Nom']).count() if num == 0: s.name = row['Nom'] s.description = row['Description'] return s def department_init(row): s = Department() num = Department.query.filter_by(name=row['Nom']).count() print(str(num)) if num == 0: s.name = row['Nom'] s.description = row['Description'] return s def unit_init(row): s = Unit() num = Unit.query.filter_by(name=row['Nom']).count() if num == 0: s.name = row['Nom'] s.description = row['Description'] d = Department.query.filter_by(name=row['Departement']).first() s.departement_id = d.id return s def trainee_init(row): c = Trainee() c.image_filename = 'default.png' c.image_url = os.path.join('', '/static/img/default.png') c.registration_number = row['Numero'] c.first_name = row['Nom'] c.last_name = row['Prenoms'] l = Level.query.filter_by(name=row['Niveau']).first() c.level_id = l.id u = Unit.query.filter_by(name=row['Unite']).first() c.unit_id = u.id s = Spinneret.query.filter_by(name=row['Filiere']).first() c.spinneret_id = s.id c.school = row['Etablissement'] c.email = row['Email'] c.phone = row['Telephone'] c.birthdate = row['Date de naissance'] c.diplome = row['Diplome'] c.theme = row['Theme'] return c request.save_book_to_database( field_name='file', session=db.session, tables=[Department, Unit, Spinneret, Level, Trainee], initializers=[ department_init, unit_init, spinneret_init, level_init, trainee_init ]) return redirect(url_for('trainee.list')) return render_template('trainee/import.html', trainee=trainee)