def review(request): recordings = Recording.objects.filter(user = request.user) phrase_set = None if request.GET.get('set_id'): set_id = int(request.GET.get('set_id')) phrase_set = PhraseSet.objects.get(id=set_id) phrases = list(phrase_set.phrases.all()) recordings = recordings.filter(phrase__in = phrases) recordingObjs = [] for recording in recordings: media_url = lib.recording_url(recording.id) media_url_encoded = urllib.quote_plus(media_url) responses = Response.objects.filter(recording=recording).order_by('-created') responseObjs = [(response,lib.response_url(response.id)) for response in responses] # Additional params we want passed through to uploading upload_params = "phrase_id=" + str(recording.phrase.id) upload_params_encoded = urllib.quote_plus(upload_params) recordingObjs.append(( recording, media_url_encoded, responseObjs, lib.expert_url(recording.phrase.id), upload_params_encoded, )) return render(request,'review.html',{ 'recordingObjs':recordingObjs, 'phrase_set':phrase_set, })
def expert_recording(request,phrase_id): try: phrase = Phrase.objects.get(id=int(phrase_id)) except Phrase.DoesNotExist: raise Exception('phrase with id does not exist: ' + str(phrase_id)) upload_params = "phrase_id=" + str(phrase.id) + "&type=expert" upload_params_encoded = urllib.quote_plus(upload_params) # Expert info filename = "expert" + str(phrase.id) + ".mp3" exists = default_storage.exists(filename) created_time = None size = None if exists: created_time = default_storage.created_time(filename) size = default_storage.size(filename) return render(request,'expert_recording.html',{ 'phrase':phrase, 'upload_params_encoded':upload_params_encoded, 'expert_url':lib.expert_url(phrase_id), 'filename':filename, 'exists':exists, 'created_time':created_time, 'size':size, })
def give_response(request): recordings = Recording.objects.order_by('-created') recordingObjs = [] for recording in recordings: media_url = lib.recording_url(recording.id) media_url_encoded = urllib.quote_plus(media_url) responses = Response.objects.filter(recording=recording) responseObjs = [(response,lib.response_url(response.id)) for response in responses] # Additional params we want passed through to uploading upload_params = "type=response&recording_id=" + str(recording.id) upload_params_encoded = urllib.quote_plus(upload_params) recordingObjs.append(( recording, media_url_encoded, responseObjs, lib.expert_url(recording.phrase.id), upload_params_encoded, )) return render(request,'give_response.html',{ 'recordingObjs':recordingObjs, })
def practice(request,phrase_set_id): phrase_set = PhraseSet.objects.get(id=int(phrase_set_id)) phrases = phrase_set.phrases.all() # Post-quiz num = int(request.GET.get('num',1)) if num > len(phrases): raise Exception('finished') last_one = num == len(phrases) # Grab relevant phrase phrase = phrases[num - 1] # Additional params we want passed through to uploading upload_params = "phrase_id=" + str(phrase.id) upload_params_encoded = urllib.quote_plus(upload_params) # Precent bar phrase_percent = max(float(num - 1) / len(phrases)*100,2) next_url = '?num=' + str(num + 1) return render(request,'practice.html',{ 'phrase_set':phrase_set, 'last_one':last_one, 'phrase':phrase, 'next_url':next_url, 'upload_params_encoded':upload_params_encoded, 'expert_url':lib.expert_url(phrase.id), 'phrase_num':num, 'phrases_in_set':len(phrases), 'phrase_percent':phrase_percent, })