Ejemplo n.º 1
0
def print_questions(request,qlist,lang_id=1,exam_id=3):

    if len(qlist) > 100:
        return HttpResponse("Please download at most 100 questions at once. Sorry for the inconvenience, we hope to be able to remove this limitation at a later stage.",content_type="text/plain")
    show_images = False
    if len(qlist) == 1:
        show_images = True
    try:
        exam = Exam.objects.get(id=int(exam_id))
        language = Language.objects.get(id=int(lang_id))
    except:
        raise Http404()

    questions = ExamQuestion.objects.filter(id__in=[int(x) for x in qlist]).order_by("position")
    exam_xml = print_question_objects(questions,lang_id,exam_id)
    return HttpResponse(exam_xml,content_type="text/plain")
    #TODO: implement proper pdf printing

    filename = "{0}_{1}_{2}.pdf".format(exam.name,language.name,request.user.id)
    utils.xml2pdf(exam_xml,filename,show_images)
    path = 'xml2pdf/output/{0}'.format(filename)
    wrapper = FileWrapper(file(path))
    response = DeleteFileAfterResponse(wrapper,content_type='application/pdf',filename=path)
    response['Content-Length'] = os.path.getsize(path)
    response['Content-Disposition'] = 'attachment; filename={0}'.format(filename)
    return response
Ejemplo n.º 2
0
def print_exam(request,exam_id,lang_id=1):
    try:
        exam = Exam.objects.get(id=int(exam_id))
        language = Language.objects.get(id=int(lang_id))
    except:
        raise Http404()


    questions = ExamQuestion.objects.filter(exam=exam).order_by("position")
    exam_xml = print_question_objects(questions,lang_id,exam_id)
    return HttpResponse(exam_xml,content_type="text/plain")
    #TODO: implement proper pdf printing

    filename = "{0}_{1}_{2}.pdf".format(exam.name,language.name,request.user.id)
    utils.xml2pdf(exam_xml,filename,images=True)
    path = 'xml2pdf/output/{0}'.format(filename)
    wrapper = FileWrapper(file(path))
    response = DeleteFileAfterResponse(wrapper,content_type='application/pdf',filename=path)
    response['Content-Length'] = os.path.getsize(path)
    response['Content-Disposition'] = 'attachment; filename={0}'.format(filename)
    return response