Skip to content

Commit

Permalink
fix publications without pdfs
Browse files Browse the repository at this point in the history
  • Loading branch information
sinaatalay committed Oct 18, 2024
1 parent 4f5c6a9 commit 9e8a2e5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 134 deletions.
12 changes: 9 additions & 3 deletions src/assets/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Publication(BaseModel):
authors: list[str]
date: str
context: Optional[str] = None
pdf_file_name: str
pdf_file_name: Optional[str] = None

@functools.cached_property
def date_object(self) -> Date:
Expand Down Expand Up @@ -67,7 +67,10 @@ def year(self) -> int:
@functools.cached_property
def pdf_url(self) -> str:
"""Return the URL of the PDF file."""
return f"https://plasmacontrol.github.io/GroupWebsite/assets/data/publications/pdfs/{self.pdf_file_name}"
if self.pdf_file_name is None:
return None
else:
return f"https://plasmacontrol.github.io/GroupWebsite/assets/data/publications/pdfs/{self.pdf_file_name}"

@pydantic.field_validator("date")
@classmethod
Expand All @@ -84,10 +87,13 @@ def validate_date(cls, date: str) -> str:
@classmethod
def validate_pdf_exists(cls, pdf_file_name: str) -> str:
"""Validate that the PDF file exists."""
if pdf_file_name is None:
return pdf_file_name

pdf_file_path = (
pathlib.Path(__file__).parent / "publications" / "pdfs" / pdf_file_name
)
if not pdf_file_path.exists():
if not pdf_file_path.exists() and pdf_file_path.is_file():
raise FileNotFoundError(f"The file {pdf_file_name} does not exist!")

return pdf_file_name
Expand Down
Loading

0 comments on commit 9e8a2e5

Please sign in to comment.