2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-13 18:45:40 +00:00

Add generic StringEnum class (#9731)

* Add generic StringEnum class

* Fix import
This commit is contained in:
Oliver
2025-06-03 15:03:35 +10:00
committed by GitHub
parent 2f0a2b5abf
commit 6d47a0dd16
5 changed files with 24 additions and 25 deletions

View File

@ -4,7 +4,6 @@ These models are 'generic' and do not fit a particular business logic object.
"""
import base64
import enum
import hashlib
import hmac
import json
@ -47,6 +46,7 @@ import InvenTree.models
import InvenTree.ready
import users.models
from common.setting.type import InvenTreeSettingsKeyType, SettingsKeyType
from generic.enums import StringEnum
from generic.states import ColorEnum
from generic.states.custom import state_color_mappings
from InvenTree.cache import get_session_cache, set_session_cache
@ -2354,13 +2354,9 @@ class DataOutput(models.Model):
errors: JSON field for storing any errors generated during the data output generation process
"""
class DataOutputTypes(str, enum.Enum):
class DataOutputTypes(StringEnum):
"""Enum for data output types."""
def __str__(self):
"""Return the string representation of the data output type."""
return str(self.value)
LABEL = 'label'
REPORT = 'report'
EXPORT = 'export'

View File

@ -0,0 +1,15 @@
"""Generic enum type definitions."""
import enum
class StringEnum(str, enum.Enum):
"""Base class for string-based enumerations."""
def __str__(self):
"""Return the string representation of the enumeration value."""
return str(self.value)
def __repr__(self):
"""Return the string representation of the enumeration value."""
return str(self.value)

View File

@ -1,11 +1,7 @@
"""Generic event enumerations for InvenTree."""
import enum
from generic.enums import StringEnum
class BaseEventEnum(str, enum.Enum):
class BaseEventEnum(StringEnum):
"""Base class for representing a set of 'events'."""
def __str__(self):
"""Return the string representation of the event."""
return str(self.value)

View File

@ -1,6 +1,5 @@
"""Base Class for InvenTree plugins."""
import enum
import inspect
import warnings
from datetime import datetime
@ -16,18 +15,15 @@ from django.utils.translation import gettext_lazy as _
import structlog
import InvenTree.helpers
from generic.enums import StringEnum
from plugin.helpers import get_git_log
logger = structlog.get_logger('inventree')
class PluginMixinEnum(str, enum.Enum):
class PluginMixinEnum(StringEnum):
"""Enumeration of the available plugin mixin types."""
def __str__(self):
"""Return the string representation of the mixin."""
return self.value
BASE = 'base'
ACTION = 'action'

View File

@ -1,18 +1,14 @@
"""Ruleset definitions which control the InvenTree user permissions."""
import enum
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from generic.enums import StringEnum
class RuleSetEnum(str, enum.Enum):
class RuleSetEnum(StringEnum):
"""Enumeration of ruleset names."""
def __str__(self):
"""Return the string representation of the ruleset."""
return str(self.value)
ADMIN = 'admin'
PART_CATEGORY = 'part_category'
PART = 'part'