示例#1
0
def index(request):
    uuid = request.GET.get('uuid', 'test')
    MEDIA_ROOT = os.getcwd() + '/images/{}'.format(uuid)
    if not os.path.exists(MEDIA_ROOT):
        os.makedirs(MEDIA_ROOT)
    images = []

    for img in os.listdir(MEDIA_ROOT):
        if img.endswith('crop.jpg'):
            continue
        temp = '../../images/{}/{}'.format(uuid, img)
        images.append(temp)

    if request.method == "POST":
        img = UploadForm(request.POST, request.FILES)
        if img.is_valid():
            for imgfile in request.FILES.getlist('image'):
                save_file(imgfile, request.POST.get('uuid', 'test'))
            return HttpResponseRedirect(reverse('index'))
    else:
        img = UploadForm()
    images_upload = Upload.objects.all()

    groups = elastic.fetch_group_data(uuid)
    print groups

    context = {"images": images, "images_upload": images_upload, 'groups': groups}
    return render(request, 'api/index.html', context)
示例#2
0
def index(request):
    uuid = request.GET.get('uuid', 'test')
    MEDIA_ROOT = os.getcwd() + '/images/{}'.format(uuid)
    if not os.path.exists(MEDIA_ROOT):
        os.makedirs(MEDIA_ROOT)
    images = []

    for img in os.listdir(MEDIA_ROOT):
        if img.endswith('crop.jpg'):
            continue
        temp = '../../images/{}/{}'.format(uuid, img)
        images.append(temp)

    if request.method == "POST":
        img = UploadForm(request.POST, request.FILES)
        if img.is_valid():
            for imgfile in request.FILES.getlist('image'):
                save_file(imgfile, request.POST.get('uuid', 'test'))
            return HttpResponseRedirect(reverse('index'))
    else:
        img = UploadForm()
    images_upload = Upload.objects.all()

    groups = elastic.fetch_group_data(uuid)
    print groups

    context = {
        "images": images,
        "images_upload": images_upload,
        'groups': groups
    }
    return render(request, 'api/index.html', context)
示例#3
0
def home(request):
    if request.method=="POST":
        img = UploadForm(request.POST, request.FILES)       
        if img.is_valid():
            img.save()  
            return HttpResponseRedirect(reverse('imageupload'))
    else:
        img=UploadForm()
    #images=Upload.objects.all()
    return render(request,'home.html',{'form':img})#,'images':images})
示例#4
0
文件: views.py 项目: ahfx/misc
def uploadimages(request):
	if request.method=="POST":
		img = UploadForm(request.POST, request.FILES)
		if img.is_valid():
			img.save()
			return HttpResponseRedirect(reverse('imageupload'))
	else:
		img = UploadForm()

	return render(request, 'uploadimages.html', {'form':img})
示例#5
0
def home(request):
    if request.method=="POST":
        song = UploadForm(request.POST, request.FILES)
        if song.is_valid():
            song.save()
            objs=Upload.objects.all()
            obj=objs[len(objs)-1]
            filename=obj.songfile.name
            if filename[-4:]!=".mp3": #To check if the file is .mp3
                flag=0
                message = "This file is not .mp3"
                id=obj.id
                Upload.objects.filter(id=id).delete() #If not delete it
                return render(request,'upload.html',{'message':message,'flag':flag})
            else:
                #To write the information on the file
                audiofile = eyed3.load(os.getcwd()+obj.songfile.url)
                audiofile.tag.artist = obj.artist
                audiofile.tag.album = obj.album
                audiofile.tag.title = obj.songname
                audiofile.tag.album_artist = obj.albumartist
                audiofile.tag.track = obj.tracknumber
                audiofile.tag.save()
                return HttpResponseRedirect(reverse('songupload'))
    else:
        song=UploadForm()
        flag=1
        message=""
    songs=Upload.objects.all().order_by('-upload_date')
    return render(request,'upload.html',{'form':song,'songs':songs,'message':message,'flag':flag})
def home(request):
    if request.method == "POST":
        img = UploadForm(request.POST, request.FILES)
        if img.is_valid():
            img.save()
            return HttpResponseRedirect(reverse('imageupload'))
    else:
        img = UploadForm()
    images = Upload.objects.all().order_by('-upload_date')
    return render(request, 'home.html', {'form': img, 'images': images})
示例#7
0
def uploadimages(request):
    if request.method == "POST":
        img = UploadForm(request.POST, request.FILES)
        if img.is_valid():
            img.save()
            return HttpResponseRedirect(reverse('imageupload'))
    else:
        img = UploadForm()

    return render(request, 'uploadimages.html', {'form': img})
