-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
648 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.