Beispiel #1
0
    def get(self, request, contest_slug, task_name, task_type):
        user = User.objects.get(username=request.user)
        translation = get_translation_by_contest_and_task_type(
            request, user, contest_slug, task_name, task_type)
        requested_user = get_requested_user(request, task_type)
        if translation.frozen:
            pdf_file_path = final_pdf_path(contest_slug, task_name,
                                           requested_user)
            return pdf_response(pdf_file_path,
                                get_file_name_from_path(pdf_file_path))

        pdf_file_path = unreleased_pdf_path(contest_slug, task_name,
                                            requested_user)
        last_edit_time = translation.get_latest_change_time()
        rebuild_needed = not os.path.exists(
            pdf_file_path) or os.path.getmtime(pdf_file_path) < last_edit_time
        if rebuild_needed:
            html = render_pdf_template(request,
                                       user,
                                       contest_slug,
                                       task_name,
                                       task_type,
                                       static_path=settings.STATIC_ROOT,
                                       images_path=settings.MEDIA_ROOT +
                                       'images/',
                                       pdf_output=True)
            convert_html_to_pdf(html, pdf_file_path)
            add_page_numbers_to_pdf(pdf_file_path, task_name)

        return pdf_response(pdf_file_path,
                            get_file_name_from_path(pdf_file_path))
 def get(self, request, contest_slug, task_name, task_type):
     user = User.objects.get(username=request.user)
     translation = self._get_translation_by_contest_and_task_type(
         request, user, contest_slug, task_name, task_type)
     return HttpResponse(
         render_pdf_template(translation,
                             task_type,
                             static_path='/static',
                             images_path='/media/images/',
                             pdf_output=False))
Beispiel #3
0
 def get(self, request, contest_slug, task_name, task_type):
     user = User.objects.get(username=request.user)
     return HttpResponse(
         render_pdf_template(request,
                             user,
                             contest_slug,
                             task_name,
                             task_type,
                             static_path='/static',
                             images_path=settings.HOST_URL +
                             'media/images/',
                             pdf_output=False))