Exemplo n.º 1
0
 def test_get_data_for_bluetooth(self):
     #create new notification without saving
     notification = Notification()        
     notification.date = datetime(2010, 4, 4)
     notification.notification_type = NotificationType.objects.get(pk = 1)
     notification.bluetooth_mac_address = "00AA11BB22"
     notification.bluetooth_server_address = "123.456.789.1"
             
     output_data = notification.get_data_for_bluetooth()
     
     self.assertEquals(type(output_data), BluetoothOutputData)
     self.assertEquals(output_data.bluetooth_mac_address, "00AA11BB22")
     self.assertEquals(output_data.server_address, \
                       '123.456.789.1')
     self.assertEquals(type(output_data.data).__name__, "unicode") 
Exemplo n.º 2
0
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))