From d757388ca8cf8bedd451b40e0db39b4f24282d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniele=20Vigan=C3=B2?= Date: Tue, 28 Oct 2025 22:19:05 +0100 Subject: [PATCH] Restore missing `DeduplicatedStorage` for documents --- ram/ram/__init__.py | 2 +- ram/ram/models.py | 1 + ram/ram/utils.py | 2 +- ...ile_alter_catalogdocument_file_and_more.py | 49 +++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 ram/repository/migrations/0003_alter_bookdocument_file_alter_catalogdocument_file_and_more.py diff --git a/ram/ram/__init__.py b/ram/ram/__init__.py index b01e9b6..ff3fbc5 100644 --- a/ram/ram/__init__.py +++ b/ram/ram/__init__.py @@ -1,4 +1,4 @@ from ram.utils import git_suffix -__version__ = "0.17.13" +__version__ = "0.17.14" __version__ += git_suffix(__file__) diff --git a/ram/ram/models.py b/ram/ram/models.py index ed71aac..fe24f3a 100644 --- a/ram/ram/models.py +++ b/ram/ram/models.py @@ -27,6 +27,7 @@ class Document(models.Model): description = models.CharField(max_length=128, blank=True) file = models.FileField( upload_to="files/", + storage=DeduplicatedStorage, ) creation_time = models.DateTimeField(auto_now_add=True) updated_time = models.DateTimeField(auto_now=True) diff --git a/ram/ram/utils.py b/ram/ram/utils.py index 111c409..b5c5e94 100644 --- a/ram/ram/utils.py +++ b/ram/ram/utils.py @@ -13,7 +13,7 @@ class DeduplicatedStorage(FileSystemStorage): """ A derived FileSystemStorage class that compares already existing files (with the same name) with new uploaded ones and stores new file only if - sha256 hash on is content is different + sha256 hash on its content is different """ def save(self, name, content, max_length=None): diff --git a/ram/repository/migrations/0003_alter_bookdocument_file_alter_catalogdocument_file_and_more.py b/ram/repository/migrations/0003_alter_bookdocument_file_alter_catalogdocument_file_and_more.py new file mode 100644 index 0000000..76842f7 --- /dev/null +++ b/ram/repository/migrations/0003_alter_bookdocument_file_alter_catalogdocument_file_and_more.py @@ -0,0 +1,49 @@ +# Generated by Django 5.2.7 on 2025-10-28 21:17 + +import ram.utils +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("repository", "0002_invoicedocument_remove_basebookdocument_book_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="bookdocument", + name="file", + field=models.FileField( + storage=ram.utils.DeduplicatedStorage, upload_to="files/" + ), + ), + migrations.AlterField( + model_name="catalogdocument", + name="file", + field=models.FileField( + storage=ram.utils.DeduplicatedStorage, upload_to="files/" + ), + ), + migrations.AlterField( + model_name="decoderdocument", + name="file", + field=models.FileField( + storage=ram.utils.DeduplicatedStorage, upload_to="files/" + ), + ), + migrations.AlterField( + model_name="genericdocument", + name="file", + field=models.FileField( + storage=ram.utils.DeduplicatedStorage, upload_to="files/" + ), + ), + migrations.AlterField( + model_name="rollingstockdocument", + name="file", + field=models.FileField( + storage=ram.utils.DeduplicatedStorage, upload_to="files/" + ), + ), + ]