def profile_items(request): """Phoneuser Items Table""" #variables = Acl.get_permissions_for_user(request.user.id, request.user.is_staff) variables = {} items_per_page = settings.ITEMS_PER_PAGE keyword = request.GET.get("keyword", "") 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(last_name__icontains=keyword) q_obj.add(Q(username__icontains=keyword), Q.OR) items_list = User.objects.filter(q_obj).order_by('last_name').exclude(is_superuser=True) total_items = items_list.count() items, items_range, items_next_page = Helper.make_pagination( items_list, page, items_per_page) 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['query_string'] = urlencode(d) variables['d'] = d if request.is_ajax(): return render_to_response( 'profiles/table.html', RequestContext(request, variables)) return render_to_string( 'profiles/table.html', RequestContext(request, variables))
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))
def archive_records_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") archived_phoneuser_id = request.GET.get("archived_phoneuser_id", "") pincode = request.GET.get("pincode", "") 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 archived_phoneuser_id: q_obj.add(Q(archived_phoneuser_id=archived_phoneuser_id), Q.AND) 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 = ArchivedRecord.objects.filter(q_obj).order_by('-calldate') total_items = items_list.count() items, items_range, items_next_page = Helper.make_pagination( items_list, page, items_per_page) for item in items: try: details = ArchivedDetail.objects.filter(uniqueid=item.uniqueid) if not details: item.detail = Detail item.detail.custom_dst = '' else: item.detail = details[0] item.whitelist = ArchivedWhitelist.objects.get( archived_phoneuser_id=item.archived_phoneuser_id, phonenumber=item.detail.custom_dst) except Exception as e: pass # TODO gestire print "Errore nel recupero delle informazioni sulla chiamata" 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( 'archives/records/table.html', RequestContext(request, variables)) return render_to_string( 'archives/records/table.html', RequestContext(request, variables))
def archive_cdrs_items(request): 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", "") archived_phoneuser_id = request.GET.get("archived_phoneuser_id", "") 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) if archived_phoneuser_id: q_obj.add(Q(archived_phoneuser_id=archived_phoneuser_id), 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 = ArchivedDetail.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" try: item.whitelist = ArchivedWhitelist.objects.filter( archived_phoneuser=item.archived_phoneuser_id, phonenumber=item.custom_dst)[0] except Exception as e: pass # TODO gestire errore 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' # print "range: %s - next: %s" % (items_range, next_page) 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 variables['archived_phoneuser_id'] = archived_phoneuser_id if request.is_ajax(): return render_to_response( 'archives/cdrs/table.html', RequestContext(request, variables)) return render_to_string( 'archives/cdrs/table.html', RequestContext(request, variables))
def credit_items(request, phoneuser_id): items_per_page = int(settings.ITEMS_PER_PAGE) d = request.GET.dict() phoneuser_id = int(phoneuser_id) user = request.user variables = Acl.get_permissions_for_user(user.id, user.is_staff) items_list = Credit.objects.filter( phoneuser_id=phoneuser_id).order_by('-recharge_date') total_items = items_list.count() try: phoneuser = PhoneUser.objects.get(pk=phoneuser_id) except ObjectDoesNotExist: raise Http404 page = 1 if 'page' in d.keys(): page = int(d['page']) # elimino la pagina dal dizionario del d['page'] items, items_range, items_next_page = Helper.make_pagination( items_list, page, items_per_page) 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['balance'] = phoneuser.balance variables['phoneuser_id'] = phoneuser_id if request.is_ajax(): return render_to_response( 'phoneusers/credits/table.html', RequestContext(request, variables)) return render_to_string( 'phoneusers/credits/table.html', RequestContext(request, variables))
def audit_items(request): """CDR Items""" variables = {} items_per_page = 10 #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) keyword = request.GET.get("keyword", "") what = request.GET.get("what", "") 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(user__username__icontains=keyword) | Q(user__last_name__icontains=keyword) if what != '': q_obj.add(Q(what__icontains=what), 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(when__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(when__lte=end_date), Q.AND) items_list = Audit.objects.filter(q_obj).order_by('-when') total_items = items_list.count() items, items_range, items_next_page = Helper.make_pagination( items_list, page, items_per_page) 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['query_string'] = urlencode(d) variables['d'] = d if request.is_ajax(): return render_to_response( 'audits/table.html', RequestContext(request, variables)) return render_to_string( 'audits/table.html', RequestContext(request, variables))
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))