From b0cf9547c1875a6d7d403300a5eb9b15d9a4d3cb Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sun, 9 Feb 2020 20:49:24 +0100 Subject: [PATCH] Fix problem with need update when tex is generated and not the pdf --- survey/exporter/tex/survey2tex.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/survey/exporter/tex/survey2tex.py b/survey/exporter/tex/survey2tex.py index 5a525ac1..3ef4a5ea 100755 --- a/survey/exporter/tex/survey2tex.py +++ b/survey/exporter/tex/survey2tex.py @@ -2,9 +2,12 @@ import logging import os +from datetime import datetime +from pathlib import Path from pydoc import locate -from django.conf import settings +import pytz +from django.utils.text import slugify from django.utils.translation import gettext_lazy as _ from survey.exporter.survey2x import Survey2X @@ -108,6 +111,19 @@ def generate(self, path, output=None): os.system("mv {}.pdf {}".format(file_name[:-3], output)) os.chdir(previous_directory) + @property + def file_modification_time(self): + """ Return the modification time of the pdf. """ + pdf_path = Path(self._get_x_dir(), "{}.pdf".format(slugify(self.survey.name))) + if not pdf_path.exists(): + earliest_working_timestamp_for_windows = 86400 + mtime = earliest_working_timestamp_for_windows + else: + mtime = os.path.getmtime(pdf_path) + mtime = datetime.utcfromtimestamp(mtime) + mtime = mtime.replace(tzinfo=pytz.timezone("UTC")) + return mtime + def survey_to_x(self, questions=None): if questions is None: questions = self.survey.questions.all()