This commit is contained in:
Gabriel Augendre 2023-03-29 09:44:58 +02:00 committed by github-actions[bot]
parent fe08c9cca9
commit 53c6fcc07e
2 changed files with 19 additions and 19 deletions

View file

@ -83,6 +83,11 @@ class Article(models.Model):
def __str__(self) -> str:
return self.title
def save(self, *args: Any, **kwargs: Any) -> None:
if not self.slug:
self.slug = slugify(self.title)
return super().save(*args, **kwargs)
def get_absolute_url(self) -> str:
return reverse("article-detail", kwargs={"slug": self.slug})
@ -117,11 +122,6 @@ class Article(models.Model):
self.save()
return self
def save(self, *args: Any, **kwargs: Any) -> None:
if not self.slug:
self.slug = slugify(self.title)
return super().save(*args, **kwargs)
@property
def draft_public_url(self) -> str:
url = self.get_absolute_url() + f"?draft_key={self.draft_key}"

View file

@ -48,20 +48,6 @@ class Attachment(models.Model):
def __str__(self) -> str:
return f"{self.description} ({self.original_file.name})"
def reprocess(self) -> None:
self.processed_file = None # type: ignore[assignment]
self.save()
@property
def original_file_url(self) -> str:
return reverse("attachments:original", kwargs={"pk": self.pk})
@property
def processed_file_url(self) -> str | None:
if self.processed_file:
return reverse("attachments:processed", kwargs={"pk": self.pk})
return None
def save(self, *args: Any, **kwargs: Any) -> None:
super().save(*args, **kwargs)
@ -136,3 +122,17 @@ class Attachment(models.Model):
temp_path.unlink()
temp_dir.rmdir()
return super().save(*args, **kwargs)
@property
def original_file_url(self) -> str:
return reverse("attachments:original", kwargs={"pk": self.pk})
@property
def processed_file_url(self) -> str | None:
if self.processed_file:
return reverse("attachments:processed", kwargs={"pk": self.pk})
return None
def reprocess(self) -> None:
self.processed_file = None # type: ignore[assignment]
self.save()