def generated_exercise_file(request, course_key, exercise_key, exercise_instance, filename): ''' Delivers a generated file of the exercise instance. ''' # Fetch the corresponding exercise entry from the config. (course, exercise) = config.exercise_entry(course_key, exercise_key) if course is None or exercise is None: raise Http404() if "generated_files" in exercise: import magic for gen_file_conf in exercise["generated_files"]: if gen_file_conf["file"] == filename: if gen_file_conf.get("allow_download", False): file_content = read_generated_exercise_file( course, exercise, exercise_instance, filename) response = HttpResponse(file_content, content_type=magic.from_buffer( file_content, mime=True)) response[ 'Content-Disposition'] = 'attachment; filename="{}"'.format( filename) return response else: # hide file existence with 404 raise Http404() raise Http404()
def generated_exercise_file(request, course_key, exercise_key, exercise_instance, filename): ''' Delivers a generated file of the exercise instance. ''' # Fetch the corresponding exercise entry from the config. (course, exercise) = config.exercise_entry(course_key, exercise_key) if course is None or exercise is None: raise Http404() if "generated_files" in exercise: import magic for gen_file_conf in exercise["generated_files"]: if gen_file_conf["file"] == filename: if "allow_download" in gen_file_conf and gen_file_conf["allow_download"]: file_content = read_generated_exercise_file(course, exercise, exercise_instance, filename) response = HttpResponse(file_content, content_type=magic.from_buffer(file_content, mime=True)) response['Content-Disposition'] = 'attachment; filename="{}"'.format(filename) return response else: # hide file existence with 404 raise Http404() raise Http404()