Ejemplo n.º 1
0
    def test_pending(self):
        # Check pending home page countso

        # Send a message to P1 so there is some data
        import transports
        transports.receive("P1 Connection", "Message Content")

        response = self.client.get(url.reverse("pending-list"))
        self.assertEqual(len(response.data), 8)
        self.assertEqual(response.data["messages"], 1)
        self.assertEqual(response.data["translations"], 1)

        response = self.client.get(url.reverse("pending-messages"))
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['text'], "Message Content")
Ejemplo n.º 2
0
def send_message(request):

    contact = None
    system = None
    participant_send_form = forms.ParticipantSendForm()
    system_send_form = forms.SystemSendForm()
    if request.POST:
        # multiple forms on the page so check the for the send button
        if request.POST.get("participant-send", False):
            participant_send_form = forms.ParticipantSendForm(request.POST)
            if participant_send_form.is_valid():
                identity = participant_send_form.cleaned_data["contact"].phone_number()
                text = participant_send_form.cleaned_data["text"]
                transports.receive(identity=identity, message=text)

                # reset form on valid
                participant_send_form = forms.ParticipantSendForm()

        elif request.POST.get("system-send", False):
            system_send_form = forms.SystemSendForm(request.POST)
            if system_send_form.is_valid():
                contact = participant_send_form.cleaned_data["contact"]
                text = participant_send_form.cleaned_data["text"]
                message = contact.send_message(text)

                # reset form on valid
                system_send_form = forms.SystemSendForm()

    return render(
        request,
        "transports/http/send_message.html",
        {
            "participant_form": participant_send_form,
            "contact": contact,
            "system_form": system_send_form,
            "system": system,
        },
    )
Ejemplo n.º 3
0
def send_message(request):

    contact = None
    system = None
    participant_send_form = forms.ParticipantSendForm()
    system_send_form = forms.SystemSendForm()
    if request.POST:
        #multiple forms on the page so check the for the send button
        if request.POST.get('participant-send', False):
            participant_send_form = forms.ParticipantSendForm(request.POST)
            if participant_send_form.is_valid():
                identity = participant_send_form.cleaned_data[
                    'contact'].phone_number()
                text = participant_send_form.cleaned_data['text']
                transports.receive(identity=identity, message_text=text)

                #reset form on valid
                participant_send_form = forms.ParticipantSendForm()

        elif request.POST.get('system-send', False):
            system_send_form = forms.SystemSendForm(request.POST)
            if system_send_form.is_valid():
                contact = system_send_form.cleaned_data['contact']
                text = system_send_form.cleaned_data['text']
                message = contact.send_message(text)

                #reset form on valid
                system_send_form = forms.SystemSendForm()

    return render(
        request, 'transports/http/send_message.html', {
            'participant_form': participant_send_form,
            'contact': contact,
            'system_form': system_send_form,
            'system': system
        })
Ejemplo n.º 4
0
    def handle(self, *args, **options):

        with open(options['file']) as fp:
            csv_reader = csv.reader(fp)
            csv_reader.next()  # skip header
            for row in csv_reader:
                kwargs = parse_incomming(row)
                message = transports.receive(kwargs['identity'],
                                             kwargs['text'],
                                             kwargs['external_id'],
                                             bulk=True)
                message.created = kwargs['created']
                message.save()
                print message.contact, message.created, message.text, kwargs[
                    'created'], row[0]
Ejemplo n.º 5
0
Archivo: views.py Proyecto: czue/mwachx
def receive(request):

	logger.debug('receive(): %s\n%s\n%s',request.method,request.META,request.POST)

	if request.method == 'POST' and can_submit(request):
		form = forms.AfricasTalkingForm(request.POST)
		if form.is_valid():
			message = transports.receive(
				identity=form.cleaned_data['from'],
				message_text=form.cleaned_data['text'],
				external_id=form.cleaned_data['id'],
				time_received=form.cleaned_data['date'],
				external_linkId=form.cleaned_data['linkId']
			)
			return render(request,'transports/africas_talking/test_receive.html',{'form':form})
	else: #GET request
		form = forms.AfricasTalkingForm()
	return render(request,'transports/africas_talking/test_receive.html',{'form':form})
Ejemplo n.º 6
0
def receive(request):

	logger.debug('receive(): %s\n%s\n%s',request.method,request.META,request.POST)

	if request.method == 'POST' and can_submit(request):
		form = forms.AfricasTalkingForm(request.POST)
		if form.is_valid():
			message = transports.receive(
				identity=form.cleaned_data['from'],
				message=form.cleaned_data['text'],
				external_id=form.cleaned_data['id'],
				time_received=form.cleaned_data['date'],
				external_linkId=form.cleaned_data['linkId']
			)
			return render(request,'transports/africas_talking/test_receive.html',{'form':form})
	else: #GET request
		form = forms.AfricasTalkingForm()
	return render(request,'transports/africas_talking/test_receive.html',{'form':form})