|
1 | 1 | """ |
2 | 2 | State tracking functionality for django models |
3 | 3 | """ |
| 4 | +from __future__ import annotations |
| 5 | + |
4 | 6 | import inspect |
5 | | -from functools import partialmethod, wraps |
| 7 | +from functools import partialmethod |
| 8 | +from functools import wraps |
6 | 9 |
|
7 | | -import django |
8 | 10 | from django.apps import apps as django_apps |
9 | 11 | from django.db import models |
10 | 12 | from django.db.models import Field |
11 | 13 | from django.db.models.query_utils import DeferredAttribute |
12 | 14 | from django.db.models.signals import class_prepared |
13 | 15 |
|
14 | | -from django_fsm.signals import pre_transition, post_transition |
15 | | - |
| 16 | +from django_fsm.signals import post_transition |
| 17 | +from django_fsm.signals import pre_transition |
16 | 18 |
|
17 | 19 | __all__ = [ |
18 | 20 | "TransitionNotAllowed", |
@@ -240,26 +242,9 @@ def deconstruct(self): |
240 | 242 | return name, path, args, kwargs |
241 | 243 |
|
242 | 244 | def get_state(self, instance): |
243 | | - # The state field may be deferred. We delegate the logic of figuring |
244 | | - # this out and loading the deferred field on-demand to Django's |
245 | | - # built-in DeferredAttribute class. DeferredAttribute's instantiation |
246 | | - # signature changed over time, so we need to check Django version |
247 | | - # before proceeding to call DeferredAttribute. An alternative to this |
248 | | - # would be copying the latest implementation of DeferredAttribute to |
249 | | - # django_fsm, but this comes with the added responsibility of keeping |
250 | | - # the copied code up to date. |
251 | | - if django.VERSION[:3] >= (3, 0, 0): |
252 | | - return DeferredAttribute(self).__get__(instance) |
253 | | - elif django.VERSION[:3] >= (2, 1, 0): |
254 | | - return DeferredAttribute(self.name).__get__(instance) |
255 | | - elif django.VERSION[:3] >= (1, 10, 0): |
256 | | - return DeferredAttribute(self.name, model=None).__get__(instance) |
257 | | - else: |
258 | | - # The field was either not deferred (in which case we can return it |
259 | | - # right away) or ir was, but we are running on an unknown version |
260 | | - # of Django and we do not know the appropriate DeferredAttribute |
261 | | - # interface, and accessing the field will raise KeyError. |
262 | | - return instance.__dict__[self.name] |
| 245 | + # The state field may be deferred. We delegate the logic of figuring this out |
| 246 | + # and loading the deferred field on-demand to Django's built-in DeferredAttribute class. |
| 247 | + return DeferredAttribute(self).__get__(instance) |
263 | 248 |
|
264 | 249 | def set_state(self, instance, state): |
265 | 250 | instance.__dict__[self.name] = state |
|
0 commit comments