Skip to content

Commit

Permalink
Step 2
Browse files Browse the repository at this point in the history
  • Loading branch information
pfouque committed Nov 22, 2023
1 parent 12c4184 commit c7fcdc0
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions django_fsm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from __future__ import annotations

import inspect
from collections.abc import Callable
from collections.abc import Sequence
from functools import partialmethod
from functools import wraps
from typing import TYPE_CHECKING
from typing import Any
from typing import Callable

from django.apps import apps as django_apps
from django.db import models
Expand All @@ -35,6 +36,9 @@
]

if TYPE_CHECKING:
from django.contrib.auth.models import AbstractBaseUser
from django.utils.functional import _StrOrPromise

_Model = models.Model
else:
_Model = object
Expand Down Expand Up @@ -62,7 +66,16 @@ class ConcurrentTransition(Exception):


class Transition:
def __init__(self, method: Callable, source, target, on_error, conditions, permission, custom) -> None:
def __init__(
self,
method: Callable,
source: str | int | Sequence[str | int] | State,
target: str | int | State | None,
on_error: str | int | None,
conditions: list[Callable[[Any], bool]],
permission: str | Callable[[models.Model, AbstractBaseUser], bool] | None,
custom: dict[str, _StrOrPromise],
) -> None:
self.method = method
self.source = source
self.target = target
Expand Down Expand Up @@ -493,7 +506,15 @@ def save(self, *args, **kwargs):
self._update_initial_state()


def transition(field, source="*", target=None, on_error=None, conditions=[], permission=None, custom={}):
def transition(
field,
source: str | int | Sequence[str | int] | State = "*",
target: str | int | State | None = None,
on_error: str | int | None = None,
conditions: list[Callable[[Any], bool]] = [],
permission: str | Callable[[models.Model, AbstractBaseUser], bool] | None = None,
custom: dict[str, _StrOrPromise] = {},
):
"""
Method decorator to mark allowed transitions.
Expand Down

0 comments on commit c7fcdc0

Please sign in to comment.