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('/')
def schedule_pnr_notification(pnr_notify): pnr_status_dict = get_pnr_status(pnr_notify, delete_on_fail=False) if pnr_status_dict.get('error'): return send_pnr_notification(pnr_notify=pnr_notify, pnr_status_dict=pnr_status_dict)