mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-07 19:08:32 -05:00
Adds validation and testing to cover some of the common settings
This commit is contained in:
@@ -96,3 +96,52 @@ def debug_mode_check(app_configs, **kwargs):
|
||||
]
|
||||
else:
|
||||
return []
|
||||
|
||||
|
||||
@register()
|
||||
def settings_values_check(app_configs, **kwargs):
|
||||
"""
|
||||
Validates at least some of the user provided settings
|
||||
"""
|
||||
|
||||
def _ocrmypdf_settings_check():
|
||||
"""
|
||||
Validates some of the arguments which will be provided to ocrmypdf
|
||||
against the valid options. Use "ocrmypdf --help" to see the valid
|
||||
inputs
|
||||
"""
|
||||
msgs = []
|
||||
if settings.OCR_OUTPUT_TYPE not in {
|
||||
"pdfa",
|
||||
"pdf",
|
||||
"pdfa-1",
|
||||
"pdfa-2",
|
||||
"pdfa-3",
|
||||
}:
|
||||
msgs.append(
|
||||
Error(f'OCR output type "{settings.OCR_OUTPUT_TYPE}" is not valid'),
|
||||
)
|
||||
|
||||
if settings.OCR_MODE not in {"force", "skip", "redo_ocr"}:
|
||||
msgs.append(Error(f'OCR output mode "{settings.OCR_MODE}" is not valid'))
|
||||
|
||||
if settings.OCR_CLEAN not in {"clean", "clean_final"}:
|
||||
msgs.append(Error(f'OCR clean mode "{settings.OCR_CLEAN}" is not valid'))
|
||||
return msgs
|
||||
|
||||
def _timezone_validate():
|
||||
"""
|
||||
Validates the user provided timezone is a valid timezone
|
||||
"""
|
||||
try:
|
||||
import zoneinfo
|
||||
except ImportError: # pragma: nocover
|
||||
import backports.zoneinfo as zoneinfo
|
||||
msgs = []
|
||||
if settings.TIME_ZONE not in zoneinfo.available_timezones():
|
||||
msgs.append(
|
||||
Error(f'Timezone "{settings.TIME_ZONE}" is not a valid timezone'),
|
||||
)
|
||||
return msgs
|
||||
|
||||
return _ocrmypdf_settings_check() + _timezone_validate()
|
||||
|
Reference in New Issue
Block a user