def obtain_number(request):
    if (not request.user.is_authenticated):
        return HttpResponseRedirect(reverse('account:login'))
    config = None
    configs = TwilioConfig.objects.filter(user=request.user)
    if configs:
        config = TwilioConfig.objects.filter(user=request.user)[0]
        client = Client(config.sid, config.token)
        if (request.method == 'POST'):
            incoming_phone_number = client.incoming_phone_numbers.create(phone_number=request.POST['number'])
            return updateNumbers(request)
        else:
            local = client.available_phone_numbers('GB').local.list(contains='+44', limit=20)
            context = {'options': local}
            return render(request, 'obtain.html', context)
    else:
        return HttpResponseRedirect(reverse('twilioconfig:configure'))
def obtain_number(request):
    if (not request.user.is_authenticated):
        return HttpResponseRedirect(reverse('account:login'))
    config = None
    configs = TwilioConfig.objects.filter(user=request.user)
    if configs:
        config = TwilioConfig.objects.filter(user=request.user)[0]
        client = Client(config.sid, config.token)
        if (request.method == 'POST'):
            incoming_phone_number = client.incoming_phone_numbers.create(phone_number=request.POST['number'])
            return updateNumbers(request)
        else:
            local = client.available_phone_numbers('GB').local.list(contains='+44', limit=20)
            context = {'options': local}
            return render(request, 'obtain.html', context)
    else:
        return HttpResponseRedirect(reverse('twilioconfig:configure'))