""" Core application enums declaration """ import re from enum import Enum, StrEnum from django.conf import global_settings, settings from django.db import models from django.utils.translation import gettext_lazy as _ ATTACHMENTS_FOLDER = "attachments" UUID_REGEX = ( r"[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}" ) FILE_EXT_REGEX = r"\.[a-zA-Z0-9]{1,10}" MEDIA_STORAGE_URL_PATTERN = re.compile( f"{settings.MEDIA_URL:s}(?P{UUID_REGEX:s})/" f"(?P{ATTACHMENTS_FOLDER:s}/{UUID_REGEX:s}(?:-unsafe)?{FILE_EXT_REGEX:s})$" ) MEDIA_STORAGE_URL_EXTRACT = re.compile( f"{settings.MEDIA_URL:s}({UUID_REGEX}/{ATTACHMENTS_FOLDER}/{UUID_REGEX}{FILE_EXT_REGEX})" ) # In Django's code base, `LANGUAGES` is set by default with all supported languages. # We can use it for the choice of languages which should not be limited to the few languages # active in the app. # pylint: disable=no-member ALL_LANGUAGES = {language: _(name) for language, name in global_settings.LANGUAGES} class MoveNodePositionChoices(models.TextChoices): """Defines the possible positions when moving a django-treebeard node.""" FIRST_CHILD = "first-child", _("First child") LAST_CHILD = "last-child", _("Last child") FIRST_SIBLING = "first-sibling", _("First sibling") LAST_SIBLING = "last-sibling", _("Last sibling") LEFT = "left", _("Left") RIGHT = "right", _("Right") class DocumentAttachmentStatus(StrEnum): """Defines the possible statuses for an attachment.""" PROCESSING = "processing" READY = "ready" class SearchType(str, Enum): """ Defines the possible search types for a document search query. - TITLE: DRF based search in the title of the documents only. - HYBRID and FULL_TEXT: more advanced search based on Find indexer. """ TITLE = "title" HYBRID = "hybrid" FULL_TEXT = "full-text" class FeatureFlag(str, Enum): """ Defines the possible feature flags for the application. """ FLAG_FIND_HYBRID_SEARCH = "flag_find_hybrid_search" FLAG_FIND_FULL_TEXT_SEARCH = "flag_find_full_text_search"