Exemple #1
0
def audioUpload(request, book_id):
    #print("book_id")
    #print(book_id)
    #return HttpResponse("You're looking at poll %s" %  book_id)
    #Make a function call for choosing a para for the user.
    #render ash's view
    # Handle file upload
    '''
    Add additional inputs to post to figure out the book and 
    the paragraph number so that the upload takes place in that folder
    Current working : Saves the file with a fixed name and the file sent for API processing is fixed as well. 
    Both of these should be made dynamic 
    '''
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile = request.FILES['docfile'])
            newdoc.docfile.save('Ashu.wav',request.FILES['docfile'])
            #soundProcessWithAuphonic('documents/Ashu.wav')
            #soundProcessingWithAuphonicTask.delay('../documents/ashu.mp3')
            return HttpResponseRedirect(reverse('wa.views.audioSelection'))
    else:
        form = DocumentForm() # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()

    # Render list page with the documents and the form
    return render_to_response(
        'wa/audioUpload.html',
        {'documents': documents, 'form': form, 'book_id': book_id},
       
        context_instance=RequestContext(request)
    )
Exemple #2
0
def audioUploadForm(request, book_id, para_id):
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile = request.FILES['docfile'])
            #newdoc.save()
            
            #The Above call is just temoraray 
            #Use this if the name of the file is to be changed and saved with a path
            file_name = str(book_id)+"_"+str(para_id)+"_"+"sound.wav"
            newdoc.docfile.save(file_name,request.FILES['docfile'])
            log = logging.getLogger("wa")
            log.info(request.POST['chapterrad'])
            isChapter = request.POST['chapterrad']
            para = Paragraph.objects.get(pk = para_id)
            if isChapter=='yes':
                para.isChapter = True
            else:
                para.isChapter = False
            para.save()
            #soundProcessWithAuphonic('documents/Ashu.wav')
            user_id = request.user.id
            #set it before sending it for processing to avoid showing it again for recording But change appropriately if an error occurs while processing
            log.info("going to call uploadAudioDb")
            uploadAudioDb(para_id, user_id)
            soundProcessingWithAuphonicTask.delay('documents/'+file_name,book_id,para_id,user_id)
    return HttpResponseRedirect(reverse('wa.views.audioSelection')) 
Exemple #3
0
def uploadBook(request):
    # Handle file upload
    if request.user.is_authenticated():
        	
        if request.method == 'POST':

            form = DocumentForm(request.POST, request.FILES)
            if form.is_valid():
                log = logging.getLogger("wa")
                log.info("Upload Book :")
                log.info(request.POST['language'])
                b = Book(lang = Language.objects.get(langName = request.POST.get("language", "")), author = request.POST.get("author", ""), bookName = request.POST.get("bookName", ""), shouldConcatAudio = True, shouldConcatDigi = True)
                b.save()
                user_id = request.user.id
                uh = UserHistory(user = CustomUser.objects.get(pk = user_id), action = 'up', uploadedBook = b)
                uh.save()
                # add points
                user = CustomUser.objects.get(pk = user_id)
                user.points = user.points + pointsToAward("up")
                user.save()
                
                newdoc = Document(docfile = request.FILES['docfile'])

                #newdoc.docfile.save(str(b.id) + "/original/originalBook.pdf", request.FILES['docfile'], save=False)
                newdoc.docfile.save(str(b.id), request.FILES['docfile'], save=False)
                a = default_storage.open("documents/"+str(b.id))
                local_fs = FileSystemStorage(location='/tmp/pdf')
                local_fs.save(a.name,a)
                #b = default_storage.save(str(b.id) + "/original/originalBook.pdf",a)
                #default_storage.close("documents/"+str(b.id))
                log.info((a.name))
                mod_path = "/tmp/pdf/"+a.name
                f = open(mod_path, 'rb')
                myfile = File(f)
                new_name =str(b.id) + "/original/originalBook.pdf"
                default_storage.save(new_name,myfile)
                os.remove(mod_path)
                #--TODO--add it to user history
                #splitBookIntoPages(str(b.id) + "/original/originalBook.pdf")
                uploadSplitBookIntoGridFS.delay( str(b.id) + "/original/originalBook.pdf", b.id)
                # Redirect to the document list after POST
                #delete the file from default storage
                default_storage.delete("documents/"+ str(b.id))
                return HttpResponseRedirect(reverse('wa.views.audioSelection'))
        else:
            form = DocumentForm() # A empty, unbound form
            #langs = Languages.objects.all()
        # Render list page with the documents and the form
	    langs = Language.objects.all()
        return render_to_response(
            'wa/uploadBook.html',

            {'form': form,'langs':Language.objects.all()},
            context_instance=RequestContext(request)
        )
    else :
        return render_to_response('/wa')
