# Path: feedhq/reader/models.py
# AUTH_TOKEN_DAYS = 7  # 1 week
# 
# class AuthToken(models.Model):
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('User'),
#                              related_name='auth_tokens',
#                              on_delete=models.CASCADE)
#     token = models.CharField(
#         _('Token'), max_length=300, db_index=True, unique=True,
#         default=default_token)
#     date_created = models.DateTimeField(_('Creation date'),
#                                         default=timezone.now)
#     client = models.CharField(_('Client'), max_length=1023, blank=True)
#     user_agent = models.TextField(_('User-Agent'), blank=True)
# 
#     def __str__(self):
#         return u'Token for {0}'.format(self.user)
# 
#     class Meta:
#         ordering = ('-date_created',)
# 
#     def delete(self):
#         super().delete()
#         cache.delete(self.cache_key)
# 
#     @property
#     def cache_key(self):
#         return 'reader_auth_token:{0}'.format(self.token)
# 
#     @property
#     def user_pk(self):
#         return self.user_id
# 
#     @property
#     def cache_value(self):
#         return cache.get(self.cache_key)
# 
#     @property
#     def preview(self):
#         return u'{0}…'.format(self.token[:8])


from datetime import timedelta
from django.utils import timezone
from ...models import AUTH_TOKEN_DAYS, AuthToken
from ....feeds.management.commands import SentryCommand




class Command(SentryCommand):
    """Updates the users' feeds"""

    def handle_sentry(self, *args, **kwargs):
        threshold = timezone.now() - timedelta(days=AUTH_TOKEN_DAYS)

# Path: feedhq/reader/models.py
# AUTH_TOKEN_DAYS = 7  # 1 week
# 
# class AuthToken(models.Model):
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('User'),
#                              related_name='auth_tokens',
#                              on_delete=models.CASCADE)
#     token = models.CharField(
#         _('Token'), max_length=300, db_index=True, unique=True,
#         default=default_token)
#     date_created = models.DateTimeField(_('Creation date'),
#                                         default=timezone.now)
#     client = models.CharField(_('Client'), max_length=1023, blank=True)
#     user_agent = models.TextField(_('User-Agent'), blank=True)
# 
#     def __str__(self):
#         return u'Token for {0}'.format(self.user)
# 
#     class Meta:
#         ordering = ('-date_created',)
# 
#     def delete(self):
#         super().delete()
#         cache.delete(self.cache_key)
# 
#     @property
#     def cache_key(self):
#         return 'reader_auth_token:{0}'.format(self.token)
# 
#     @property
#     def user_pk(self):
#         return self.user_id
# 
#     @property
#     def cache_value(self):
#         return cache.get(self.cache_key)
# 
#     @property
#     def preview(self):
#         return u'{0}…'.format(self.token[:8])


# Path: feedhq/reader/management/commands/delete_expired_tokens.py
from datetime import timedelta
from django.utils import timezone
from ...models import AUTH_TOKEN_DAYS, AuthToken
from ....feeds.management.commands import SentryCommand





class Command(SentryCommand):
    """Updates the users' feeds"""

    def handle_sentry(self, *args, **kwargs):
        threshold = timezone.now() - timedelta(days=AUTH_TOKEN_DAYS)

        AuthToken.objects.filter(date_created__lte=threshold).delete()