示例#8
0
def uploader(request):
    if request.method == "POST":
        img = UploadForm(request.POST, request.FILES)
        if img.is_valid():
            pic = request.FILES['pic']
            img_obj = Upload(pic=pic)
            img_obj.save()

            img_Path = os.path.join(settings.MEDIA_ROOT, "images/" + pic.name)
            normalized_image = image_normalize(img_Path)

            with graph.as_default():
                prediction = model.predict_classes(normalized_image)

            img_obj.description = "此圖經 Mnist Model 辨識為 " + str(prediction[0])
            img_obj.save()

            return HttpResponseRedirect(reverse('uploader'))
    else:
        img = UploadForm()
    images = Upload.objects.all()
    return render(request, 'upload.html', {'form': img, 'images': images})
示例#9
0
def home(request):
    name = 'san'
    # if request.method=="POST":
    doc = UploadForm(request.POST, request.FILES) 
    print(doc)
    doc_file = str(request.FILES)
    print(doc_file)
    if doc_file != "<MultiValueDict: {}>":
        spliting = doc_file.split(" ")
        print(spliting[3])
        name = str(spliting[3])
        print("before docs...........")
        print(name)
        if doc.is_valid():
            doc.save()  
            # return HttpResponseRedirect(reverse('imageupload'))
        path=r'.\media\Doc'
        v=str('\\')
        name=v+name
    
        finalarray = []
        LoanCount = 0
        LoanCountArray = []
      
        print(path)
        # with open ('.\media\Doc\hello.txt','r') as f:
        with open (path+name,'r') as f:
            print("hhhhh...........")
            text = f.read()
            # print(text)
            para = text.split("Loan Type")
            x=len(para)
            i=0
            q=0
            while(x>0):
            # while(q>0):
                returnobj = {}
                line = para[i].split("\n")
                l=0
                l=len(line)
                j=0
                f1=0
                f2=0
        
                while(l>0):
                    m = line[j].split(":")
                    
                    if m[0].find("Student First Name") != -1: 
                        m[0]=m[0].replace(" ","")
                        
                        m[1]=m[1].strip()
                        if m[1] == '':
                            returnobj[m[0]]='Null'
                            StudentFirstName = 'Null'
                        else:
                            returnobj[m[0]]=m[1]
                            StudentFirstName = m[1]

                    elif m[0].find("Student Middle Initial") != -1:
                        m[0]=m[0].replace(" ","")
                        
                        m[1]=m[1].strip()
                        if m[1] == '':
                            StudentMiddleInitial = 'Null'
                        else:
                            StudentMiddleInitial = m[1] 

                    elif m[0].find("Student Last Name") != -1:
                        m[0]=m[0].replace(" ","")
                        
                        m[1]=m[1].strip()
                        if m[1] == '':
                            StudentLastName = 'Null'
                        else:
                            StudentLastName = m[1]
                        
                        
                    elif m[0].find("Student Street Address 1") != -1:
                        m[0]=m[0].replace(" ","")
                        
                        m[1]=m[1].strip()
                        if m[1] == '':
                            StudentStreetAddress = 'Null'
                        else:
                            StudentStreetAddress = m[1]
                    
                    elif m[0].find("Student City") != -1:
                        m[0]=m[0].replace(" ","")
                        
                        m[1]=m[1].strip()
                        if m[1] == '':
                            StudentCity = 'Null'
                        else:
                            StudentCity = m[1]
                        
                    elif m[0].find("Student State Code") != -1:
                        m[0]=m[0].replace(" ","")
                        
                        m[1]=m[1].strip()
                        if m[1] == '':
                            StudentStateCode = 'Null'
                        else:
                            StudentStateCode = m[1]

                    elif m[0].find("Student Zip Code") != -1:
                        m[0]=m[0].replace(" ","")
                        
                        m[1]=m[1].strip()
                        if m[1] == '':
                            StudentZipCode = 'Null'
                        else:
                            StudentZipCode = m[1]

                    elif m[0].find("Student Home Phone Country Code") != -1:
                        m[0]=m[0].replace(" ","")
                        
                        m[1]=m[1].strip()
                        if m[1] == '':
                            StudentHomePhoneCountryCode = 'Null'
                        else:
                            StudentHomePhoneCountryCode = m[1]

                    elif m[0].find("Student Work Phone Country Code") != -1:
                        m[0]=m[0].replace(" ","")
                        
                        m[1]=m[1].strip()
                        if m[1] == '':
                            StudentWorkPhoneCountryCode = 'Null'
                        else:
                            StudentWorkPhoneCountryCode = m[1]

                    elif m[0].find("Student Cell Phone Country Code") != -1:
                        m[0]=m[0].replace(" ","")
                        
                        m[1]=m[1].strip()
                        if m[1] == '':
                            StudentCellPhoneCountryCode = 'Null'
                        else:
                            StudentCellPhoneCountryCode = m[1]

                    elif m[0].find("Student Home Phone Number") != -1:
                        m[0]=m[0].replace(" ","")
                        
                        m[1]=m[1].strip()
                        if m[1] == '':
                            StudentHomePhoneNumber = 'Null'
                        else:
                            StudentHomePhoneNumber = m[1]

                    elif m[0].find("Student Work Phone Number") != -1:
                        m[0]=m[0].replace(" ","")
                        
                        m[1]=m[1].strip()
                        if m[1] == '':
                            StudentWorkPhoneNumber = 'Null'
                        else:
                            StudentWorkPhoneNumber = m[1]

                    elif m[0].find("Student Cell Phone Number") != -1:
                        m[0]=m[0].replace(" ","")
                        
                        m[1]=m[1].strip()
                        if m[1] == '':
                            StudentCellPhoneNumber = 'Null'
                        else:
                            StudentCellPhoneNumber = m[1]
                            
                    elif m[0].find("Loan Outstanding Principal Balance") != -1 or m[0].find("Loan Outstanding Interest Balance") != -1 or m[0].find("Loan Interest Rate") != -1 or m[0].find("Loan Date") != -1 or m[0].find("Loan Canceled Date") != -1 or m[0].find("Loan Canceled Amount") != -1 or m[0].find("Loan Contact Name") != -1 or m[0].find("Student Cell Phone Country Code") != -1 or m[0].find("Loan Repayment Plan Type") != -1:
                        m[0]=m[0].replace(" ","")
                        m[1]=m[1].strip()
                        if m[1] == '':
                            returnobj[m[0]]='Null'
                        else:
                            returnobj[m[0]]=m[1]

                    elif m[0].find("Loan Status Description") != -1 and f1 == 0:
                        m[0]=m[0].replace(" ","")
                        m[1]=m[1].strip()
                        if m[1] == '':
                            returnobj[m[0]]='Null'
                        else:
                            returnobj[m[0]]=m[1]
                        f1=1

                    elif m[0].find("Loan Status Effective Date") != -1 and f2 == 0:
                        m[0]=m[0].replace(" ","")
                        m[1]=m[1].strip()
                        if m[1] == '':
                            returnobj[m[0]]='Null'
                        else:
                            returnobj[m[0]]=m[1]
                        f2=1

                    elif len(m[0]) == 0 and len(m) != 1:
            
                        m[1]=m[1].strip()
                        # if m[1] == '':
                        #     returnobj["Loan type"]='Null'
                        # else:
                        returnobj["LoanType"]=m[1]

                    j=j+1
                    l=l-1
                    
                x=x-1
        
                if i == 0:
                    # final["studentDetails"] = result
                    # final["studentDetails"] = json.dumps(returnobj)
                    # returnobj.clear()
                    pass
                
                else:
                    finalarray.extend([returnobj])
                    q=q+1
                    LoanCount = LoanCount + 1
                    LoanCountArray.extend([LoanCount])
                    # returnobj.clear()

                i=i+1
    
        final["Loans"] = json.dumps(finalarray)    
        finalresult = json.dumps(final)
        print(type(finalresult))
        return render(request,'home.html',{'Doc':StudentFirstName, 'StudentMiddleInitial':StudentMiddleInitial, 'StudentLastName':StudentLastName, 'StudentStreetAddress':StudentStreetAddress, 'StudentCity':StudentCity, 'StudentStateCode':StudentStateCode, 'StudentZipCode':StudentZipCode, 'StudentHomePhoneCountryCode':StudentHomePhoneCountryCode, 'StudentWorkPhoneCountryCode':StudentWorkPhoneCountryCode, 'StudentCellPhoneCountryCode':StudentCellPhoneCountryCode, 'StudentHomePhoneNumber':StudentHomePhoneNumber, 'StudentWorkPhoneNumber':StudentWorkPhoneNumber, 'StudentCellPhoneNumber':StudentCellPhoneNumber, 'final':finalarray, 'LoanCount':LoanCountArray})
    docs=Upload.objects.all().order_by('-upload_date')
    return render(request,'home.html',{'form':doc,'Doc':docs})