mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-10 00:18:57 +00:00
Enhancement: add barcode frontend config (#9742)
This commit is contained in:
@@ -96,10 +96,65 @@ class OcrConfig(OutputTypeConfig):
|
||||
user_args = json.loads(settings.OCR_USER_ARGS)
|
||||
except json.JSONDecodeError:
|
||||
user_args = {}
|
||||
|
||||
self.user_args = user_args
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class BarcodeConfig(BaseConfig):
|
||||
"""
|
||||
Barcodes settings
|
||||
"""
|
||||
|
||||
barcodes_enabled: bool = dataclasses.field(init=False)
|
||||
barcode_enable_tiff_support: bool = dataclasses.field(init=False)
|
||||
barcode_string: str = dataclasses.field(init=False)
|
||||
barcode_retain_split_pages: bool = dataclasses.field(init=False)
|
||||
barcode_enable_asn: bool = dataclasses.field(init=False)
|
||||
barcode_asn_prefix: str = dataclasses.field(init=False)
|
||||
barcode_upscale: float = dataclasses.field(init=False)
|
||||
barcode_dpi: int = dataclasses.field(init=False)
|
||||
barcode_max_pages: int = dataclasses.field(init=False)
|
||||
barcode_enable_tag: bool = dataclasses.field(init=False)
|
||||
barcode_tag_mapping: dict[str, str] = dataclasses.field(init=False)
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
app_config = self._get_config_instance()
|
||||
|
||||
self.barcodes_enabled = (
|
||||
app_config.barcodes_enabled or settings.CONSUMER_ENABLE_BARCODES
|
||||
)
|
||||
self.barcode_enable_tiff_support = (
|
||||
app_config.barcode_enable_tiff_support
|
||||
or settings.CONSUMER_BARCODE_TIFF_SUPPORT
|
||||
)
|
||||
self.barcode_string = (
|
||||
app_config.barcode_string or settings.CONSUMER_BARCODE_STRING
|
||||
)
|
||||
self.barcode_retain_split_pages = (
|
||||
app_config.barcode_retain_split_pages
|
||||
or settings.CONSUMER_BARCODE_RETAIN_SPLIT_PAGES
|
||||
)
|
||||
self.barcode_enable_asn = (
|
||||
app_config.barcode_enable_asn or settings.CONSUMER_ENABLE_ASN_BARCODE
|
||||
)
|
||||
self.barcode_asn_prefix = (
|
||||
app_config.barcode_asn_prefix or settings.CONSUMER_ASN_BARCODE_PREFIX
|
||||
)
|
||||
self.barcode_upscale = (
|
||||
app_config.barcode_upscale or settings.CONSUMER_BARCODE_UPSCALE
|
||||
)
|
||||
self.barcode_dpi = app_config.barcode_dpi or settings.CONSUMER_BARCODE_DPI
|
||||
self.barcode_max_pages = (
|
||||
app_config.barcode_max_pages or settings.CONSUMER_BARCODE_MAX_PAGES
|
||||
)
|
||||
self.barcode_enable_tag = (
|
||||
app_config.barcode_enable_tag or settings.CONSUMER_ENABLE_TAG_BARCODE
|
||||
)
|
||||
self.barcode_tag_mapping = (
|
||||
app_config.barcode_tag_mapping or settings.CONSUMER_TAG_BARCODE_MAPPING
|
||||
)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class GeneralConfig(BaseConfig):
|
||||
"""
|
||||
|
@@ -0,0 +1,100 @@
|
||||
# Generated by Django 5.1.7 on 2025-04-02 19:21
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("paperless", "0003_alter_applicationconfiguration_max_image_pixels"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="applicationconfiguration",
|
||||
name="barcode_asn_prefix",
|
||||
field=models.CharField(
|
||||
blank=True,
|
||||
max_length=32,
|
||||
null=True,
|
||||
verbose_name="Sets the ASN barcode prefix",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="applicationconfiguration",
|
||||
name="barcode_dpi",
|
||||
field=models.PositiveIntegerField(
|
||||
null=True,
|
||||
validators=[django.core.validators.MinValueValidator(1)],
|
||||
verbose_name="Sets the barcode DPI",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="applicationconfiguration",
|
||||
name="barcode_enable_asn",
|
||||
field=models.BooleanField(null=True, verbose_name="Enables ASN barcode"),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="applicationconfiguration",
|
||||
name="barcode_enable_tag",
|
||||
field=models.BooleanField(null=True, verbose_name="Enables tag barcode"),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="applicationconfiguration",
|
||||
name="barcode_enable_tiff_support",
|
||||
field=models.BooleanField(
|
||||
null=True,
|
||||
verbose_name="Enables barcode TIFF support",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="applicationconfiguration",
|
||||
name="barcode_max_pages",
|
||||
field=models.PositiveIntegerField(
|
||||
null=True,
|
||||
validators=[django.core.validators.MinValueValidator(1)],
|
||||
verbose_name="Sets the maximum pages for barcode",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="applicationconfiguration",
|
||||
name="barcode_retain_split_pages",
|
||||
field=models.BooleanField(null=True, verbose_name="Retains split pages"),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="applicationconfiguration",
|
||||
name="barcode_string",
|
||||
field=models.CharField(
|
||||
blank=True,
|
||||
max_length=32,
|
||||
null=True,
|
||||
verbose_name="Sets the barcode string",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="applicationconfiguration",
|
||||
name="barcode_tag_mapping",
|
||||
field=models.JSONField(
|
||||
null=True,
|
||||
verbose_name="Sets the tag barcode mapping",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="applicationconfiguration",
|
||||
name="barcode_upscale",
|
||||
field=models.FloatField(
|
||||
null=True,
|
||||
validators=[django.core.validators.MinValueValidator(1.0)],
|
||||
verbose_name="Sets the barcode upscale factor",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="applicationconfiguration",
|
||||
name="barcodes_enabled",
|
||||
field=models.BooleanField(
|
||||
null=True,
|
||||
verbose_name="Enables barcode scanning",
|
||||
),
|
||||
),
|
||||
]
|
@@ -167,6 +167,10 @@ class ApplicationConfiguration(AbstractSingletonModel):
|
||||
null=True,
|
||||
)
|
||||
|
||||
"""
|
||||
Settings for the Paperless application
|
||||
"""
|
||||
|
||||
app_title = models.CharField(
|
||||
verbose_name=_("Application title"),
|
||||
null=True,
|
||||
@@ -184,6 +188,83 @@ class ApplicationConfiguration(AbstractSingletonModel):
|
||||
upload_to="logo/",
|
||||
)
|
||||
|
||||
"""
|
||||
Settings for the barcode scanner
|
||||
"""
|
||||
|
||||
# PAPERLESS_CONSUMER_ENABLE_BARCODES
|
||||
barcodes_enabled = models.BooleanField(
|
||||
verbose_name=_("Enables barcode scanning"),
|
||||
null=True,
|
||||
)
|
||||
|
||||
# PAPERLESS_CONSUMER_BARCODE_TIFF_SUPPORT
|
||||
barcode_enable_tiff_support = models.BooleanField(
|
||||
verbose_name=_("Enables barcode TIFF support"),
|
||||
null=True,
|
||||
)
|
||||
|
||||
# PAPERLESS_CONSUMER_BARCODE_STRING
|
||||
barcode_string = models.CharField(
|
||||
verbose_name=_("Sets the barcode string"),
|
||||
null=True,
|
||||
blank=True,
|
||||
max_length=32,
|
||||
)
|
||||
|
||||
# PAPERLESS_CONSUMER_BARCODE_RETAIN_SPLIT_PAGES
|
||||
barcode_retain_split_pages = models.BooleanField(
|
||||
verbose_name=_("Retains split pages"),
|
||||
null=True,
|
||||
)
|
||||
|
||||
# PAPERLESS_CONSUMER_ENABLE_ASN_BARCODE
|
||||
barcode_enable_asn = models.BooleanField(
|
||||
verbose_name=_("Enables ASN barcode"),
|
||||
null=True,
|
||||
)
|
||||
|
||||
# PAPERLESS_CONSUMER_ASN_BARCODE_PREFIX
|
||||
barcode_asn_prefix = models.CharField(
|
||||
verbose_name=_("Sets the ASN barcode prefix"),
|
||||
null=True,
|
||||
blank=True,
|
||||
max_length=32,
|
||||
)
|
||||
|
||||
# PAPERLESS_CONSUMER_BARCODE_UPSCALE
|
||||
barcode_upscale = models.FloatField(
|
||||
verbose_name=_("Sets the barcode upscale factor"),
|
||||
null=True,
|
||||
validators=[MinValueValidator(1.0)],
|
||||
)
|
||||
|
||||
# PAPERLESS_CONSUMER_BARCODE_DPI
|
||||
barcode_dpi = models.PositiveIntegerField(
|
||||
verbose_name=_("Sets the barcode DPI"),
|
||||
null=True,
|
||||
validators=[MinValueValidator(1)],
|
||||
)
|
||||
|
||||
# PAPERLESS_CONSUMER_BARCODE_MAX_PAGES
|
||||
barcode_max_pages = models.PositiveIntegerField(
|
||||
verbose_name=_("Sets the maximum pages for barcode"),
|
||||
null=True,
|
||||
validators=[MinValueValidator(1)],
|
||||
)
|
||||
|
||||
# PAPERLESS_CONSUMER_ENABLE_TAG_BARCODE
|
||||
barcode_enable_tag = models.BooleanField(
|
||||
verbose_name=_("Enables tag barcode"),
|
||||
null=True,
|
||||
)
|
||||
|
||||
# PAPERLESS_CONSUMER_TAG_BARCODE_MAPPING
|
||||
barcode_tag_mapping = models.JSONField(
|
||||
verbose_name=_("Sets the tag barcode mapping"),
|
||||
null=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("paperless application settings")
|
||||
|
||||
|
@@ -185,11 +185,14 @@ class ProfileSerializer(serializers.ModelSerializer):
|
||||
|
||||
class ApplicationConfigurationSerializer(serializers.ModelSerializer):
|
||||
user_args = serializers.JSONField(binary=True, allow_null=True)
|
||||
barcode_tag_mapping = serializers.JSONField(binary=True, allow_null=True)
|
||||
|
||||
def run_validation(self, data):
|
||||
# Empty strings treated as None to avoid unexpected behavior
|
||||
if "user_args" in data and data["user_args"] == "":
|
||||
data["user_args"] = None
|
||||
if "barcode_tag_mapping" in data and data["barcode_tag_mapping"] == "":
|
||||
data["barcode_tag_mapping"] = None
|
||||
if "language" in data and data["language"] == "":
|
||||
data["language"] = None
|
||||
return super().run_validation(data)
|
||||
|
Reference in New Issue
Block a user