Exemple #1
0
def phoneuser_realtime_info(request):
    """Get call info for realtime displaying"""
    pincode = request.POST.get("data[pincode]", "")
    dst = request.POST.get("data[dst]", "")
    src = request.POST.get("data[src]", "")

    values = {
              'data': {},
              'err': 0,
              'err_msg': '',
              }

    values['data']['name'] = 'Non disponibile'
    values['data']['dst'] = 'Non disponibile'
    values['data']['src'] = 'Non disponibile'
    values['data']['recording'] = 'hidden'
    try:
        if pincode:
            phoneuser = PhoneUser.get_from_pincode(pincode)
            if phoneuser:
                values['data']['name'] = phoneuser.get_full_name()
                if phoneuser.recording_enabled:
                    values['data']['recording'] = 'progress'
                if dst:
                    whitelist = Whitelist.objects.get(phonenumber=dst, phoneuser_id=phoneuser.id)
                    values['data']['dst'] = "%s %s" % (dst, whitelist.label)
                    if whitelist.frequency == 1:
                        values['data']['recording'] = 'hidden'
                src_name = Extension.get_extension_name(src)
                if src_name:
                    values['data']['src_name'] = "%s (%s)" % (src_name, src)
                else:
                    values['data']['src_name'] = src

        return HttpResponse(json.dumps(values), content_type="application/json")

    except Exception as e:
        return HttpResponse(status=400, content=json.dumps({'err_msg': format(e)}), content_type='application/json')
Exemple #2
0
def record_items(request):
    """Record Items"""
    from urllib import urlencode
    variables = {}

    items_per_page = settings.ITEMS_PER_PAGE

    start_date = request.GET.get("start_date", "")
    end_date = request.GET.get("end_date", "")
    start_time = request.GET.get("start_time", "00:00")
    end_time = request.GET.get("end_time", "23:59")
    pincode = request.GET.get("pincode", "")
    dst = request.GET.get("dst", "")
    page = int(request.GET.get("page", "1"))
    d = request.GET.dict()

    page = 1
    if 'page' in d.keys():
        page = int(d['page'])
        # elimino la pagina dal dizionario
        del d['page']

    q_obj = Q(pincode__icontains=pincode)

    if start_date != '':
        start_date = Helper.convert_datestring_format(
            start_date, "%d-%m-%Y", "%Y-%m-%d")
        if start_time:
            start_time = "%s:00" % start_time
        else:
            start_time = "00:00:00"
        start_date = "%s %s" % (start_date, start_time)
        q_obj.add(Q(calldate__gte=start_date), Q.AND)

    if end_date != '':
        end_date = Helper.convert_datestring_format(
            end_date, "%d-%m-%Y", "%Y-%m-%d")
        if end_time:
            end_time = "%s:59" % end_time
        else:
            end_time = "23:59:59"
        end_date = "%s %s" % (end_date, end_time)
        q_obj.add(Q(calldate__lte=end_date), Q.AND)

    items_list = Record.objects.filter(q_obj).order_by('-calldate')

    if dst != '':
        filtered_item_list = []
        for item in items_list:
            try:
                detail = Detail.objects.get(uniqueid=item.uniqueid)
                if dst in detail.custom_dst:
                    filtered_item_list.append(item)
            except:
                pass
        items_list = filtered_item_list

    #total_items = items_list.count()
    total_items = len(items_list)

    items, items_range, items_next_page = Helper.make_pagination(
        items_list, page, items_per_page)

    for item in items:
        item.phoneuser = PhoneUser.get_from_pincode(item.pincode)
        try:
            details = Detail.objects.filter(uniqueid=item.uniqueid)
            if not details:
                item.detail = Detail
                item.detail.custom_dst = ''
            else:
                item.detail = details[0]
                src_name = Extension.get_extension_name(item.detail.custom_src)
                if src_name:
                    item.detail.custom_src = "%s (%s)" % (src_name, item.detail.custom_src)
            item.whitelist = Whitelist.objects.get(
                phoneuser_id=item.phoneuser.id, phonenumber=item.detail.custom_dst)
        except Exception as e:
            return redirect("/records/?err=1&err_msg=Impossibile caricare la lista dei record")

        if item.filename != '':
            item.filename = "/recordings/%s" % item.filename


    prev_page = page - 1
    prev_page_disabled = ''
    if prev_page < 1:
        prev_page = 1
        prev_page_disabled = 'disabled'

    next_page = 1
    next_page_disabled = ''
    if items:
        next_page = page + 1
        if next_page > items.paginator.num_pages:
            next_page = items.paginator.num_pages
            next_page_disabled = 'disabled'

    start_item = 1
    if page > 0:
        start_item = (page - 1) * items_per_page + 1
    end_item = start_item + items_per_page - 1
    if end_item > total_items:
        end_item = total_items

    variables['items'] = items
    variables['total_items'] = total_items
    variables['prev_page'] = prev_page
    variables['next_page'] = next_page
    variables['prev_page_disabled'] = prev_page_disabled
    variables['next_page_disabled'] = next_page_disabled
    variables['current_page'] = page
    variables['start_item'] = start_item
    variables['end_item'] = end_item
    variables['d'] = d
    variables['query_string'] = urlencode(d)

    if request.is_ajax():
        return render_to_response(
            'records/table.html', RequestContext(request, variables))

    return render_to_string(
        'records/table.html', RequestContext(request, variables))
