Commit c14be685 by Ed Crewe

clean up old tickets

parent 3ae1396d
......@@ -5,6 +5,9 @@ from django.conf import settings
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django_cas.exceptions import CasTicketException, CasConfigException
# Ed Crewe - add in signals to delete old tickets
from django.db.models.signals import post_save
from datetime import datetime
class Tgt(models.Model):
username = models.CharField(max_length = 255, unique = True)
......@@ -54,3 +57,15 @@ def get_tgt_for(user):
return Tgt.objects.get(username = user.username)
except ObjectDoesNotExist:
raise CasTicketException("no ticket found for user " + user.username)
def delete_old_tickets(**kwargs):
""" Delete tickets if they are over 2 days old
kwargs = ['raw', 'signal', 'instance', 'sender', 'created']
"""
sender = kwargs.get('sender', None)
now = datetime.now()
expire = datetime(now.year, now.month, now.day - 3)
sender.objects.filter(created__lt=expire).delete()
post_save.connect(delete_old_tickets, sender=pgtIOU)
post_save.connect(delete_old_tickets, sender=Tgt)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment