Exemple #1
0
def get_statistic(request, template):
    """
	Controller to get test calls file
	:param request: HTTP GET request
	:param template: html template
	:return: json format
	"""
    params = ApiParams(request.GET or None)

    update_res = PBXDataService.update_calls_list(params, request.user)
    logger.info(Code.UCLEXE,
                is_success=update_res.is_success,
                status_code=update_res.status_code,
                message=update_res.message,
                data=update_res.data)

    filter_params = CallsFilterParams(request.GET)
    calls = [
        CallRecord(call=call)
        for call in request.user.userprofile.call_set.filter(
            **filter_params.params).exclude(**filter_params.exclude_params).
        filter(filter_params.call_type_query).order_by('date')
    ]
    calls_stat = CallsStat(calls)

    # send_mail.apply_async((MailMessage(settings.INFO_EMAIL, 'Попытка обновления статы', 'mail_stat_updated.html', {'username': request.user.username}, request.user.email),), countdown=60)

    return render_to_response(template, {
        'calls': calls,
        'calls_stat': calls_stat
    },
                              context_instance=RequestContext(request))
Exemple #2
0
def request_callback(request):
	"""
	Request the callback
	:param request: HTTP request
	:return: HttpResponse instance
	"""
	from_number = CommonService.reduce_number(request.GET.get('cbFromNumber') or request.user.userprofile.sip)
	to_number = CommonService.reduce_number(request.GET.get('cbToNumber'))

	result = PBXDataService.request_callback(request.user, from_number, to_number)
	if result:
		return HttpResponse(status=200, content=result)

	return HttpResponse(status=500)
def profile_info_cash(context, cls, url):
	user = context['user']

	balance = PBXDataService.get_pbx_account_balance(user)

	return {
		'cash': {
			'cls': cls,
			'text_type': '',
			'title': '',
			'url': url,
			'icon': 'icon-credit-card',
			'value':  '%.2f руб.' % balance if balance else 'Баланс временно недоступен',
		}
	}
Exemple #4
0
def request_callback(request):
    """
	Request the callback
	:param request: HTTP request
	:return: HttpResponse instance
	"""
    from_number = CommonService.reduce_number(
        request.GET.get('cbFromNumber') or request.user.userprofile.sip)
    to_number = CommonService.reduce_number(request.GET.get('cbToNumber'))

    result = PBXDataService.request_callback(request.user, from_number,
                                             to_number)
    if result:
        return HttpResponse(status=200, content=result)

    return HttpResponse(status=500)
Exemple #5
0
def get_call_record(request):
	"""
	Controller to get test call record file
	:param request: HTTP GET request
	:return: wav file
	"""
	call_id = request.GET.get('call_id') or None
	if not call_id:
		return HttpResponse(status=400)

	file_instance = PBXDataService.get_call_record_file(call_id, request.user)
	if not file_instance:
		return HttpResponse(status=500)

	response = HttpResponse(content_type='audio/mp3')
	response['Content-Disposition'] = 'attachment; filename={filename}'.format(filename=file_instance.filename)
	response.content = file_instance.content
	return response
Exemple #6
0
def get_call_record(request):
    """
	Controller to get test call record file
	:param request: HTTP GET request
	:return: wav file
	"""
    call_id = request.GET.get('call_id') or None
    if not call_id:
        return HttpResponse(status=400)

    file_instance = PBXDataService.get_call_record_file(call_id, request.user)
    if not file_instance:
        return HttpResponse(status=500)

    response = HttpResponse(content_type='audio/mp3')
    response['Content-Disposition'] = 'attachment; filename={filename}'.format(
        filename=file_instance.filename)
    response.content = file_instance.content
    return response
Exemple #7
0
def get_statistic(request, template):
	"""
	Controller to get test calls file
	:param request: HTTP GET request
	:param template: html template
	:return: json format
	"""
	params = ApiParams(request.GET or None)

	update_res = PBXDataService.update_calls_list(params, request.user)
	logger.info(Code.UCLEXE, is_success=update_res.is_success, status_code=update_res.status_code, message=update_res.message, data=update_res.data)

	filter_params = CallsFilterParams(request.GET)
	calls = [CallRecord(call=call) for call in request.user.userprofile.call_set.filter(**filter_params.params).exclude(**filter_params.exclude_params).filter(filter_params.call_type_query).order_by('date')]
	calls_stat = CallsStat(calls)

	# send_mail.apply_async((MailMessage(settings.INFO_EMAIL, 'Попытка обновления статы', 'mail_stat_updated.html', {'username': request.user.username}, request.user.email),), countdown=60)

	return render_to_response(template, {'calls': calls, 'calls_stat': calls_stat}, context_instance=RequestContext(request))
Exemple #8
0
def get_call_cost(request):
	"""
	Request to the api to get call cost by target phone number
	:param request: HTTP request
	:return: HttpResponse Instance
	"""
	to = request.GET.get('n')
	if not to:
		return HttpResponse(status=400)

	if len(to) < 6:
		return JsonResponse({'phone': to, 'notAvalible': True})

	result = PBXDataService.get_call_cost(request.user, CommonService.reduce_number(to))
	if result:
		result['phone'] = to
		return JsonResponse(result)

	return HttpResponse(status=500)
Exemple #9
0
def get_call_cost(request):
    """
	Request to the api to get call cost by target phone number
	:param request: HTTP request
	:return: HttpResponse Instance
	"""
    to = request.GET.get('n')
    if not to:
        return HttpResponse(status=400)

    if len(to) < 6:
        return JsonResponse({'phone': to, 'notAvalible': True})

    result = PBXDataService.get_call_cost(request.user,
                                          CommonService.reduce_number(to))
    if result:
        result['phone'] = to
        return JsonResponse(result)

    return HttpResponse(status=500)
Exemple #10
0
	def sign_in(request):
		"""
		Authenticate and Sign in user by login and password
		:param request: HTTP request
		:return: True if the user was singed in
		"""
		form = AuthUserForm(request.POST)
		if form.errors:
			return ServiceResponse(False, form.errors)
		auth_user = authenticate(username=form.data['username'], password=form.data['password'])
		if auth_user is not None:

			if not auth_user.is_superuser and (not auth_user.last_login or not auth_user.userprofile.sip):
				auth_user.userprofile.sip = PBXDataService.get_pbx_sip(auth_user)
				auth_user.userprofile.save()

			login(request, auth_user)

			return ServiceResponse(True, data=auth_user)
		return ServiceResponse(False, {'username': ['Invalidusernameorpassword'], 'password': ['Invalidusernameorpassword']})
Exemple #11
0
def profile_info_cash(context, cls, url):
    user = context['user']

    balance = PBXDataService.get_pbx_account_balance(user)

    return {
        'cash': {
            'cls':
            cls,
            'text_type':
            '',
            'title':
            '',
            'url':
            url,
            'icon':
            'icon-credit-card',
            'value':
            '%.2f руб.' % balance if balance else 'Баланс временно недоступен',
        }
    }