def list_all(request): menu_texts = FrontendTexts('menu') try: backend_host = MachineConfigurator().getBackend() r = requests.get(backend_host + '/auth/providers/') backend_message = BackendMessage(json.loads(r.text)) providers_list = json.loads(backend_message.getValue()) paginator = Paginator(providers_list, 10) # Show 25 contacts per page page = request.GET.get('page') contacts = paginator.get_page(page) return render(request, 'providers/list_all.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'contacts': contacts}) except ValueError as exception: print("There is a problem with the backend return value") print(exception) return render(request, 'providers/list_all.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend problem', }) except ConnectionError as exception: print("Backend connection problem") print(exception) return render(request, 'providers/list_all.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', }) except Exception as exception: print(exception) return render(request, 'providers/list_all.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'System error', })
def rfq_material_reload(request, code): menu_texts = FrontendTexts('menu') instructions = Instructions('rfqs', 'reload') try: backend_host = MachineConfigurator().getBackend() r = requests.put(backend_host + '/auth/rfqs/reload/' + code, json={}) backend_message = BackendMessage(json.loads(r.text)) backend_result = json.loads(backend_message.getValue()) return render(request, 'rfqs/rfq_material_reload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'updated_materials': backend_result}) except ValueError as exception: print("There is a problem with the backend return value") print(exception) return render(request, 'rfqs/rfq_material_reload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'No such RFQ exists in the DB: ' + code, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()}) except ConnectionError as exception: print("Backend connection problem") print(exception) return render(request, 'rfqs/rfq_material_reload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()}) except Exception as exception: print(exception) return render(request, 'rfqs/rfq_material_reload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'System error', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()})
def quoted_materials_editor(request, code): menu_texts = FrontendTexts('menu') instructions = Instructions('quotes', 'edit') try: backend_host = MachineConfigurator().getBackend() r = requests.post(backend_host + '/auth/quotes/materials/' + code) backend_message = BackendMessage(json.loads(r.text)) quoted_materials_data = json.loads(backend_message.getValue()) quoted_material_form = QuotedMaterialForm(initial=quoted_materials_data) if request.method == 'POST': quoted_material_form = QuotedMaterialForm(request.POST) if quoted_material_form.is_valid(): # ... update current material with the data provided # ... send data to backend creator = QuoteCreator() result = creator.editQuotedMaterials(quoted_material_form, quoted_materials_data) result_json = [] for quote in result: result_json.append(json.dumps(quote)) r = requests.put(backend_host + '/auth/quotes/materials/' + code, json=result) backend_message = BackendMessage(json.loads(r.text)) backend_result = json.loads(backend_message.getValue()) return render(request, 'quotes/materials_editor.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'updated_materials': backend_result}) else: print("Invalid form") return render(request, 'quotes/materials_editor.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'quote_form': quoted_material_form, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()}) except ValueError as exception: print("There is a problem with the backend return value") print(exception) return render(request, 'quotes/materials_editor.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'No such quoted material exists ' + 'in the DB: ' + code, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()}) except ConnectionError as exception: print("Backend connection problem") print(exception) return render(request, 'quotes/materials_editor.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()}) except Exception as exception: print(exception) return render(request, 'quotes/materials_editor.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'System error', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()})
def quotes_upload(request): menu_texts = FrontendTexts('menu') instructions = Instructions('quotes', 'upload') uploaded_file_url = '' try: form = QuotesForm() if request.method == 'POST': form = QuotesForm(request.POST, request.FILES) if form.is_valid(): quote = QuoteCreator() internal_code = form.cleaned_data['internalCode'] external_code = form.cleaned_data['externalCode'] provider_code = form.cleaned_data['providerCode'] received_date = form.cleaned_data['receivedDate'] sent_date = form.cleaned_data['sentDate'] user = form.cleaned_data['user'] provider_id = form.cleaned_data['providerId'] provider_name = form.cleaned_data['providerName'] contact_name = form.cleaned_data['contactName'] incoterms = form.cleaned_data['incoterms'] note = form.cleaned_data['note'] edt = form.cleaned_data['edt'] quote.setQuoteInformation(internal_code, external_code, provider_code, provider_id, provider_name, contact_name, received_date, sent_date, user, edt) quote.setQuoteIncoterms(incoterms) quote.setQuoteNote(note) myfile = request.FILES['document'] fs = FileSystemStorage() filename = fs.save(myfile.name, myfile) uploaded_file_url = fs.url(filename) result = quote.createQuotefromCSV('.' + uploaded_file_url) # ... print(json.dumps(result)) backend_host = MachineConfigurator().getBackend() r = requests.post(backend_host + '/auth/quotes/', json=result) backend_message = BackendMessage(json.loads(r.text)) cleanup(uploaded_file_url) backend_result = [] if backend_message.errorInd: display_message = {} display_message['internalCode'] = internal_code display_message['externalCode'] = external_code display_message['status'] = backend_message.getValue() backend_result.append(display_message) else: backend_result = json.loads(backend_message.getValue()) return render(request, 'quotes/quote_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'upload_result': backend_result}) return render(request, 'quotes/quote_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'form': form, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()}) except ValueError as exception: cleanup(uploaded_file_url) print("There is a problem with the backend return value") print(exception) return render(request, 'quotes/quote_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ConnectionError as exception: cleanup(uploaded_file_url) print("Backend connection problem") print(exception) return render(request, 'quotes/quote_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except Exception as exception: cleanup(uploaded_file_url) print(exception) return render(request, 'quotes/quote_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'General problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() })
def quoted_materials_upload(request): menu_texts = FrontendTexts('menu') instructions = Instructions('quotes', 'materials_upload') uploaded_file_url = '' try: if request.method == 'POST': form = QuotedMaterialsForm(request.POST, request.FILES) if form.is_valid(): data = ExtQuotedMaterialCreator() providerId = form.cleaned_data['providerId'] providerName = form.cleaned_data['providerName'] revision = form.cleaned_data['revision'] data.setExtendedInformation(providerId, providerName, revision) my_file = request.FILES['document'] fs = FileSystemStorage() filename = fs.save(my_file.name, my_file) uploaded_file_url = fs.url(filename) result = data.createExtQuotedMaterialsfromCSV('.' + uploaded_file_url) # print(json.dumps(result)) backend_host = MachineConfigurator().getBackend() r = requests.post(backend_host + '/auth/quotes/materials', json=result) backend_message = BackendMessage(json.loads(r.text)) cleanup(uploaded_file_url) backend_result = [] if backend_message.errorInd: display_message = {} display_message['itemcode'] = "-" display_message['revision'] = "-" display_message['status'] = "-" backend_result.append(display_message) else: backend_result = json.loads(backend_message.getValue()) return render(request, 'quotes/materials_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'upload_result': backend_result}) else: form = QuotedMaterialsForm() return render(request, 'quotes/materials_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'form': form, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ValueError as exception: cleanup(uploaded_file_url) print("There is a problem with the backend return value") print(exception) return render(request, 'quotes/materials_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ConnectionError as exception: cleanup(uploaded_file_url) print("There is a problem with the backend return value") print(exception) return render(request, 'quotes/materials_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except Exception as exception: cleanup(uploaded_file_url) print(exception) return render(request, 'quotes/materials_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': "Frontend Error", 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() })
def material_weight(request, code): menu_texts = FrontendTexts('menu') instructions = Instructions('materials', 'weightcalc') try: backend_host = MachineConfigurator().getBackend() quantity_form = WeightCalculatorForm(request.POST) if request.method == 'POST': if quantity_form.is_valid(): # ... update current material with the data provided value = quantity_form.cleaned_data['value'] units = UNIT_CHOICES[int(quantity_form.cleaned_data['units']) - 1][1] result = {'quantity': value, 'units': units} r = requests.post(backend_host + '/auth/materials/weights/' + code, json=result) backend_message = BackendMessage(json.loads(r.text)) backend_result = json.loads(backend_message.getValue()) return render( request, 'materials/material_weight.html', { 'menu_text': menu_texts.getComponent(), 'weight_materials': backend_result }) return render( request, 'materials/material_weight.html', { 'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'quantity_form': quantity_form, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ConnectionError as exception: print("Backend connection problem") print(exception) return render( request, 'materials/material_weight.html', { 'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except Exception as exception: print(exception) return render( request, 'materials/material_weight.html', { 'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'System error', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() })
def simple_upload(request): menu_texts = FrontendTexts('menu') instructions = Instructions('materials', 'upload') uploaded_file_url = '' try: if request.method == 'POST' and request.FILES['myfile']: myfile = request.FILES['myfile'] fs = FileSystemStorage() filename = fs.save(myfile.name, myfile) uploaded_file_url = fs.url(filename) # ... do here the magic creator = MaterialCreator() result = creator.createMaterialfromCSV('.' + uploaded_file_url) result_json = [] for material in result: result_json.append(json.dumps(material)) backend_host = MachineConfigurator().getBackend() r = requests.post(backend_host + '/auth/materials/', json=result) backend_message = BackendMessage(json.loads(r.text)) backend_result = json.loads(backend_message.getValue()) cleanup(uploaded_file_url) return render( request, 'materials/simple_upload.html', { 'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'uploaded_materials': backend_result }) return render( request, 'materials/simple_upload.html', { 'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except MultiValueDictKeyError as exception: print("No file selected") print(exception) return render( request, 'materials/simple_upload.html', { 'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'No file selected', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except UnicodeDecodeError as exception: print( "There is a problem with the input file - unicode decoding error") print(exception) cleanup(uploaded_file_url) return render( request, 'materials/simple_upload.html', { 'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Cannot read file correctly', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ValueError as exception: print("There is a problem with the backend return value") print(exception) cleanup(uploaded_file_url) return render( request, 'materials/simple_upload.html', { 'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ConnectionError as exception: cleanup(uploaded_file_url) print("Backend connection problem") print(exception) return render( request, 'materials/simple_upload.html', { 'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except Exception as exception: print(exception) cleanup(uploaded_file_url) return render( request, 'materials/simple_upload.html', { 'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'System error', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() })
def singlexcheck(request): menu_texts = FrontendTexts('menu') instructions = Instructions('materials', 'singlexcheck') try: if request.method == 'POST': form = xcheckForm(request.POST) if form.is_valid(): itemcode = form.cleaned_data['itemcode'] backend_host = MachineConfigurator().getBackend() r = requests.post(backend_host + '/auth/materials/xcheck/' + itemcode) backend_message = BackendMessage(json.loads(r.text)) backend_result = json.loads(backend_message.getValue()) return render( request, 'materials/singlexcheck.html', { 'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'uploaded_materials': backend_result }) else: form = xcheckForm() return render( request, 'materials/singlexcheck.html', { 'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'xform': form, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ValueError as exception: print("There is a problem with the backend return value") print(exception) return render( request, 'materials/singlexcheck.html', { 'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ConnectionError as exception: print("Backend connection problem") print(exception) return render( request, 'materials/singlexcheck.html', { 'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except Exception as exception: print(exception) return render( request, 'materials/singlexcheck.html', { 'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'System error', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() })
def rfq_basic_analyzer(request, code): menu_texts = FrontendTexts('menu') instructions = Instructions('rfqs', 'analyze') output_file = '' try: backend_host = MachineConfigurator().getBackend() r = requests.get(backend_host + '/auth/rfqs/analysis/' + code) backend_message = BackendMessage(json.loads(r.text)) print(backend_message.getErrorInd()) if not backend_message.getErrorInd(): rfq = json.loads(backend_message.getValue()) rfq_service = RFQCreator() output_file = rfq_service.runBasicAnalysis(rfq) if os.path.exists(output_file): with open(output_file, 'rb') as fh: response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel") cleanup('/' + output_file) response['Content-Disposition'] = 'inline; filename=' + os.path.basename(output_file) return response raise Http404 return render(request, 'rfqs/rfq_basic_analysis.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend problem - cannot create file', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()}) except ValueError as exception: print("There is a problem with the backend return value") print(exception) return render(request, 'rfqs/rfq_basic_analysis.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ConnectionError as exception: print("There is a problem with the backend return value") print(exception) return render(request, 'rfqs/rfq_basic_analysis.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except Exception as exception: cleanup(output_file) print(exception) return render(request, 'rfqs/rfq_basic_analysis.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': "Frontend Error", 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() })
def rfq_upload(request): menu_texts = FrontendTexts('menu') instructions = Instructions('rfqs', 'upload') uploaded_file_url = '' try: if request.method == 'POST': form = RFQForm(request.POST, request.FILES) if form.is_valid(): rfq = RFQCreator() internal_code = form.cleaned_data['internalCode'] external_code = form.cleaned_data['externalCode'] sender = form.cleaned_data['sender'] company = form.cleaned_data['company'] received_date = form.cleaned_data['receivedDate'] note = form.cleaned_data['note'] rfq.setRFQInformation(internal_code, external_code, sender, company, received_date) rfq.addRFQNote(note) myfile = request.FILES['document'] fs = FileSystemStorage() filename = fs.save(myfile.name, myfile) uploaded_file_url = fs.url(filename) result = rfq.createRFQfromCSV('.' + uploaded_file_url) print(json.dumps(result)) backend_host = MachineConfigurator().getBackend() r = requests.post(backend_host + '/auth/rfqs/', json=result) backend_message = BackendMessage(json.loads(r.text)) cleanup(uploaded_file_url) backend_result = [] if backend_message.errorInd: display_message = {} display_message['internalCode'] = internal_code display_message['externalCode'] = external_code display_message['status'] = backend_message.getValue() backend_result.append(display_message) else: backend_result = json.loads(backend_message.getValue()) return render(request, 'rfqs/rfq_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'upload_result': backend_result}) else: form = RFQForm() return render(request, 'rfqs/rfq_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'form': form, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ValueError as exception: cleanup(uploaded_file_url) print("There is a problem with the backend return value") print(exception) return render(request, 'rfqs/rfq_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ConnectionError as exception: cleanup(uploaded_file_url) print("There is a problem with the backend return value") print(exception) return render(request, 'rfqs/rfq_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except Exception as exception: cleanup(uploaded_file_url) print(exception) return render(request, 'rfqs/rfq_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': "Frontend Error", 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() })
def rfq_material_editor(request, code): menu_texts = FrontendTexts('menu') instructions = Instructions('rfqs', 'edit') try: backend_host = MachineConfigurator().getBackend() r = requests.post(backend_host + '/auth/rfqs/' + code) backend_message = BackendMessage(json.loads(r.text)) backend_result = json.loads(backend_message.getValue()) material_data = backend_result['materialList'] rfq_form = RFQFormOnlyinfo(initial=backend_result) MaterialFormSet = formset_factory(ExtMaterialForm, extra=0) materials_formset = MaterialFormSet(initial=material_data) if request.method == 'POST': rfq_form = RFQFormOnlyinfo(request.POST) materials_formset = MaterialFormSet(request.POST) if rfq_form.is_valid() and materials_formset.is_valid(): # ... update current material with the data provided # ... send data to backend creator = RFQCreator() result = creator.editRFQwithMaterials(rfq_form, materials_formset, material_data) result_json = [] for rfq in result: result_json.append(json.dumps(rfq)) r = requests.put(backend_host + '/auth/rfqs/' + code, json=result) backend_message = BackendMessage(json.loads(r.text)) backend_result = json.loads(backend_message.getValue()) return render(request, 'rfqs/rfq_material_editor.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'updated_materials': backend_result}) return render(request, 'rfqs/rfq_material_editor.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'rfq_form': rfq_form, 'materials_formset': materials_formset, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()}) except ValueError as exception: print("There is a problem with the backend return value") print(exception) return render(request, 'rfqs/rfq_material_editor.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'No such RFQ exists in the DB: ' + code, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()}) except ConnectionError as exception: print("Backend connection problem") print(exception) return render(request, 'rfqs/rfq_material_editor.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()}) except Exception as exception: print(exception) return render(request, 'rfqs/rfq_material_editor.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'System error', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()})
def rfq_qfinder(request): menu_texts = FrontendTexts('menu') instructions = Instructions('rfqs', 'qfinder') uploaded_file_url = '' try: if request.method == 'POST' and request.FILES['myfile']: myfile = request.FILES['myfile'] fs = FileSystemStorage() filename = fs.save(myfile.name, myfile) uploaded_file_url = fs.url(filename) rfq = RFQCreator() result = rfq.findQuotesFromCSV('.' + uploaded_file_url) # ... print(json.dumps(result)) backend_host = MachineConfigurator().getBackend() r = requests.post(backend_host + '/auth/rfqs/quotes', json=result) backend_message = BackendMessage(json.loads(r.text)) if not backend_message.getErrorInd(): quoted_materials = json.loads(backend_message.getValue()) cleanup(uploaded_file_url) return render(request, 'rfqs/rfq_qfinder.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'quoted_materials': quoted_materials, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) else: print(backend_message.getValue()) cleanup(uploaded_file_url) return render(request, 'rfqs/rfq_qfinder.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': backend_message.getValue(), 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) return render(request, 'rfqs/rfq_qfinder.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ConnectionError as exception: print("There is a problem with the backend return value") print(exception) return render(request, 'rfqs/rfq_qfinder.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except Exception as exception: cleanup(uploaded_file_url) print(exception) return render(request, 'rfqs/rfq_qfinder.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': "Frontend Error", 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() })
def rfq_export(request): menu_texts = FrontendTexts('menu') instructions = Instructions('rfqs', 'export') output_file = '' try: if request.method == 'POST': form = RFQInternalCode(request.POST) if form.is_valid(): internal_code = form.cleaned_data['internalcode'] incoterms = form.cleaned_data['incoterms'] port = form.cleaned_data['port'] backend_host = MachineConfigurator().getBackend() r = requests.get(backend_host + '/auth/rfqs/' + internal_code) backend_message = BackendMessage(json.loads(r.text)) if not backend_message.getErrorInd(): rfq = json.loads(backend_message.getValue()) rfq_service = RFQCreator() output_file = rfq_service.exportRFQtoCSV(rfq, incoterms, port) if os.path.exists(output_file): with open(output_file, 'rb') as fh: response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel") cleanup('/' + output_file) response['Content-Disposition'] = 'inline; filename=' + os.path.basename(output_file) return response raise Http404 else: print("There is a backend error message") return render(request, 'rfqs/rfq_export.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'rfqform': form, 'error_message': backend_message.getValue(), 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) else: form = RFQInternalCode() return render(request, 'rfqs/rfq_export.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'rfqform': form, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ValueError as exception: print("There is a problem with the backend return value") print(exception) return render(request, 'rfqs/rfq_export.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ConnectionError as exception: print("There is a problem with the backend return value") print(exception) return render(request, 'rfqs/rfq_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except Exception as exception: cleanup(output_file) print(exception) return render(request, 'rfqs/rfq_upload.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': "Frontend Error", 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() })
def provider_comment(request, code): menu_texts = FrontendTexts('menu') instructions = Instructions('providers', 'comment') try: if request.method == 'POST': comment_form = CommentForm(request.POST) if comment_form.is_valid(): # ... update current provider with the data provided backend_host = MachineConfigurator().getBackend() creator = ProviderCreator() result = creator.createComment(comment_form) r = requests.post(backend_host + '/auth/providers/comments/' + code, json=result) backend_message = BackendMessage(json.loads(r.text)) backend_result = json.loads(backend_message.getValue()) return render(request, 'providers/provider_comment.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'updated_providers': backend_result}) form = CommentForm() return render(request, 'providers/provider_comment.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'comment_form': form, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()}) except ValueError as exception: print("There is a problem with the backend return value") print(exception) return render(request, 'providers/provider_comment.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ConnectionError as exception: print("Backend connection problem") print(exception) return render(request, 'providers/provider_comment.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except Exception as exception: print(exception) return render(request, 'providers/provider_comment.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'System error', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() })
def provider_editor(request, code): menu_texts = FrontendTexts('menu') instructions = Instructions('providers', 'edit') try: backend_host = MachineConfigurator().getBackend() r = requests.post(backend_host + '/auth/providers/' + code) backend_message = BackendMessage(json.loads(r.text)) backend_result = json.loads(backend_message.getValue()) provider_form = ProviderForm(initial=backend_result) if request.method == 'POST': provider_form = ProviderForm(request.POST) if provider_form.is_valid(): # ... update current provider with the data provided print(code) creator = ProviderCreator() result = creator.createProvider(provider_form) result_json = [] print(result) for provider in result: result_json.append(json.dumps(provider)) r = requests.put(backend_host + '/auth/providers/' + code, json=result) backend_message = BackendMessage(json.loads(r.text)) backend_result = json.loads(backend_message.getValue()) return render(request, 'providers/provider_editor.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'updated_providers': backend_result}) return render(request, 'providers/provider_editor.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'provider_form': provider_form, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()}) except ValueError as exception: print("There is a problem with the backend return value") print(exception) return render(request, 'providers/provider_editor.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'No such provider exists in the DB: ' + code, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ConnectionError as exception: print("Backend connection problem") print(exception) return render(request, 'providers/provider_editor.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except Exception as exception: print(exception) return render(request, 'providers/provider_editor.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'System error', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() })
def provider_creator(request): menu_texts = FrontendTexts('menu') instructions = Instructions('providers', 'create') try: if request.method == 'POST': form = ProviderForm(request.POST) if form.is_valid(): creator = ProviderCreator() result = creator.createProvider(form) result_json = [] print(result) for provider in result: result_json.append(json.dumps(provider)) backend_host = MachineConfigurator().getBackend() r = requests.post(backend_host + '/auth/providers/', json=result) backend_message = BackendMessage(json.loads(r.text)) backend_result = json.loads(backend_message.getValue()) return render(request, 'providers/provider_creator.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'uploaded_providers': backend_result}) else: form = ProviderForm() return render(request, 'providers/provider_creator.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'providerform': form, 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps()}) except ValueError as exception: print("There is a problem with the backend return value") print(exception) return render(request, 'providers/provider_creator.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except ConnectionError as exception: print("Backend connection problem") print(exception) return render(request, 'providers/provider_creator.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'Backend connection problem', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() }) except Exception as exception: print(exception) return render(request, 'providers/provider_creator.html', {'menu_text': menu_texts.getComponent(), 'view_texts': view_texts.getComponent(), 'error_message': 'System error', 'instructions_title': instructions.getTitle(), 'instructions_steps': instructions.getSteps() })