Exemple #3
0
def cdr_items(request):
    """CDR Items"""
    variables = {}

    items_per_page = settings.ITEMS_PER_PAGE

    start_date = request.GET.get("start_date", "")
    end_date = request.GET.get("end_date", "")
    start_time = request.GET.get("start_time", None)
    end_time = request.GET.get("end_time", None)
    accountcode = request.GET.get("accountcode", "")
    dst = request.GET.get("dst", "")
    custom_calltype = request.GET.get("custom_calltype", None)
    page = int(request.GET.get("page", "1"))

    d = request.GET.dict()

    page = 1
    if 'page' in d.keys():
        page = int(d['page'])
        # elimino la pagina dal dizionario
        del d['page']

    q_obj = Q(accountcode__icontains=accountcode)
    q_obj.add(Q(custom_dst__icontains=dst), Q.AND)
    q_obj.add(Q(dcontext='cabs-dial-number')|Q(dcontext='outgoing-operator-dial-number')|Q(dcontext='incoming-operator-dial-number'), Q.AND)

    if start_date != '':
        start_date = Helper.convert_datestring_format(
            start_date, "%d-%m-%Y", "%Y-%m-%d")
        if start_time:
            start_time = "%s:00" % start_time
        else:
            start_time = "00:00:00"
        start_date = "%s %s" % (start_date, start_time)
        q_obj.add(Q(calldate__gte=start_date), Q.AND)

    if end_date != '':
        end_date = Helper.convert_datestring_format(
            end_date, "%d-%m-%Y", "%Y-%m-%d")
        if end_time:
            end_time = "%s:59" % end_time
        else:
            end_time = "23:59:59"
        end_date = "%s %s" % (end_date, end_time)
        q_obj.add(Q(calldate__lte=end_date), Q.AND)
        
    if custom_calltype:
        q_obj.add(Q(custom_calltype=custom_calltype), Q.AND)

    items_list = Detail.objects.filter(q_obj).order_by('-calldate')
    total_items = items_list.count()
    total_costs = 0.0

    # calcoliamo numero e costo complessivo
    for item in items_list:
        if float(item.price) > 0:
            total_costs += float(item.price)

    items, items_range, items_next_page = Helper.make_pagination(
        items_list, page, items_per_page)

    for item in items:
        if item.price < 0:
            item.price = "0.00"
            # cerchiamo di recuperare informazioni sul phoneuser
        item.phoneuser = PhoneUser.get_from_pincode(item.accountcode)
        try:
            item.whitelist = Whitelist.objects.filter(
                phoneuser_id=item.phoneuser.id, phonenumber=item.custom_dst)[0]
        except Exception as e:
            pass

        src_name = Extension.get_extension_name(item.custom_src)
        if src_name:
            item.custom_src = "%s (%s)" % (src_name, item.custom_src)

    prev_page = page - 1
    prev_page_disabled = ''
    if prev_page < 1:
        prev_page = 1
        prev_page_disabled = 'disabled'

    next_page = 1
    next_page_disabled = ''
    if items:
        next_page = page + 1
        if next_page > items.paginator.num_pages:
            next_page = items.paginator.num_pages
            next_page_disabled = 'disabled'
            
    start_item = 1
    if page > 0:
        start_item = (page - 1) * items_per_page + 1
    end_item = start_item + items_per_page - 1
    if end_item > total_items:
        end_item = total_items

    variables['items'] = items
    variables['total_costs'] = total_costs
    variables['total_items'] = total_items
    variables['prev_page'] = prev_page
    variables['next_page'] = next_page
    variables['prev_page_disabled'] = prev_page_disabled
    variables['next_page_disabled'] = next_page_disabled
    variables['current_page'] = page
    variables['start_item'] = start_item
    variables['end_item'] = end_item
    variables['query_string'] = urlencode(d)
    variables['d'] = d

    if request.is_ajax():
        return render_to_response(
            'cdrs/table.html', RequestContext(request, variables))

    return render_to_string(
        'cdrs/table.html', RequestContext(request, variables))