def match_or_send_to_waiting_room(call, schedule): # Refreshing database object flush_transaction() call.reload() if call.matched: other = call.conference.call_set.exclude(pk=call.pk)[0] data = send_to_conference_room(call, schedule, other, initial=False) if data: return data matchcall = find_match(schedule, call) if matchcall: conf = Conference() conf.maxcapacity = 2 conf.datecreated = as_date(schedule) conf.save() call.conference = conf call.matched = True call.save() matchcall.conference = conf matchcall.matched = True matchcall.save() data = send_to_conference_room(call, schedule, matchcall, initial=True) if data: return data if call.user.profile.any_match: call.user.profile.any_match = False call.user.profile.save() return render_to_response("twilioresponse.xml", { 'say' :"We are very sorry - We could not find you a match today, but tomorrow we'll do our best to compensate it! We wish you an awesome day!", 'hangup' : True }) #Check if we have exceeded the waiting redirect limits elif call.retries >= REDIRECT_LIMIT: # The user has reached the limit of redials, so hang up logger.debug("LIMIT RETRIES - Ask to try to match with any person") any_match = "We could not find any matches. If you'd like us to try to match you with Anyone please press any number now." goodbye = "We wish you an Amazing day! Good bye!" return render_to_response("twilioresponse.xml", { 'any_match' :any_match, 'schedule': schedule, 'hangup': True, 'goodbye' : goodbye }) call.retries = call.retries + 1 call.save() # Send user to private conference (Conferencename=Username) or send them to the waiting room they were at return send_to_waiting_room( HOLD_LIMIT , schedule , call.user.username , False , "Please bare with us - we'll find the best match for you!")
def get_active_waiting_room(schedule): dateSchedule = as_date(schedule) # Refreshing database flush_transaction() try: allWaitingRooms = Conference.objects.filter(datecreated=dateSchedule, maxcapacity=WAITING_ROOM_MAX) logger.debug("All waiting rooms: " + str(allWaitingRooms)) # Find free waiting room for waiting in allWaitingRooms: if waiting.available(): logger.debug("Waiting room chosen: " + str(waiting.pk)) return waiting # No free waiting rooms so create one except Conference.DoesNotExist: pass # None found, so create one waiting = Conference() waiting.datecreated = dateSchedule waiting.maxcapacity = WAITING_ROOM_MAX waiting.save() return waiting
def get_active_waiting_room(schedule): dateSchedule = as_date(schedule) # Refreshing database flush_transaction() try: allWaitingRooms = Conference.objects.filter( datecreated=dateSchedule, maxcapacity=WAITING_ROOM_MAX) logger.debug("All waiting rooms: " + str(allWaitingRooms)) # Find free waiting room for waiting in allWaitingRooms: if waiting.available(): logger.debug("Waiting room chosen: " + str(waiting.pk)) return waiting # No free waiting rooms so create one except Conference.DoesNotExist: pass # None found, so create one waiting = Conference() waiting.datecreated = dateSchedule waiting.maxcapacity = WAITING_ROOM_MAX waiting.save() return waiting
def match_or_send_to_waiting_room(call, schedule): # Refreshing database object flush_transaction() call.reload() if call.matched: other = call.conference.call_set.exclude(pk=call.pk)[0] data = send_to_conference_room(call, schedule, other, initial=False) if data: return data matchcall = find_match(schedule, call) if matchcall: conf = Conference() conf.maxcapacity = 2 conf.datecreated = as_date(schedule) conf.save() call.conference = conf call.matched = True call.save() matchcall.conference = conf matchcall.matched = True matchcall.save() data = send_to_conference_room(call, schedule, matchcall, initial=True) if data: return data if call.user.profile.any_match: call.user.profile.any_match = False call.user.profile.save() return render_to_response( "twilioresponse.xml", { 'say': "We are very sorry - We could not find you a match today, but tomorrow we'll do our best to compensate it! We wish you an awesome day!", 'hangup': True }) #Check if we have exceeded the waiting redirect limits elif call.retries >= REDIRECT_LIMIT: # The user has reached the limit of redials, so hang up logger.debug("LIMIT RETRIES - Ask to try to match with any person") any_match = "We could not find any matches. If you'd like us to try to match you with Anyone please press any number now." goodbye = "We wish you an Amazing day! Good bye!" return render_to_response( "twilioresponse.xml", { 'any_match': any_match, 'schedule': schedule, 'hangup': True, 'goodbye': goodbye }) call.retries = call.retries + 1 call.save() # Send user to private conference (Conferencename=Username) or send them to the waiting room they were at return send_to_waiting_room( HOLD_LIMIT, schedule, call.user.username, False, "Please bare with us - we'll find the best match for you!")