def circuits(): providers = Provider.query.all() choices = [(p.id, p.name) for p in providers] form = AddCircuitForm() form.provider.choices = choices if form.validate_on_submit(): filename = documents.save(request.files['circuit_contract']) circuit = Circuit( provider_cid=form.provider_cid.data, a_side=form.a_side.data, z_side=form.z_side.data, provider_id=form.provider.data, contract_filename=filename, ) db.session.add(circuit) db.session.commit() flash('circuit added successfully!') return redirect(url_for('main.circuits')) page = request.args.get('page', 1, type=int) circuits = Circuit.query.paginate(page, current_app.config['POSTS_PER_PAGE'], False) next_url = (url_for('main.circuits', page=circuits.next_num) if circuits.has_next else None) prev_url = (url_for('main.circuits', page=circuits.prev_num) if circuits.has_prev else None) return render_template( 'circuits.html', title='circuits', form=form, circuits=circuits.items, next_url=next_url, prev_url=prev_url, )
def add(project_id=0): project = None form = OrderForm() if project_id != 0: project = Project.query.get(project_id) form.customer.data = project.customer_id form.project.data = project.id form.customer.choices = [(c.id, c.display_as) for c in Customer.query.all()] form.project.choices = [(c.id, c.title) for c in Project.query.all()] form.temperature.choices = [(c.id, c.name) for c in Temperature.query.all()] if form.validate_on_submit(): order = Order() if 'file' in request.files: file = request.files['file'] order.file_name = documents.save(file) order.file_url = documents.url(order.file_name) order.serial = get_order_code() order.project_id = form.project.data order.first_name = form.first_name.data order.last_name = form.last_name.data order.telephone = form.telephone.data order.receive_date = form.receive_date.data order.send_date = form.send_date.data order.temperature_id = form.temperature.data order.nbr_pack = form.nbr_pack.data order.timestamp = datetime.utcnow() order.user_id = current_user.id order.status = 0 db.session.add(order) db.session.commit() flash(_('Informations du dépôt enregistrées!')) return redirect(url_for('order.detail', id=order.id)) return render_template('order/form.html', form=form, project=project)
def add_research(): """ Add a research to the database """ check_inventor() add_research = True form = ResearchForm() if form.validate_on_submit(): fil = documents.save(request.files['doc_file']) fil_url = documents.url(fil) user = current_user.id research = Research(name=form.name.data, category=form.category.data, user_id=user, details=form.details.data, file_name=fil, file_url=fil_url, date=datetime.datetime.utcnow()) try: # add research to the database db.session.add(research) db.session.commit() flash('You have successfully added a new research.') except: # in case research name already exists flash('Error: project title name already exists.') # redirect to researchs page return redirect(url_for('inventor.list_researchs')) # load research template return render_template('inventor/researchs/research.html', action="Add", add_research=add_research, form=form, title="Add Research")
def edit(id): order = Order.query.get(id) form = OrderForm(obj=order) form.customer.choices = [(c.id, c.display_as) for c in Customer.query.all()] form.project.choices = [(c.id, c.title) for c in Project.query.all()] form.temperature.choices = [(c.id, c.name) for c in Temperature.query.all()] if form.validate_on_submit(): if 'file' in request.files: file = request.files['file'] order.file_name = documents.save(file) order.file_url = documents.url(order.file_name) order.customer_id = form.project.data order.project_id = form.project.data order.first_name = form.first_name.data order.last_name = form.last_name.data order.telephone = form.telephone.data order.send_date = form.send_date.data order.temperature_id = form.temperature.data order.nbr_pack = form.nbr_pack.data db.session.commit() flash(_('Modification effectuée avec succèss!!')) return redirect(url_for('order.detail', id=order.id)) form.customer.data = order.project.customer.id form.project.data = order.project_id form.first_name.data = order.first_name form.last_name.data = order.last_name form.telephone.data = order.telephone form.send_date.data = order.send_date form.receive_date.data = order.receive_date form.nbr_pack.data = order.nbr_pack form.temperature.data = order.temperature_id return render_template('order/form.html', form=form)
def circuit_detail(circuit_id): circuit = Circuit.query.filter_by(id=circuit_id).first_or_404() providers = Provider.query.all() choices = [(p.id, p.name) for p in providers] form = EditCircuitForm() form.provider.choices = choices if form.validate_on_submit(): if request.files.get('circuit_contract'): filename = documents.save(request.files['circuit_contract']) circuit.contract_filename = filename circuit.a_side = form.a_side.data circuit.z_side = form.z_side.data circuit.provider_id = form.provider.data db.session.add(circuit) db.session.commit() flash('circuit updated successfully!') return redirect(url_for('main.circuit_detail', circuit_id=circuit_id)) page = request.args.get('page', 1, type=int) maints = (MaintCircuit.query.filter_by(circuit_id=circuit_id).order_by( desc(MaintCircuit.date)).paginate(page, current_app.config['POSTS_PER_PAGE'], False)) next_url = (url_for('main.circuit_detail', page=maints.next_num, circuit_id=circuit_id) if maints.has_next else None) prev_url = (url_for('main.circuit_detail', page=maints.prev_num, circuit_id=circuit_id) if maints.has_prev else None) return render_template( 'circuit_detail.html', circuit=circuit, maints=maints.items, next_url=next_url, prev_url=prev_url, form=form, )
def do_import(id): order = Order.query.get(id) if request.method == 'POST': file = request.files['file'] filename = documents.save(file) data_xls = pd.read_excel(file) for index, row in data_xls.iterrows(): # one patient have samples that have results # check patient number first if exist in db per row patient = Patient() patient_count = Patient.query.filter_by(code=row[0]).count() if patient_count > 0: sample_count = Sample.query.filter_by(code=row[7]).count() if sample_count > 0: # add new resltuts print(row[0] + ' ' + str(index)) else: sample = Sample() sample.bio_code = patient.bio_code sample.volume = row[16] sample_nature = SampleNature.query.filter_by( name=row[8]).first() sample.sample_nature_id = sample_nature.id sample_type = SampleType.query.filter_by( name=row[9]).first() sample.sample_type_id = sample_type.id support = Support.query.filter_by(name=row[13]).first() sample.support_id = support.id jonc_type = JoncType.query.filter_by(name=row[14]).first() sample.jonc_type_id = jonc_type.id mesure = Mesure.query.filter_by(name=row[17]).first() sample.mesure_id = mesure.id sample.code = row[7] sample.date = str(row[10]) sample.technique = row[11] sample.site = row[12] sample.status = 0 patient.samples.append(sample) order.patients.append(patient) db.session.commit() generateCode(sample, r + 1) else: # add new patient and samples and result of sample print(row[4] + ' ' + str(index)) patient.code = row[0] patient.origin_id = 1 patient.bio_code = get_bio_code('HU') patient.age = row[1] patient.sexe = row[2] patient.birthday = str(row[3]) patient.city = row[4] patient.job = row[5] patient.clinical_data = row[6] # samples implementation for r in range(int(row[15])): sample = Sample() sample.bio_code = patient.bio_code sample.volume = row[16] sample_nature = SampleNature.query.filter_by( name=row[8]).first() sample.sample_nature_id = sample_nature.id sample_type = SampleType.query.filter_by( name=row[9]).first() sample.sample_type_id = sample_type.id support = Support.query.filter_by(name=row[13]).first() sample.support_id = support.id jonc_type = JoncType.query.filter_by(name=row[14]).first() sample.jonc_type_id = jonc_type.id mesure = Mesure.query.filter_by(name=row[17]).first() sample.mesure_id = mesure.id sample.code = row[7] sample.date = str(row[10]) sample.technique = row[11] sample.site = row[12] sample.status = 0 patient.samples.append(sample) generateCode(sample, r + 1) print(str(sample.bio_code)) order.patients.append(patient) db.session.commit() # and check sample id if already in db url = documents.url(filename) document = Document(name=filename, url=url) order.documents.append(document) db.session.add(document) db.session.commit() flash(_('Fichier importé avec succes!')) return redirect(url_for('order.detail', id=order.id)) return render_template('order/import.html', order=order)