コード例 #1
0
ファイル: views.py プロジェクト: thecocce/phonecab
def _multi_record_export_as_zip_file(request):
    "Esportazione multifile in formato zip"""
    import os
    import contextlib
    import zipfile

    d = request.GET.dict()
    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", "")

    q_obj = Q(pincode__icontains=pincode)

    if start_date != '':
        start_date = Helper.convert_datestring_format(
            start_date, "%d-%m-%Y", "%Y-%m-%d")
        start_date = "%s %s:00" % (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")
        end_date = "%s %s:59" % (end_date, end_time)
        q_obj.add(Q(calldate__lte=end_date), Q.AND)

    items_list = Record.objects.filter(q_obj).order_by('-calldate')
    
    filename = 'registrazioni'
    if pincode != '':
        phoneuser = PhoneUser.get_from_pincode(pincode)
        filename = 'registrazioni %s' % phoneuser
    zipname = "%s.zip" % filename
    tmpzippath = os.path.join(settings.TMP_ZIP_ROOT, zipname)
    file_counter = 0
    with contextlib.closing(zipfile.ZipFile(tmpzippath, 'w')) as myzip:
        for item in items_list:
            
            detail = Detail.objects.get(uniqueid=item.uniqueid) 
            if detail.custom_valid and (detail.dcontext == 'cabs-dial-number' or detail.dcontext == 'outgoing-operator-dial-number' or detail.dcontext == 'incoming-operator-dial-number'):
                file_counter += 1
                path = os.path.join(settings.RECORDS_ROOT, item.filename)
                myzip.write(path, arcname = item.filename)
        
    if not file_counter:
        return redirect("/records/?err=1&err_msg=Nessuno dei file soddisfa i criteri per l'esportazione&%s" % urlencode(d))

    response = Helper.file_export(tmpzippath)

    # logghiamo azione
    audit = Audit()
    audit.user_id = request.user.id
    detail = Helper.get_filter_detail(d)
    audit.what = "Esportazione registrazioni corrispondenti ai seguenti criteri: %s" \
                            % (detail)
    audit.save()

    return response
コード例 #2
0
ファイル: views.py プロジェクト: thecocce/phonecab
def phoneuser_name(request, accountcode):
    """Get phoneuser name for realtime displaying"""
    values = {
              'data': {},
              'err': 0,
              'err_msg': '',
              }

    values['data']['name'] = 'Non disponibile'
    values['data']['recording'] = False
    if accountcode:
        phoneuser = PhoneUser.get_from_pincode(accountcode)
        if phoneuser:
            values['data']['name'] = phoneuser.get_full_name()
            values['data']['recording'] = phoneuser.recording_enabled
    else:
        values['err'] = 1
        values['err_msg'] = 'Errore phoneuser_name'

    return HttpResponse(json.dumps(values), content_type="application/json")
コード例 #3
0
ファイル: views.py プロジェクト: thecocce/phonecab
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')
コード例 #4
0
ファイル: views.py プロジェクト: thecocce/phonecab
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))
コード例 #5
0
ファイル: views.py プロジェクト: thecocce/phonecab
def phoneuser_save(request):
    """Save or update user"""
    phoneuser_id = int(request.POST.get("data[phoneuser_id]", "0"))
    enabled = int(request.POST.get("data[enabled]", "0"))
    first_name = request.POST.get("data[first_name]", "")
    last_name = request.POST.get("data[last_name]", "")
    serial_no = request.POST.get("data[serial_no]", "")
    pincode = request.POST.get("data[pincode]", "")
    four_bis_limited = int(request.POST.get("data[four_bis_limited]", "0"))
    listening_enabled = int(request.POST.get("data[listening_enabled]", "0"))
    recording_enabled = int(request.POST.get("data[recording_enabled]", "0"))
    language = request.POST.get("data[language]", "")
    vipaccount = int(request.POST.get("data[vipaccount]", "0"))

    variables = Acl.get_permissions_for_user(request.user.id, request.user.is_staff)
    is_new = False
    action = "Creazione"
    try:
        if phoneuser_id:
            phoneuser = PhoneUser.objects.get(pk=phoneuser_id)
            action = "Modifica"
        else:
            phoneuser = PhoneUser()
            is_new = True

        phoneuser.enabled = enabled
        phoneuser.first_name = first_name.title()
        phoneuser.last_name = last_name.title()
        phoneuser.serial_no = serial_no
        phoneuser.pincode = pincode
        phoneuser.four_bis_limited = four_bis_limited
        phoneuser.listening_enabled = listening_enabled
        phoneuser.recording_enabled = recording_enabled
        phoneuser.language = language
        phoneuser.vipaccount = vipaccount

        phoneuser.save()

        # log azione
        audit = Audit()
        audit.log(user=request.user,
            what="%s anagrafica: %s" % (action, phoneuser))
        
        if is_new:
            return phoneuser_items(request)
        variables['phoneuser'] = phoneuser
        return render_to_response(
            'phoneusers/phoneuser_data.html', RequestContext(request, variables))
    except Exception as e:
        return HttpResponse(status=400, content=json.dumps({'err_msg': format(e)}), content_type='application/json')
コード例 #6
0
ファイル: views.py プロジェクト: thecocce/phonecab
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))