Some more + the migration

This commit is contained in:
Trenton H
2026-01-21 14:17:03 -08:00
parent e5df90bc77
commit 6d7350a97c
3 changed files with 19 additions and 47 deletions

View File

@@ -1,5 +1,4 @@
# this is here so that django finds the checks. # this is here so that django finds the checks.
from documents.checks import changed_password_check
from documents.checks import parser_check from documents.checks import parser_check
__all__ = ["changed_password_check", "parser_check"] __all__ = ["parser_check"]

View File

@@ -1,51 +1,8 @@
# Generated by Django 3.1.3 on 2020-11-20 11:21 # Generated by Django 3.1.3 on 2020-11-20 11:21
from pathlib import Path
import magic
from django.conf import settings
from django.db import migrations from django.db import migrations
from django.db import models from django.db import models
from paperless.db import GnuPG
STORAGE_TYPE_UNENCRYPTED = "unencrypted"
STORAGE_TYPE_GPG = "gpg"
def source_path(self) -> Path:
if self.filename:
fname: str = str(self.filename)
else:
fname = f"{self.pk:07}.{self.file_type}"
if self.storage_type == STORAGE_TYPE_GPG:
fname += ".gpg"
return Path(settings.ORIGINALS_DIR) / fname
def add_mime_types(apps, schema_editor):
Document = apps.get_model("documents", "Document")
documents = Document.objects.all()
for d in documents:
with Path(source_path(d)).open("rb") as f:
if d.storage_type == STORAGE_TYPE_GPG:
data = GnuPG.decrypted(f)
else:
data = f.read(1024)
d.mime_type = magic.from_buffer(data, mime=True)
d.save()
def add_file_extensions(apps, schema_editor):
Document = apps.get_model("documents", "Document")
documents = Document.objects.all()
for d in documents:
d.file_type = Path(d.filename).suffix.lstrip(".")
d.save()
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
@@ -59,7 +16,7 @@ class Migration(migrations.Migration):
field=models.CharField(default="-", editable=False, max_length=256), field=models.CharField(default="-", editable=False, max_length=256),
preserve_default=False, preserve_default=False,
), ),
migrations.RunPython(add_mime_types, migrations.RunPython.noop), migrations.RunPython(migrations.RunPython.noop, migrations.RunPython.noop),
# This operation is here so that we can revert the entire migration: # This operation is here so that we can revert the entire migration:
# By allowing this field to be blank and null, we can revert the # By allowing this field to be blank and null, we can revert the
# remove operation further down and the database won't complain about # remove operation further down and the database won't complain about
@@ -84,7 +41,7 @@ class Migration(migrations.Migration):
blank=True, blank=True,
), ),
), ),
migrations.RunPython(migrations.RunPython.noop, add_file_extensions), migrations.RunPython(migrations.RunPython.noop, migrations.RunPython.noop),
migrations.RemoveField( migrations.RemoveField(
model_name="document", model_name="document",
name="file_type", name="file_type",

View File

@@ -0,0 +1,16 @@
# Generated by Django 5.2.9 on 2026-01-21 22:16
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("documents", "1076_alter_paperlesstask_task_name"),
]
operations = [
migrations.RemoveField(
model_name="document",
name="storage_type",
),
]