Best Python code snippet using fMBT_python
views.py
Source:views.py  
1from utils import prescription , blockchain ,x_ray2from django.shortcuts import render,redirect3from .models import Prescriptions ,XRay4from . import forms5from django.core.files.storage import FileSystemStorage6from PIL import Image7import pytesseract8from django.http import HttpResponse , HttpResponseRedirect9from web3 import Web310import json11from django.urls import reverse12from django.contrib.auth.decorators import login_required13import web314# Create your views here.15# contract_address="0x68C7375827709848F649C2996fC806d10D5514d6"16path = "./model.h5"17print("THIS WORKS")18flag1=False19# Create your views here.20@login_required21def record_list(request):22	trial = prescription.Prescription()23	prescriptions = trial.record_list(request)24	return render(request,'prescription/prescription_list.html',{'prescriptions':prescriptions})25@login_required26def upload(request):27	trial = prescription.Prescription()28	form ,pk = trial.upload(request)29	if pk!=-1:30		# return redirect('prescription:ocr/'+str(pk))31		print("a")32		return HttpResponseRedirect(reverse('prescription:ocr' , args=(pk,)))33		34	else:35		print("b")36		return render(request,'prescription/prescription_upload.html',{'form':form})37		38@login_required39def delete(request,pk):40	trial = prescription.Prescription()41	trial.delete_record(request,pk)42	# pk1 = kwargs.get('pk1', none) 43	return redirect('prescription:list')44@login_required45def ocr(request,pk):46	if request.method == "GET":	47		trial = prescription.Prescription()48		ocr_instance = trial.ocr(request,pk)49		# pk2 = kwargs.get('pk2', none) 50		text = ocr_instance[0]51		prescriptions = ocr_instance[1]52	53	elif request.method == "POST":54		# form = forms.VerifyOCRText(request.POST , request.FILES)55		# if form.is_valid():56		instance = Prescriptions.objects.get(pk = pk)57		if instance is not None:58			instance.text = request.POST.get('ocr-text' , "")59			instance.save()60			instance = Prescriptions.objects.get(pk=pk)61			text = instance.text62			hash_ = Web3.sha3(text=text)63			hash_hex = hash_.hex()64			# print(hash_hex)65			# print(hash_)66			# print(len(hash_hex))67			if flag1==False:68				b = blockchain.Blockchain(url="http://127.0.0.1:7545" , abi=abi)69				# flag1=True70			if b.connect():71				inserted = b.insert_hash(hash_hex)72				print(inserted)73				if inserted:74					return redirect('prescription:list')75				else:76					return HttpResponse('<h1>Push to blockchain failed</h1>')77			else:78				return HttpResponse("<h1>Connection failed</h1>")79			# return redirect('prescription:block' , args=(pk))80			# return render(block(request,pk))81		else:82			return HttpResponse("<h1>Instance is null</h1>")	83	84	return render(request,'prescription/prescription_ocr.html',{'prescriptions':prescriptions,'text':text })85@login_required86def download(request,pk):87	instance = Prescriptions.objects.get(pk=pk)88	text = instance.text89	hash_ = Web3.soliditySha3(['string'],[text])90	hash_hex = hash_.hex()91	if flag1==False:92		b = blockchain.Blockchain(url="http://127.0.0.1:7545", abi=abi)93		# flag1=True94	b.connect()95	exists = b.check_hash(hash_hex)96	if exists:97		return render(request , 'prescription/prescription_download.html' ,{"prescription":instance} )98	else:99		return HttpResponse("<h1>Hash does not exist in blockchain</h1>")	100@login_required101def view(request,pk):102	trial = prescription.Prescription()103	print(trial)104	(exists , instance) = trial.view(request,pk)105	if exists:106		return render(request , 'prescription/prescription_view.html' , {'prescription':instance})107	else:108		return HttpResponse("<h1>Hash does not exist in blockchain</h1>")	109@login_required110def xray(request):111	trial = x_ray.XRay_class()112	form , pk = trial.upload_xray(request)113	if pk!=-1:114		print(pk)115		obj = XRay.objects.get(pk=pk)116		pred = trial.get_results(request , path)   117		print(pred)118		print(obj.predictions)119		obj.predictions = pred120		obj.save()121		image_path = obj.image.url122		return render(request , "prescription/xray_result.html" , {"image_path":image_path,"predictions":pred})	123	# pred = "Nahi aaya"124	return render(request , "prescription/xray_upload.html" , {"form":form})125@login_required126def xray_list(request):127	trial = x_ray.XRay_class()128	xray = trial.xray_list(request)129	return render(request,'prescription/xray_list.html',{'xray':xray})130@login_required131def xray_delete(request,pk):132	# print("deelte ho rha hai" , pk)133	trial = x_ray.XRay_class()134	trial.delete_xray(request,pk)135	return redirect('prescription:xray_list')136bytecode = "608060405234801561001057600080fd5b506101c6806100206000396000f3fe608060405260043610610046576000357c01000000000000000000000000000000000000000000000000000000009004806366e34cf11461004b578063af5135fd1461009e575b600080fd5b34801561005757600080fd5b506100846004803603602081101561006e57600080fd5b81019080803590602001909291905050506100f1565b604051808215151515815260200191505060405180910390f35b3480156100aa57600080fd5b506100d7600480360360208110156100c157600080fd5b8101908080359060200190929190505050610140565b604051808215151515815260200191505060405180910390f35b60006100fc82610140565b1561010a576000905061013b565b6000829080600181540180825580915050906001820390600052602060002001600090919290919091505550600190505b919050565b60008060009050600090505b60008054905081101561018f578260008281548110151561016957fe5b90600052602060002001541415610184576001915050610195565b80600101905061014c565b60009150505b91905056fea165627a7a72305820577f0c80bf483610360752f4736f01428e4edf66c5102792faaf73951fb4cf2b0029"137abi = json.loads("""[138	{139		"constant": false,140		"inputs": [141			{142				"name": "hash",143				"type": "bytes32"144			}145		],146		"name": "add_hash",147		"outputs": [148			{149				"name": "",150				"type": "bool"151			}152		],153		"payable": false,154		"stateMutability": "nonpayable",155		"type": "function"156	},157	{158		"inputs": [],159		"payable": false,160		"stateMutability": "nonpayable",161		"type": "constructor"162	},163	{164		"constant": true,165		"inputs": [166			{167				"name": "hash",168				"type": "bytes32"169			}170		],171		"name": "check_existence",172		"outputs": [173			{174				"name": "",175				"type": "bool"176			}177		],178		"payable": false,179		"stateMutability": "view",180		"type": "function"181	}...forms.py
Source:forms.py  
1from django import forms2from . import models3class UploadPrescription(forms.ModelForm):4	class Meta:5		model=models.Prescriptions6		fields = ['image','record','name']#required fields(input by user)7class VerifyOCRText(forms.ModelForm):8	class Meta:9		model=models.Prescriptions10		fields = ['text']	11class UploadXRay(forms.ModelForm):12	class Meta:13		model = models.XRay...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
