Skip to content

Commit

Permalink
trying to fix error with cropped hphoto
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiboutas committed Jan 5, 2024
1 parent 8812d9f commit 4109e95
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ staticfiles/*

# media files
media
media/*
media/*
tex_media/*
5 changes: 4 additions & 1 deletion config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,10 @@
# LaTex settings
# LATEX_INTERPRETER = "pdflatex" # pdflatex, latex, xelatex, lualatex
# LATEX_INTERPRETER_OPTIONS = "-interaction=nonstopmode"
LATEX_GRAPHICSPATH = os.path.join(BASE_DIR, "media")
# LATEX_GRAPHICSPATH = os.path.join(BASE_DIR, "media") # changed 05.01.2024

TEX_MEDIA_DIR = BASE_DIR / "tex_media"
LATEX_GRAPHICSPATH = [TEX_MEDIA_DIR]


# crispy forms
Expand Down
13 changes: 12 additions & 1 deletion core/models/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,21 @@ def has_photo(self):
return to_check != "" and to_check is not None

@cached_property
def photo_path(self):
def photo_path_old(self):
if self.has_photo:
return self.cropped_photo.path

@cached_property
def photo_path(self):
if self.has_photo:
self.cropped_photo.seek(0)
photobytes = self.cropped_photo.read()
local_path = settings.TEX_MEDIA_DIR / self.cropped_photo.name
local_path.parent.mkdir(exist_ok=True, parents=True)
with open(local_path, "wb") as f:
f.write(photobytes)
return local_path

@classmethod
def create_template_profiles(cls):
from ..factories.profiles import ProfileFactory
Expand Down
3 changes: 3 additions & 0 deletions core/tex/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@


def format_path_for_latex(path):
if not isinstance(path, str):
path = str(path)

path = path.replace("\\", "/")
if not path.endswith("/"):
path += "/"
Expand Down

0 comments on commit 4109e95

Please sign in to comment.