Reuse the scope function in models.

This commit is contained in:
juanifioren 2015-03-20 14:38:28 -03:00
parent 8c458fb028
commit b7d4c4377d

View file

@ -5,6 +5,15 @@ from django.utils import timezone
from django.contrib.auth.models import User from django.contrib.auth.models import User
def scope_property():
def fget(self):
return self._scope.split()
def fset(self, value):
self._scope = ' '.join(value)
return locals()
class Client(models.Model): class Client(models.Model):
RESPONSE_TYPE_CHOICES = [ RESPONSE_TYPE_CHOICES = [
@ -42,14 +51,7 @@ class Code(models.Model):
expires_at = models.DateTimeField() expires_at = models.DateTimeField()
_scope = models.TextField(default='') _scope = models.TextField(default='')
scope = property(**scope_property())
def scope():
def fget(self):
return self._scope.split()
def fset(self, value):
self._scope = ' '.join(value)
return locals()
scope = property(**scope())
def has_expired(self): def has_expired(self):
return timezone.now() >= self.expires_at return timezone.now() >= self.expires_at
@ -63,14 +65,7 @@ class Token(models.Model):
expires_at = models.DateTimeField() expires_at = models.DateTimeField()
_scope = models.TextField(default='') _scope = models.TextField(default='')
scope = property(**scope_property())
def scope():
def fget(self):
return self._scope.split()
def fset(self, value):
self._scope = ' '.join(value)
return locals()
scope = property(**scope())
_id_token = models.TextField() _id_token = models.TextField()