forked from souen/django-locking
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Lock to its own model. This passes all relevant AppTestCase tests
Note: managers and associated tests are removed because they aren't relevant as managers. Maybe we should add them back as methods, that would filter on Lock instances ?
- Loading branch information
Showing
3 changed files
with
94 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +0,0 @@ | ||
import datetime | ||
from django.db.models import Q, Manager | ||
from django.conf import settings | ||
|
||
def point_of_timeout(): | ||
delta = datetime.timedelta(seconds=settings.LOCKING['time_until_expiration']) | ||
return datetime.datetime.now() - delta | ||
|
||
class LockedManager(Manager): | ||
def get_query_set(self): | ||
timeout = point_of_timeout() | ||
return super(LockedManager, self).get_query_set().filter(locked_at__gt=timeout, locked_at__isnull=False) | ||
|
||
class UnlockedManager(Manager): | ||
def get_query_set(self): | ||
timeout = point_of_timeout() | ||
return super(UnlockedManager, self).get_query_set().filter(Q(locked_at__lte=timeout) | Q(locked_at__isnull=True)) | ||
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