Exemple #1
0
def pnr_status(request):
    if request.method == "POST":
        pnr_no = request.POST.get('pnrno')
        notification_type = request.POST.get('notification_type')
        notification_type_value = request.POST.get('email_or_phone')
        notification_frequency = request.POST.get('notification_frequency')
        notification_frequency_value = request.POST.get('notifyValue')

        timenow = datetime.datetime.now()

        next_schedule_time =  timenow + caluclate_timedelta(notification_frequency,
                notification_frequency_value)

        pnr_no = pnr_no[:10]
        try:
            pnr_notify = PNRNotification.objects.get(pnr_no=pnr_no)
            pnr_notify.notification_type = notification_type
            pnr_notify.notification_type_value = notification_type_value
            pnr_notify.notification_frequency = notification_frequency
            pnr_notify.notification_frequency_value = notification_frequency_value
            pnr_notify.next_schedule_time = next_schedule_time
            pnr_notify.save()
        except PNRNotification.DoesNotExist:
            pnr_notify = PNRNotification.objects.create( pnr_no=pnr_no, notification_type=notification_type,
                notification_type_value=notification_type_value, notification_frequency=notification_frequency,
                notification_frequency_value=notification_frequency_value, next_schedule_time=next_schedule_time )

        pnr_status = get_pnr_status(pnr_notify)
        if not pnr_status.get('error'):
            send_pnr_notification(pnr_notify=pnr_notify, pnr_status_dict=pnr_status)
        return render(request, 'pnr_status.html', pnr_status)
    else:
        return HttpResponseRedirect('/')
Exemple #2
0
def send_pnr_notification(pnr_notify, pnr_status_dict):
    passengers = pnr_status_dict['passengers']
    notify_type = pnr_notify.notification_type
    pnr_notify.next_schedule_time = datetime.datetime.now() + caluclate_timedelta(
        pnr_notify.notification_frequency, pnr_notify.notification_frequency_value)
    pnr_notify.save()

    if pnr_status_dict['ticket_is_cancelled']:
        if notify_type == 'email':
            send_ticket_cancelled_email(passengers, pnr_notify)
        elif notify_type == 'phone':
            send_ticket_cancelled_sms(passengers, pnr_notify)
        pnr_notify.delete()
        return

    if pnr_status_dict['ticket_is_confirmed']:
        if notify_type == 'email':
            send_pnr_status_confirmed_email(passengers, pnr_notify)
        elif notify_type == 'phone':
            send_pnr_status_confirmed_sms(passengers, pnr_notify)
        pnr_notify.delete()
        return

    if pnr_status_dict['chart_prepared_for_ticket']:
        if notify_type == 'email':
            send_pnr_status_chart_prepared_email(passengers, pnr_notify)
        elif notify_type == 'phone':
            send_pnr_status_chart_prepared_sms(passengers, pnr_notify)
        pnr_notify.delete()
        return

    if pnr_notify.notification_type == 'email':
        send_pnr_status_email(passengers, pnr_notify)
    elif pnr_notify.notification_type == 'phone':
        send_pnr_status_sms(passengers, pnr_notify)