flows: enum to django TextChoices

This commit is contained in:
Jens Langhammer
2020-05-09 20:54:56 +02:00
parent 3456527f10
commit 8a6009c278
5 changed files with 62 additions and 21 deletions

View File

@ -11,7 +11,7 @@ from passbook.lib.models import UUIDModel
from passbook.policies.models import PolicyBindingModel
class FlowDesignation(Enum):
class FlowDesignation(models.TextChoices):
"""Designation of what a Flow should be used for. At a later point, this
should be replaced by a database entry."""
@ -20,13 +20,6 @@ class FlowDesignation(Enum):
RECOVERY = "recovery"
PASSWORD_CHANGE = "password_change" # nosec # noqa
@staticmethod
def as_choices() -> Tuple[Tuple[str, str]]:
"""Generate choices of actions used for database"""
return tuple(
(x, y.value) for x, y in getattr(FlowDesignation, "__members__").items()
)
class Stage(UUIDModel):
"""Stage is an instance of a component used in a flow. This can verify the user,
@ -56,7 +49,7 @@ class Flow(PolicyBindingModel, UUIDModel):
name = models.TextField()
slug = models.SlugField(unique=True)
designation = models.CharField(max_length=100, choices=FlowDesignation.as_choices())
designation = models.CharField(max_length=100, choices=FlowDesignation.choices)
stages = models.ManyToManyField(Stage, through="FlowStageBinding", blank=True)