* Saving some start on this * At least partially working for the tesseract parser * Problems with migration testing need to figure out * Work around that error * Fixes max m_pixels * Moving the settings to main paperless application * Starting some consumer options * More fixes and work * Fixes these last tests * Fix max_length on OcrSettings.mode field * Fix all fields on Common & Ocr settings serializers * Umbrellla config view * Revert "Umbrellla config view" This reverts commit fbaf9f4be30f89afeb509099180158a3406416a5. * Updates to use a single configuration object for all settings * Squashed commit of the following: commit 8a0a49dd5766094f60462fbfbe62e9921fbd2373 Author: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue Dec 19 23:02:47 2023 -0800 Fix formatting commit 66b2d90c507b8afd9507813ff555e46198ea33b9 Author: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue Dec 19 22:36:35 2023 -0800 Refactor frontend data models commit 5723bd8dd823ee855625e250df39393e26709d48 Author: Adam Bogdał <adam@bogdal.pl> Date: Wed Dec 20 01:17:43 2023 +0100 Fix: speed up admin panel for installs with a large number of documents (#5052) commit 9b08ce176199bf9011a6634bb88f616846150d2b Author: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue Dec 19 15:18:51 2023 -0800 Update PULL_REQUEST_TEMPLATE.md commit a6248bec2d793b7690feed95fcaf5eb34a75bfb6 Author: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue Dec 19 15:02:05 2023 -0800 Chore: Update Angular to v17 (#4980) commit b1f6f52486d5ba5c04af99b41315eb6428fd1fa8 Author: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue Dec 19 13:53:56 2023 -0800 Fix: Dont allow null custom_fields property via API (#5063) commit 638d9970fd468d8c02c91d19bd28f8b0796bdcb1 Author: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue Dec 19 13:43:50 2023 -0800 Enhancement: symmetric document links (#4907) commit 5e8de4c1da6eb4eb8f738b20962595c7536b30ec Author: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue Dec 19 12:45:04 2023 -0800 Enhancement: shared icon & shared by me filter (#4859) commit 088bad90306025d3f6b139cbd0ad264a1cbecfe5 Author: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Tue Dec 19 12:04:03 2023 -0800 Bulk updates all the backend libraries (#5061) * Saving some work on frontend config * Very basic but dynamically-generated config form * Saving work on slightly less ugly frontend config * JSON validation for user_args field * Fully dynamic config form * Adds in some additional validators for a nicer error message * Cleaning up the testing and coverage more * Reverts unintentional change * Adds documentation about the settings and the precedence * Couple more commenting and style fixes --------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
174 lines
4.4 KiB
Python
174 lines
4.4 KiB
Python
from django.core.validators import MinValueValidator
|
|
from django.db import models
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
DEFAULT_SINGLETON_INSTANCE_ID = 1
|
|
|
|
|
|
class AbstractSingletonModel(models.Model):
|
|
class Meta:
|
|
abstract = True
|
|
|
|
def save(self, *args, **kwargs):
|
|
"""
|
|
Always save as the first and only model
|
|
"""
|
|
self.pk = DEFAULT_SINGLETON_INSTANCE_ID
|
|
super().save(*args, **kwargs)
|
|
|
|
|
|
class OutputTypeChoices(models.TextChoices):
|
|
"""
|
|
Matches to --output-type
|
|
"""
|
|
|
|
PDF = ("pdf", _("pdf"))
|
|
PDF_A = ("pdfa", _("pdfa"))
|
|
PDF_A1 = ("pdfa-1", _("pdfa-1"))
|
|
PDF_A2 = ("pdfa-2", _("pdfa-2"))
|
|
PDF_A3 = ("pdfa-3", _("pdfa-3"))
|
|
|
|
|
|
class ModeChoices(models.TextChoices):
|
|
"""
|
|
Matches to --skip-text, --redo-ocr, --force-ocr
|
|
and our own custom setting
|
|
"""
|
|
|
|
SKIP = ("skip", _("skip"))
|
|
REDO = ("redo", _("redo"))
|
|
FORCE = ("force", _("force"))
|
|
SKIP_NO_ARCHIVE = ("skip_noarchive", _("skip_noarchive"))
|
|
|
|
|
|
class ArchiveFileChoices(models.TextChoices):
|
|
"""
|
|
Settings to control creation of an archive PDF file
|
|
"""
|
|
|
|
NEVER = ("never", _("never"))
|
|
WITH_TEXT = ("with_text", _("with_text"))
|
|
ALWAYS = ("always", _("always"))
|
|
|
|
|
|
class CleanChoices(models.TextChoices):
|
|
"""
|
|
Matches to --clean, --clean-final
|
|
"""
|
|
|
|
CLEAN = ("clean", _("clean"))
|
|
FINAL = ("clean-final", _("clean-final"))
|
|
NONE = ("none", _("none"))
|
|
|
|
|
|
class ColorConvertChoices(models.TextChoices):
|
|
"""
|
|
Refer to the Ghostscript documentation for valid options
|
|
"""
|
|
|
|
UNCHANGED = ("LeaveColorUnchanged", _("LeaveColorUnchanged"))
|
|
RGB = ("RGB", _("RGB"))
|
|
INDEPENDENT = ("UseDeviceIndependentColor", _("UseDeviceIndependentColor"))
|
|
GRAY = ("Gray", _("Gray"))
|
|
CMYK = ("CMYK", _("CMYK"))
|
|
|
|
|
|
class ApplicationConfiguration(AbstractSingletonModel):
|
|
"""
|
|
Settings which are common across more than 1 parser
|
|
"""
|
|
|
|
output_type = models.CharField(
|
|
verbose_name=_("Sets the output PDF type"),
|
|
null=True,
|
|
blank=True,
|
|
max_length=8,
|
|
choices=OutputTypeChoices.choices,
|
|
)
|
|
|
|
"""
|
|
Settings for the Tesseract based OCR parser
|
|
"""
|
|
|
|
pages = models.PositiveIntegerField(
|
|
verbose_name=_("Do OCR from page 1 to this value"),
|
|
null=True,
|
|
validators=[MinValueValidator(1)],
|
|
)
|
|
|
|
language = models.CharField(
|
|
verbose_name=_("Do OCR using these languages"),
|
|
null=True,
|
|
blank=True,
|
|
max_length=32,
|
|
)
|
|
|
|
mode = models.CharField(
|
|
verbose_name=_("Sets the OCR mode"),
|
|
null=True,
|
|
blank=True,
|
|
max_length=16,
|
|
choices=ModeChoices.choices,
|
|
)
|
|
|
|
skip_archive_file = models.CharField(
|
|
verbose_name=_("Controls the generation of an archive file"),
|
|
null=True,
|
|
blank=True,
|
|
max_length=16,
|
|
choices=ArchiveFileChoices.choices,
|
|
)
|
|
|
|
image_dpi = models.PositiveIntegerField(
|
|
verbose_name=_("Sets image DPI fallback value"),
|
|
null=True,
|
|
validators=[MinValueValidator(1)],
|
|
)
|
|
|
|
# Can't call it clean, that's a model method
|
|
unpaper_clean = models.CharField(
|
|
verbose_name=_("Controls the unpaper cleaning"),
|
|
null=True,
|
|
blank=True,
|
|
max_length=16,
|
|
choices=CleanChoices.choices,
|
|
)
|
|
|
|
deskew = models.BooleanField(verbose_name=_("Enables deskew"), null=True)
|
|
|
|
rotate_pages = models.BooleanField(
|
|
verbose_name=_("Enables page rotation"),
|
|
null=True,
|
|
)
|
|
|
|
rotate_pages_threshold = models.FloatField(
|
|
verbose_name=_("Sets the threshold for rotation of pages"),
|
|
null=True,
|
|
validators=[MinValueValidator(0.0)],
|
|
)
|
|
|
|
max_image_pixels = models.FloatField(
|
|
verbose_name=_("Sets the maximum image size for decompression"),
|
|
null=True,
|
|
validators=[MinValueValidator(1_000_000.0)],
|
|
)
|
|
|
|
color_conversion_strategy = models.CharField(
|
|
verbose_name=_("Sets the Ghostscript color conversion strategy"),
|
|
blank=True,
|
|
null=True,
|
|
max_length=32,
|
|
choices=ColorConvertChoices.choices,
|
|
)
|
|
|
|
user_args = models.JSONField(
|
|
verbose_name=_("Adds additional user arguments for OCRMyPDF"),
|
|
null=True,
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name = _("paperless application settings")
|
|
|
|
def __str__(self) -> str: # pragma: no cover
|
|
return "ApplicationConfiguration"
|