2 A management command which deletes expired service tickets (e.g.,
5 Calls ``ServiceTickets.objects.delete_expired_users()``, which
6 contains the actual logic for determining which accounts are deleted.
9 from django.core.management.base import NoArgsCommand
10 from django.conf import settings
14 from cas_provider.models import ServiceTicket, LoginTicket
16 class Command(NoArgsCommand):
17 help = "Delete expired service tickets from the database"
19 def handle_noargs(self, **options):
20 print("Service tickets:")
21 tickets = ServiceTicket.objects.all()
22 for ticket in tickets:
23 expiration = datetime.timedelta(minutes=settings.CAS_TICKET_EXPIRATION)
24 if datetime.datetime.now() > ticket.created + expiration:
25 print("Deleting %s..." % ticket.ticket)
28 print("%s not expired..." % ticket.ticket)
29 tickets = LoginTicket.objects.all()
30 print("Login tickets:")
31 for ticket in tickets:
32 expiration = datetime.timedelta(minutes=settings.CAS_TICKET_EXPIRATION)
33 if datetime.datetime.now() > ticket.created + expiration:
34 print("Deleting %s..." % ticket.ticket)
37 print("%s not expired..." % ticket.ticket)