Skip to content

Commit

Permalink
Merge pull request #709 from velrest/cherry_release
Browse files Browse the repository at this point in the history
Cherry release v6.4.2
  • Loading branch information
velrest authored Nov 26, 2024
2 parents c3ba3d5 + 7d87b62 commit 646b5f4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 6.4.2
### Fix
* **document:** Dont assume that a document has files ([`91e6a1f`](https://github.com/projectcaluma/alexandria/commit/91e6a1fdd6fe8fa9b89144a83f4ff94653c668fd))

# 6.4.1
### Fix
* **document:** Revalidate mimetypes after moving document to different category ([`46066ac`](https://github.com/projectcaluma/alexandria/commit/46066ac030808fde94bfc263f8b303e21bea0482))
Expand Down
5 changes: 4 additions & 1 deletion alexandria/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.contrib.postgres.fields import ArrayField
from django.contrib.postgres.indexes import GinIndex
from django.contrib.postgres.search import SearchVectorField
from django.core.exceptions import ImproperlyConfigured
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
from django.core.files import File as DjangoFile
from django.core.validators import RegexValidator
from django.db import models, transaction
Expand Down Expand Up @@ -155,11 +155,14 @@ class Document(UUIDModel):
date = models.DateField(blank=True, null=True)

def get_latest_original(self):
if not self.files.count():
raise ObjectDoesNotExist("Document has no files")
return self.files.filter(variant=File.Variant.ORIGINAL).latest("created_at")

@transaction.atomic()
def clone(self):
latest_original = self.get_latest_original()

self.pk = None
self.save()

Expand Down
13 changes: 13 additions & 0 deletions alexandria/core/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from django.core.files.uploadedfile import SimpleUploadedFile
from django.db.models import ObjectDoesNotExist

from alexandria.core.factories import FileData
from alexandria.core.models import Document, File
Expand Down Expand Up @@ -37,3 +38,15 @@ def test_clone_document(db, file_factory, content_type):

if content_type != "unsupported":
assert clone.files.filter(variant=File.Variant.THUMBNAIL).exists()


def test_document_no_files(
db,
document_factory,
):
document = document_factory.create()

try:
document.get_latest_original()
except ObjectDoesNotExist:
assert True
2 changes: 1 addition & 1 deletion alexandria/core/validations.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def validate_document(self, data, context):
if context["request"].method == "PATCH" and "category" in data:
category = data["category"]
document = context["view"].get_object()
if not document.category.pk == category.pk:
if not document.category.pk == category.pk and document.files.count():
# Validate if a document is moved to another category that the
# mime type of the file is still compatible with the category's
# mime types.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "caluma-alexandria"
version = "6.4.1"
version = "6.4.2"
description = "Document management service"
repository = "https://github.com/projectcaluma/alexandria"
authors = ["Caluma <[email protected]>"]
Expand Down

0 comments on commit 646b5f4

Please sign in to comment.