def answerphone(request): """Twiml application view which services incoming calls from Twilio.""" anonymous_user, created = User.objects.get_or_create(username="******") call_data_fields = ["From", "Called", "CallSid", "AccountSid"] blob = request.POST or request.GET incoming_data = {i: blob.get(i, None) for i in call_data_fields} incoming = urllib.parse.unquote(incoming_data['Called']).replace("+", "") twilio_number = TwilioNumber.objects.get(phone_number__icontains=incoming) asker = twilio_number.answerphone_script reply = Reply( asker=asker, external_id=incoming_data['CallSid'], user=anonymous_user, entry_method="answerphone" ) reply.save() # save some details of the call right away as Answers attached to the Reply answers = [Answer(reply=reply, other_variable_name=i, answer=j) for i, j in list(incoming_data.items())] [i.save() for i in answers] return play_twiml(request, first=True, external_id=incoming_data['CallSid'])
def use_adhoc_asker(request, membership_id, asker_id): asker = get_object_or_404(Asker, pk=asker_id) membership = get_object_or_404(Membership, pk=membership_id) reply = Reply(asker=asker, user=request.user, membership=membership, entry_method="ad_hoc",) reply.save() return HttpResponseRedirect(reverse('show_page', args=(reply.token,)))
def use_adhoc_asker(request, membership_id, asker_id): asker = get_object_or_404(Asker, pk=asker_id) membership = get_object_or_404(Membership, pk=membership_id) reply = Reply( asker=asker, user=request.user, membership=membership, entry_method="ad_hoc", ) reply.save() return HttpResponseRedirect(reverse('show_page', args=(reply.token, )))
def start_anonymous_survey(request, asker_id, collector=None): # todo - could add a study id here to attach this all to? Or perhaps use different usernames # as collectors, like surveymonkey? asker = get_object_or_404(Asker, pk=asker_id) anonymous_user, created = User.objects.get_or_create(username="******") reply = Reply(asker=asker, user=anonymous_user, redirect_to=request.GET.get('next', "/"), entry_method="anonymous", collector=collector) reply.save() return HttpResponseRedirect(reverse('show_page', args=(reply.token,)))
def start_anonymous_survey(request, asker_id, collector=None): # todo - could add a study id here to attach this all to? Or perhaps use different usernames # as collectors, like surveymonkey? asker = get_object_or_404(Asker, pk=asker_id) anonymous_user, created = User.objects.get_or_create( username="******") reply = Reply(asker=asker, user=anonymous_user, redirect_to=request.GET.get('next', "/"), entry_method="anonymous", collector=collector) reply.save() return HttpResponseRedirect(reverse('show_page', args=(reply.token, )))
def preview_asker(request, asker_id=None, page_num=None): page_num = int(page_num) or 0 a = get_object_or_404(Asker, id=asker_id) entry_method = page_num and "page_preview" or "preview" reply = Reply(asker=a, entry_method=entry_method, user=request.user) reply.save() reply.redirect_to = reverse('admin:signalbox_reply_change', args=(reply.id, )) reply.save() url = reverse('show_page', kwargs={'reply_token': reply.token }) + "?page={}".format(page_num) return HttpResponseRedirect(url)
def preview_asker(request, asker_id=None, page_num=None): page_num = int(page_num) or 0 a = get_object_or_404(Asker, id=asker_id) entry_method = page_num and "page_preview" or "preview" reply = Reply(asker=a, entry_method=entry_method, user=request.user) reply.save() reply.redirect_to = reverse('admin:signalbox_reply_change', args=(reply.id, )) reply.save() url = reverse('show_page', kwargs={'reply_token': reply.token}) + "?page={}".format(page_num) return HttpResponseRedirect(url)