def create_and_save_notification(self, way_of_communication, phone_number): self.create_notification(way_of_communication) patient = Patient() patient.phone_number = phone_number self.client.post(reverse('web_authenticate_phonenumber'), \ {'patient': patient}) return self.client.get(reverse("notifications_save"))
def set_session_variables_for_register(request): ''' session variables way_of_communication and patient are filled ''' woc = WayOfCommunication.objects.get(pk = request.POST['way_of_communication']) request.session['way_of_communication'] = woc patient = Patient() patient.phone_number = request.POST['phone_number'] request.session['patient'] = patient
def create_notification(request, notification_type_name = None): ''' Display the form and creates a new notification, but does not save it yet. Redirect to authentication if switched on ''' notification_type = NotificationType.objects. \ filter(name = notification_type_name)[0] nexturl = "" backurl = reverse('web_index') ways_of_communication = get_ways_of_communication( notification_type.notify_immediately) if request.method == "POST": data = deepcopy(request.POST) if notification_type.notify_immediately: data['date'] = date.today().strftime('%Y-%m-%d') + \ ' ' + DEFAULT_SEND_TIME else: data['date'] = data.get('date', '') + ' ' + DEFAULT_SEND_TIME form = NotificationValidationForm(data) woc = get_woc_by_id( request.POST['way_of_communication'] ) if not woc.can_send_immediately: form = NotificationValidationFormBluetooth(data) if form.is_valid(): notification = Notification() patient = Patient() if woc.can_send_immediately: patient.phone_number = form.cleaned_data['phone_number'] notification.date = form.cleaned_data['date'] notification.notification_type = notification_type notification.hospital = Hospital.get_current_hospital() notification.way_of_communication = \ form.cleaned_data['way_of_communication'] request.session['notification'] = notification request.session['patient'] = patient logger.info("Create notification via %s" % notification.way_of_communication.verbose_name) if notification.way_of_communication == get_woc('bluetooth'): return HttpResponseRedirect(reverse("web_list_devices") + \ "?next=" + reverse("notifications_send")) elif notification.way_of_communication.name in ('sms', 'voice' ): return redirect_to_authentication_or( reverse("notifications_save")) else: logger.error("Unknown way of communication selected.") raise Exception ("Unknown way of communication %s " \ %notification.way_of_communication.\ verbose_name + "(this is neither " + \ "bluetooth nor sms or voice)") else: logger.info("create_notification: Invalid form.") return render_to_response('notifications/create.html', locals(), context_instance=RequestContext(request))