Exemplo n.º 1
0
Arquivo: views.py Projeto: m3ouf/test
def get_services(request):
    logger.debug("Getting (%s) services for user (%s), transaction id: (%s)",
                 request.GET['serviceType'].encode('utf-8').strip(),
                 request.GET['userName'].encode('utf-8').strip(),
                 request.GET['transactionId'].encode('utf-8').strip())
    form = ServiceForm(request.GET)
    if not form.is_valid():
        error_msg = ""
        for k, v in form.errors.items():
            error_msg += "%s: %s\n" % (k, ", ".join(v))
        return HttpResponse(json.dumps({
            'success': False,
            'msg': error_msg
        }),
                            content_type="application/json")
    pcrf_client = PCRFClient()
    result = pcrf_client.get_services(
        subscriber_id=form.cleaned_data['userName'],
        service_type=form.cleaned_data['serviceType'],
        start_date=form.cleaned_data.get('startDate'),
        end_date=form.cleaned_data.get('endDate'))

    response = {
        'success': result['action_result'],
        'msg': result.get('action_error_message'),
        'services': result.get('services')
    }
    log_action(inspect.stack()[0][3],
               request,
               response,
               transaction_id=request.GET['transactionId'])
    return HttpResponse(json.dumps(response), content_type="application/json")
Exemplo n.º 2
0
Arquivo: views.py Projeto: m3ouf/test
def get_profile(request):
    form = InputForm(request.GET)
    if not form.is_valid():
        error_msg = ""
        for k, v in form.errors.items():
            error_msg += "%s: %s\n" % (k, ", ".join(v))
        return HttpResponse(json.dumps({
            'success': False,
            'msg': error_msg
        }),
                            content_type="application/json")

    subscriber_id = form.cleaned_data['userName']
    transaction_id = form.cleaned_data['transactionId']
    free_quota = form.cleaned_data['freeQuota']

    pcrf_client = PCRFClient()
    profile_result = pcrf_client.get_profile(subscriber_id=subscriber_id,
                                             free_quota=free_quota)
    logger.debug("Getting profile for user (%s), transaction id: (%s)",
                 subscriber_id, transaction_id)
    if not profile_result['action_result']:
        response = {
            'success':
            True if profile_result.get('action_error_message').endswith(
                "does not exist") else profile_result['action_result'],
            'msg':
            profile_result.get('action_error_message'),
        }
        if 'not_exist' in profile_result:
            response['not_exist'] = profile_result['not_exist']
        log_action(inspect.stack()[0][3],
                   request,
                   response,
                   transaction_id=transaction_id)
        return HttpResponse(json.dumps(response),
                            content_type="application/json")

    topups_result = pcrf_client.get_services(subscriber_id,
                                             service_type='topup',
                                             free_quota=free_quota)

    response = {
        'success':
        True if topups_result.get('action_error_message',
                                  '').endswith("does not exist") else
        topups_result['action_result'],
        'msg':
        topups_result.get('action_error_message'),
        'profile':
        profile_result.get('profile'),
        'topups':
        topups_result.get('services')
    }

    log_action(inspect.stack()[0][3],
               request,
               response,
               transaction_id=transaction_id)
    return HttpResponse(json.dumps(response), content_type="application/json")