Skip to content

Commit

Permalink
Merge pull request #6 from JamesRitchie/default_settings
Browse files Browse the repository at this point in the history
Provide default settings
  • Loading branch information
JamesRitchie committed Oct 10, 2015
2 parents 708205e + 9e78810 commit 6aa23da
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
5 changes: 3 additions & 2 deletions rest_framework_expiring_authtoken/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
ExpiringToken
"""

from django.conf import settings
from django.utils import timezone

from rest_framework.authtoken.models import Token

from rest_framework_expiring_authtoken.settings import token_settings


class ExpiringToken(Token):

Expand All @@ -20,6 +21,6 @@ class Meta(object):
def expired(self):
"""Return boolean indicating token expiration."""
now = timezone.now()
if self.created < now - settings.EXPIRING_TOKEN_LIFESPAN:
if self.created < now - token_settings.EXPIRING_TOKEN_LIFESPAN:
return True
return False
29 changes: 29 additions & 0 deletions rest_framework_expiring_authtoken/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Provides access to settings.
Returns defaults if not set.
"""
from datetime import timedelta

from django.conf import settings


class TokenSettings(object):

"""Provides settings as defaults for working with tokens."""

@property
def EXPIRING_TOKEN_LIFESPAN(self):
"""
Return the allowed lifespan of a token as a TimeDelta object.
Defaults to 30 days.
"""
try:
val = settings.EXPIRING_TOKEN_LIFESPAN
except AttributeError:
val = timedelta(days=30)

return val

token_settings = TokenSettings()
2 changes: 0 additions & 2 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@
}

ROOT_URLCONF = 'tests.urls'

EXPIRING_TOKEN_LIFESPAN = timedelta(days=30)

0 comments on commit 6aa23da

Please sign in to comment.