def obtainNewTicketForUser(userRequestingTicket): """ There is a non-zero probability that we may get a unqiueness violation here by generating the same random hash. However, the probability of this is so astronomically small, we choose to not account for it. Google it if you don't beleive me. """ ticket = Ticket(user=userRequestingTicket, ticket_hash=generateRandomHash()) ticket.save() return ticket
def obtainTicketForUser(userRequestingTicket): current_tickets = Ticket.objects.filter(user=userRequestingTicket) if current_tickets.exists(): ticket = current_tickets[0] if (datetime.now() - ticket.time_issued).days >= 1: ticket.ticket_hash=getUniqueRandHash() ticket.time_issued=datetime.now() ticket.save() return ticket else: newTicket = Ticket(user=userRequestingTicket, ticket_hash = getUniqueRandHash()) newTicket.save() return newTicket