Exemple #4
0
def audioUploadForm(request):
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile = request.FILES['docfile'])
            newdoc.save()
            
            #The Above call is just temoraray 
            #Use this if the name of the file is to be changed and saved with a path
            #newdoc.docfile.save('Ashu.wav',request.FILES['docfile'])
            #soundProcessWithAuphonic('documents/Ashu.wav')
            #soundProcessingWithAuphonicTask.delay('../documents/ashu.mp3')
    return HttpResponseRedirect(reverse('wa.views.audioSelection')) 
Exemple #5
0
def uploadBook(request):
    # Handle file upload
	if request.user.is_authenticated():
		if request.method == 'POST':

			form = DocumentForm(request.POST, request.FILES)
			if form.is_valid():
				#add book to book table

				b = Book(lang = Language.objects.get(langName = request.POST.get("language", "")), author = request.POST.get("author", ""), bookName = request.POST.get("bookName", ""))
				b.save()
				newdoc = Document(docfile = request.FILES['docfile'])
				#newdoc.docfile.save(str(b.id) + "/original/originalBook.pdf", request.FILES['docfile'], save=False)
				newdoc.docfile.save(str(b.id), request.FILES['docfile'], save=False)
				a = default_storage.open("documents/"+str(b.id))
				local_fs = FileSystemStorage(location='/tmp/pdf')
				local_fs.save(a.name,a)
				#b = default_storage.save(str(b.id) + "/original/originalBook.pdf",a)
				log = logging.getLogger("wa")
				log.info((a.name))
				mod_path = "/tmp/pdf/"+a.name
				f = open(mod_path, 'r')
				myfile = File(f)
				new_name =str(b.id) + "/original/originalBook.pdf"
				default_storage.save(new_name,myfile)
				os.remove(mod_path)
				#--TODO--add it to user history
				#splitBookIntoPages(str(b.id) + "/original/originalBook.pdf")
				uploadSplitBookIntoGridFS.delay( str(b.id) + "/original/originalBook.pdf", b.id)
				# Redirect to the document list after POST
				#delete the file from default storage
				default_storage.delete("documents/"+ str(b.id))
				return HttpResponseRedirect(reverse('wa.views.audioSelection'))
		else:
			form = DocumentForm() # A empty, unbound form

		# Render list page with the documents and the form
		return render_to_response(
			'wa/uploadBook.html',
			{'form': form},
			context_instance=RequestContext(request)
		)
	else :
		return render_to_response('/wa')
Exemple #6
0
def audioUpload(request, book_id):
    if request.user.is_authenticated():
        # Handle file upload
        '''
        Add additional inputs to post to figure out the book and 
        the paragraph number so that the upload takes place in that folder
        Current working : Saves the file with a fixed name and the file sent for API processing is fixed as well. 
        Both of these should be made dynamic 
        '''
        if request.method == 'POST':
            form = DocumentForm(request.POST, request.FILES)
            if form.is_valid():
                newdoc = Document(docfile = request.FILES['docfile'])
                newdoc.docfile.save('Ashu.wav',request.FILES['docfile'])
                log = logging.getLogger("wa")
                log.info(request.POST['yes'])
                #soundProcessWithAuphonic('documents/Ashu.wav')
                #soundProcessingWithAuphonicTask.delay('../documents/ashu.mp3')
                return HttpResponseRedirect(reverse('wa.views.audioSelection'))
        else:
            form = DocumentForm() # A empty, unbound form

        # Load documents for the list page
        #documents = Document.objects.all()
        #para_id = getChunkID(request.user.id, book_id, 0)
        para_id=1
        # Render list page with the documents and the form
        if(para_id != 0):
            return render_to_response(
                'wa/audioUpload.html',
                {'book_id': 1, 'para_id': 1 },
                context_instance=RequestContext(request)
            )
        else:
            return render_to_response('wa/error.html')
    else :
        return render_to_response('/wa')