Skip to content

Commit

Permalink
Update Enums
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvianen committed Jul 7, 2024
1 parent 037af2e commit 8b17289
Show file tree
Hide file tree
Showing 14 changed files with 648 additions and 223 deletions.
26 changes: 24 additions & 2 deletions src/django-lan/enums/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,35 @@
# =============================================================================

# Local enumeration modules

from .enum_authentication_type import AuthenticationTypeEnum
from .enum_device_role import DeviceRoleEnum
from .enum_device_status import DeviceStatusEnum
from .enum_device_type import DeviceTypeEnum
from .enum_interface_type import InterfaceTypeEnum
from .enum_ip_address_version import IPAddressVersionEnum
from .enum_logging_level import LoggingLevelEnum
from .enum_network_protocol_type import NetworkProtocolEnum
from .enum_port_status import PortStatusEnum
from .enum_security_level import SecurityLevelEnum
from .enum_traffic_type import TrafficTypeEnum
from .enum_vlan_status import VLANStatusEnum


# =============================================================================
# Public Interface
# =============================================================================

__all__ = [

"AuthenticationTypeEnum",
"DeviceRoleEnum",
"DeviceStatusEnum",
"DeviceTypeEnum",
"InterfaceTypeEnum",
"IPAddressVersionEnum",
"LoggingLevelEnum",
"NetworkProtocolEnum",
"PortStatusEnum",
"SecurityLevelEnum",
"TrafficTypeEnum",
"VLANStatusEnum",
]
64 changes: 55 additions & 9 deletions src/django-lan/enums/enum_authentication_type.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,60 @@
Authentication Type
# -*- coding: utf-8 -*-


# =============================================================================
# Docstring
# =============================================================================

"""
Provides Authentication Type Enum Class
=======================================
Enum for different authentication methods used in network security settings.
from enum import Enum
Links:
-
""" # noqa E501


# =============================================================================
# Import
# =============================================================================

# Import | Standard Library

# Import | Libraries
from django.utils.translation import gettext_lazy as _

# Import | Local Modules
from .enum_base import BaseEnum


# =============================================================================
# Classes
# =============================================================================

class AuthenticationTypeEnum(BaseEnum):
"""
Authentication Type Enum Class
==============================
"""

# Class | Enum Members
# =========================================================================

PASSWORD = _("Password")
PUBLIC_KEY = _("Public Key")
BIOMETRIC = _("Biometric")
TWO_FACTOR = _("Two Factor")


class AuthenticationType(Enum):
PASSWORD = 'Password'
PUBLIC_KEY = 'Public Key'
BIOMETRIC = 'Biometric'
TWO_FACTOR = 'Two Factor'
# =============================================================================
# Public Interface
# =============================================================================

def __str__(self):
return self.value
__all__ = [
"AuthenticationTypeEnum",
]
109 changes: 109 additions & 0 deletions src/django-lan/enums/enum_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# -*- coding: utf-8 -*-


# =============================================================================
# Docstring
# =============================================================================

"""
Provides Base Enum Class
========================
Provides a base class for all enumeration classes used in the project,
adding utility methods for integration with Django models, forms, and
serializers.
"""

# =============================================================================
# Import
# =============================================================================

# Import | Standard Library
from typing import List, Tuple
from enum import Enum

# Import | Libraries

# Import | Local Modules


# =============================================================================
# Classes
# =============================================================================

class BaseEnum(Enum):
"""
Base Enum Class
===============
A base class for all enumeration types, providing common functionality
needed for Django integration.
"""

def __str__(self) -> str:
"""
Return the user-friendly name of the enum member, enhancing its
usability in user interfaces.
Overrides the default string representation of Enum members to return
the value directly, making it more readable when used in user-facing
interfaces.
Returns:
str: The value of the enum member, ensuring that it is
user-friendly.
"""
try:
return self.value
except ValueError as e:
return str(e) # Log the error or handle it appropriately

@classmethod
def choices(cls) -> List[Tuple[str, str]]:
"""
Provides a list of tuple pairs suitable for use in Django model
field choices.
This class method facilitates the use of this enum in model fields,
forms, and serializers where choices need to be defined in the format
expected by Django.
Returns:
List[Tuple[str, str]]: A list of tuples, where each tuple
contains the enum member's name and value.
"""

return [(member.name, member.value) for member in cls]

@classmethod
def has_value(cls, value: str) -> bool:
"""
Checks if the given value is a valid member of the enum.
This utility method provides a simple way to validate if a provided
value matches any of the enum's values, enhancing validation logic
across your application.
Args:
value (str): The value to check against the enum's members.
Returns:
bool: True if the value is a member of the enum, False otherwise.
"""

# return value in cls._value2member_map_
return value in (member.value for member in cls)


# =============================================================================
# Public Interface
# =============================================================================

__all__ = [
"BaseEnum",
]
68 changes: 58 additions & 10 deletions src/django-lan/enums/enum_device_role.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,63 @@
Device Role
This enum defines roles for network devices, facilitating role-based configuration and actions.
# -*- coding: utf-8 -*-


# =============================================================================
# Docstring
# =============================================================================

from enum import Enum
"""
Provides Device Role Enum Class
===============================
class DeviceRole(Enum):
ROUTER = 'Router'
SWITCH = 'Switch'
ACCESS_POINT = 'Access Point'
BRIDGE = 'Bridge'
This enum defines roles for network devices, facilitating role-based
configuration and actions.
def __str__(self):
return self.value
Links:
-
""" # noqa E501


# =============================================================================
# Import
# =============================================================================

# Import | Standard Library

# Import | Libraries
from django.utils.translation import gettext_lazy as _

# Import | Local Modules
from .enum_base import BaseEnum


# =============================================================================
# Classes
# =============================================================================

class DeviceRoleEnum(BaseEnum):
"""
Device Role Enum Class
======================
"""

# Class | Enum Members
# =========================================================================

ROUTER = _("Router")
SWITCH = _("Switch")
ACCESS_POINT = _("Access Point")
BRIDGE = _("Bridge")

# Class | Methods
# =========================================================================


# =============================================================================
# Public Interface
# =============================================================================

__all__ = [
"DeviceRoleEnum",
]
41 changes: 29 additions & 12 deletions src/django-lan/enums/enum_device_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
# =============================================================================

"""
Provides IFC Change Action Enum Class
=====================================
Provides Device Status Enum Class
=================================
Define the possible statuses for network devices, such as active, inactive,
or under maintenance.
Links:
-
Network Device Status
Define the possible statuses for network devices, such as active, inactive, or under maintenance.
""" # noqa E501


Expand All @@ -19,24 +23,37 @@
# =============================================================================

# Import | Standard Library
from enum import Enum, auto

# Import | Libraries
from django.utils.translation import gettext_lazy as _

# Import | Local Modules
from .enum_base import BaseEnum


# =============================================================================
# Classes
# =============================================================================

from enum import Enum
class DeviceStatusEnum(BaseEnum):
"""
Device Status Enum Class
========================
"""

# Class | Enum Members
# =========================================================================

class NetworkDeviceStatus(Enum):
ACTIVE = 'active'
INACTIVE = 'inactive'
MAINTENANCE = 'maintenance'
ACTIVE = _("Active")
INACTIVE = _("Inactive")
MAINTENANCE = _("Maintenance")


# =============================================================================
# Public Interface
# =============================================================================

def __str__(self):
return self.value
__all__ = [
"DeviceStatusEnum",
]
Loading

0 comments on commit 8b17289

Please sign in to comment.