def new_invoice_excel(): excel_file = request.get_dict(field_name='invoice_file') samsung_keys = ( 'Shipped Parts', 'Qty', 'Amount', 'Delivery No', 'P/O No', 'Description', 'Tracking No', ) # Check for valid Samsung invoice format if all(k in excel_file for k in samsung_keys): invoice_number = excel_file['Delivery No'][0] if Invoice.query.get(invoice_number): flash('This invoice already exists', 'alert-danger') return redirect(url_for('invoices')) invoice = Invoice(invoice_number=invoice_number) for idx, part_number in enumerate(excel_file['Shipped Parts']): qty = int(excel_file['Qty'][idx]) purchase_order_number = excel_file['P/O No'][idx] description = excel_file['Description'][idx].strip() price = float(excel_file['Amount'][idx]) / qty part = Part.get_or_create(part_number, db.session) part.description = description part.price = price for _ in range(qty): invoice_detail = InvoiceDetail( invoice_number=invoice_number, purchase_order_number=purchase_order_number, ) invoice_detail.part = part invoice.parts.append(invoice_detail) db.session.add(invoice) db.session.commit() flash('Imported excel file successfully', 'alert-success') else: flash('Invalid file, try again', 'alert-danger') return redirect(url_for('invoices'))
def cached(): override = {'override': 'data'} # not cached yet self.assertFalse(hasattr(request, '_cached_dict')) # calling get_dict caches result result1 = request.get_dict() self.assertTrue(hasattr(request, '_cached_dict')) self.assertNotEqual(result1, override) self.assertNotEqual(request._cached_dict, override) # override cache request._cached_dict = override result2 = request.get_dict() # results are pulled from cache self.assertEqual(result2, override) return result2
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')
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})
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")
def index(): return {'data': request.get_dict(), 'params': request.args}
def session_post(): auth.login(request.get_dict()['user_id']) return ''
def index(): return request.get_dict()
def process(): data_dict = request.get_dict(field_name='file') df = pd.DataFrame.from_dict(data_dict) return jsonify({'data': df.to_json(orient="records")})
def test(): data_dict = request.get_dict(field_name='file') df = pd.DataFrame.from_dict(data_dict) print(df.head(10)) test = brain.make_prediction(df) return jsonify({'data': test})
def excel_parse(): file = request.files['file'] if file: return dict(request.get_dict(field_name='file'))