def voip_daily_report(self, request): opts = VoIPCall._meta kwargs = {} if request.method == 'POST': form = VoipSearchForm(request.user, request.POST) kwargs = voipcall_record_common_fun(request) else: kwargs = voipcall_record_common_fun(request) tday = datetime.today() form = VoipSearchForm(request.user, initial={ "from_date": tday.strftime("%Y-%m-%d"), "to_date": tday.strftime("%Y-%m-%d") }) if len(kwargs) == 0: kwargs['starting_date__gte'] = datetime( tday.year, tday.month, tday.day, 0, 0, 0, 0) select_data = { "starting_date": "SUBSTR(CAST(starting_date as CHAR(30)),1,10)" } # Get Total Records from VoIPCall Report table for Daily Call Report total_data = VoIPCall.objects.extra(select=select_data)\ .values('starting_date')\ .filter(**kwargs)\ .annotate(Count('starting_date'))\ .annotate(Sum('duration'))\ .annotate(Avg('duration'))\ .order_by('-starting_date') # Following code will count total voip calls, duration if total_data: max_duration = max([x['duration__sum'] for x in total_data]) total_duration = sum([x['duration__sum'] for x in total_data]) total_calls = sum([x['starting_date__count'] for x in total_data]) total_avg_duration = (sum([x['duration__avg'] for x in total_data])) / total_calls else: max_duration = 0 total_duration = 0 total_calls = 0 total_avg_duration = 0 ctx = RequestContext( request, { 'form': form, 'total_data': total_data, 'total_duration': total_duration, 'total_calls': total_calls, 'total_avg_duration': total_avg_duration, 'max_duration': max_duration, 'opts': opts, 'model_name': opts.object_name.lower(), 'app_label': APP_LABEL, 'title': _('call aggregate report'), }) return render_to_response('admin/dialer_cdr/voipcall/voip_report.html', context_instance=ctx)
def voip_daily_report(self, request): opts = VoIPCall._meta kwargs = {} if request.method == "POST": form = AdminVoipSearchForm(request.POST) kwargs = voipcall_record_common_fun(request) else: kwargs = voipcall_record_common_fun(request) tday = datetime.today() form = AdminVoipSearchForm( initial={"from_date": tday.strftime("%Y-%m-%d"), "to_date": tday.strftime("%Y-%m-%d")} ) if len(kwargs) == 0: kwargs["starting_date__gte"] = datetime(tday.year, tday.month, tday.day, 0, 0, 0, 0).replace(tzinfo=utc) select_data = {"starting_date": "SUBSTR(CAST(starting_date as CHAR(30)),1,10)"} # Get Total Records from VoIPCall Report table for Daily Call Report total_data = ( VoIPCall.objects.extra(select=select_data) .values("starting_date") .filter(**kwargs) .annotate(Count("starting_date")) .annotate(Sum("duration")) .annotate(Avg("duration")) .order_by("-starting_date") ) # Following code will count total voip calls, duration if total_data: max_duration = max([x["duration__sum"] for x in total_data]) total_duration = sum([x["duration__sum"] for x in total_data]) total_calls = sum([x["starting_date__count"] for x in total_data]) total_avg_duration = (sum([x["duration__avg"] for x in total_data])) / total_calls else: max_duration = 0 total_duration = 0 total_calls = 0 total_avg_duration = 0 ctx = RequestContext( request, { "form": form, "total_data": total_data, "total_duration": total_duration, "total_calls": total_calls, "total_avg_duration": total_avg_duration, "max_duration": max_duration, "opts": opts, "model_name": opts.object_name.lower(), "app_label": APP_LABEL, "title": _("call aggregate report"), }, ) return render_to_response("admin/dialer_cdr/voipcall/voip_report.html", context_instance=ctx)
def voip_daily_report(self, request): opts = VoIPCall._meta kwargs = {} if request.method == 'POST': form = VoipSearchForm(request.user, request.POST) kwargs = voipcall_record_common_fun(request) else: kwargs = voipcall_record_common_fun(request) tday = datetime.today() form = VoipSearchForm(request.user, initial={"from_date": tday.strftime("%Y-%m-%d"), "to_date": tday.strftime("%Y-%m-%d")}) if len(kwargs) == 0: kwargs['starting_date__gte'] = datetime(tday.year, tday.month, tday.day, 0, 0, 0, 0) select_data = {"starting_date": "SUBSTR(CAST(starting_date as CHAR(30)),1,10)"} # Get Total Records from VoIPCall Report table for Daily Call Report total_data = VoIPCall.objects.extra(select=select_data)\ .values('starting_date')\ .filter(**kwargs)\ .annotate(Count('starting_date'))\ .annotate(Sum('duration'))\ .annotate(Avg('duration'))\ .order_by('-starting_date') # Following code will count total voip calls, duration if total_data: max_duration = max([x['duration__sum'] for x in total_data]) total_duration = sum([x['duration__sum'] for x in total_data]) total_calls = sum([x['starting_date__count'] for x in total_data]) total_avg_duration = (sum([x['duration__avg'] for x in total_data])) / total_calls else: max_duration = 0 total_duration = 0 total_calls = 0 total_avg_duration = 0 ctx = RequestContext(request, { 'form': form, 'total_data': total_data, 'total_duration': total_duration, 'total_calls': total_calls, 'total_avg_duration': total_avg_duration, 'max_duration': max_duration, 'opts': opts, 'model_name': opts.object_name.lower(), 'app_label': APP_LABEL, 'title': _('call aggregate report'), }) return render_to_response('admin/dialer_cdr/voipcall/voip_report.html', context_instance=ctx)
def changelist_view(self, request, extra_context=None): """ Override changelist_view method of django-admin for search parameters **Attributes**: * ``form`` - VoipSearchForm * ``template`` - admin/dialer_cdr/voipcall/change_list.html **Logic Description**: * VoIP report Record Listing with search option & Daily Call Report search Parameters: by date, by status and by billed. """ opts = VoIPCall._meta query_string = '' form = VoipSearchForm(request.user) if request.method == 'POST': # Session variable get record set with searched option into export file request.session['admin_voipcall_record_kwargs'] = voipcall_record_common_fun(request) query_string = voipcall_search_admin_form_fun(request) return HttpResponseRedirect("/admin/%s/%s/?%s" % (opts.app_label, opts.object_name.lower(), query_string)) else: status = '' from_date = '' to_date = '' campaign_id = '' from_date = getvar(request, 'starting_date__gte') to_date = getvar(request, 'starting_date__lte')[0:10] status = getvar(request, 'disposition__exact') campaign_id = getvar(request, 'callrequest__campaign_id') form = VoipSearchForm(request.user, initial={'status': status, 'from_date': from_date, 'to_date': to_date, 'campaign_id': campaign_id}) ChangeList = self.get_changelist(request) try: cl = ChangeList(request, self.model, self.list_display, self.list_display_links, self.list_filter, self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_max_show_all, self.list_editable, self) except IncorrectLookupParameters: if ERROR_FLAG in request.GET.keys(): return render_to_response('admin/invalid_setup.html', {'title': _('Database error')}) return HttpResponseRedirect('%s?%s=1' % (request.path, ERROR_FLAG)) if request.META['QUERY_STRING'] == '': # Default # Session variable get record set with searched option into export file request.session['admin_voipcall_record_kwargs'] = voipcall_record_common_fun(request) query_string = voipcall_search_admin_form_fun(request) return HttpResponseRedirect("/admin/%s/%s/?%s" % (opts.app_label, opts.object_name.lower(), query_string)) cl.formset = None selection_note_all = ungettext('%(total_count)s selected', 'All %(total_count)s selected', cl.result_count) ctx = { 'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)}, 'selection_note_all': selection_note_all % {'total_count': cl.result_count}, 'cl': cl, 'form': form, 'opts': opts, 'model_name': opts.object_name.lower(), 'app_label': APP_LABEL, 'title': _('call report'), } return super(VoIPCallAdmin, self).changelist_view(request, extra_context=ctx)
def voip_report(self, request): opts = VoIPCall._meta app_label = opts.app_label kwargs = {} form = VoipSearchForm() if request.method == 'POST': form = VoipSearchForm(request.POST) kwargs = voipcall_record_common_fun(request) request.session['from_date'] = request.POST.get('from_date') request.session['to_date'] = request.POST.get('to_date') request.session['status'] = request.POST.get('status') else: kwargs = voipcall_record_common_fun(request) tday = datetime.today() if len(kwargs) == 0: kwargs['starting_date__gte'] = datetime( tday.year, tday.month, tday.day, 0, 0, 0, 0) select_data = \ {"starting_date": "SUBSTR(CAST(starting_date as CHAR(30)),1,10)"} total_data = '' # Get Total Records from VoIPCall Report table for Daily Call Report total_data = VoIPCall.objects.extra(select=select_data)\ .values('starting_date')\ .filter(**kwargs).annotate(Count('starting_date'))\ .annotate(Sum('duration'))\ .annotate(Avg('duration'))\ .order_by('-starting_date') # Following code will count total voip calls, duration if total_data.count() != 0: max_duration = \ max([x['duration__sum'] for x in total_data]) total_duration = \ sum([x['duration__sum'] for x in total_data]) total_calls = \ sum([x['starting_date__count'] for x in total_data]) total_avg_duration = \ (sum([x['duration__avg']\ for x in total_data])) / total_data.count() else: max_duration = 0 total_duration = 0 total_calls = 0 total_avg_duration = 0 ctx = RequestContext( request, { 'form': form, 'total_data': total_data.reverse(), 'total_duration': total_duration, 'total_calls': total_calls, 'total_avg_duration': total_avg_duration, 'max_duration': max_duration, 'opts': opts, 'model_name': opts.object_name.lower(), 'app_label': _('VoIP Report'), 'title': _('Call Aggregate Report'), }) return render_to_response('admin/dialer_cdr/voipcall/voip_report.html', context_instance=ctx)
def voip_report(self, request): opts = VoIPCall._meta app_label = opts.app_label kwargs = {} form = VoipSearchForm() if request.method == 'POST': form = VoipSearchForm(request.POST) kwargs = voipcall_record_common_fun(request) request.session['from_date'] = request.POST.get('from_date') request.session['to_date'] = request.POST.get('to_date') request.session['status'] = request.POST.get('status') else: kwargs = voipcall_record_common_fun(request) tday = datetime.today() if len(kwargs) == 0: kwargs['starting_date__gte'] = datetime(tday.year, tday.month, tday.day, 0, 0, 0, 0) select_data = \ {"starting_date": "SUBSTR(CAST(starting_date as CHAR(30)),1,10)"} total_data = '' # Get Total Records from VoIPCall Report table for Daily Call Report total_data = VoIPCall.objects.extra(select=select_data)\ .values('starting_date')\ .filter(**kwargs).annotate(Count('starting_date'))\ .annotate(Sum('duration'))\ .annotate(Avg('duration'))\ .order_by('-starting_date') # Following code will count total voip calls, duration if total_data.count() != 0: max_duration = \ max([x['duration__sum'] for x in total_data]) total_duration = \ sum([x['duration__sum'] for x in total_data]) total_calls = sum([x['starting_date__count'] for x in total_data]) total_avg_duration = \ (sum([x['duration__avg']\ for x in total_data])) / total_data.count() else: max_duration = 0 total_duration = 0 total_calls = 0 total_avg_duration = 0 ctx = RequestContext(request, { 'form': form, 'total_data': total_data.reverse(), 'total_duration': total_duration, 'total_calls': total_calls, 'total_avg_duration': total_avg_duration, 'max_duration': max_duration, 'opts': opts, 'model_name': opts.object_name.lower(), 'app_label': _('VoIP Report'), 'title': _('Call Aggregate Report'), }) return render_to_response('admin/dialer_cdr/voipcall/voip_report.html', context_instance=ctx)
def changelist_view(self, request, extra_context=None): """ Override changelist_view method of django-admin for search parameters **Attributes**: * ``form`` - AdminVoipSearchForm * ``template`` - admin/dialer_cdr/voipcall/change_list.html **Logic Description**: * VoIP report Record Listing with search option & Daily Call Report search Parameters: by date, by status and by billed. """ opts = VoIPCall._meta query_string = '' form = AdminVoipSearchForm() if request.method == 'POST': # Session variable get record set with searched option into export file request.session['admin_voipcall_record_kwargs'] = voipcall_record_common_fun(request) query_string = voipcall_search_admin_form_fun(request) return HttpResponseRedirect("/admin/%s/%s/?%s" % (opts.app_label, opts.object_name.lower(), query_string)) else: disposition = '' from_date = '' to_date = '' campaign_id = '' leg_type = '' from_date = getvar(request, 'starting_date__gte') to_date = getvar(request, 'starting_date__lte')[0:10] disposition = getvar(request, 'disposition__exact') campaign_id = getvar(request, 'callrequest__campaign_id') leg_type = getvar(request, 'leg_type__exact') form = AdminVoipSearchForm(initial={'disposition': disposition, 'from_date': from_date, 'to_date': to_date, 'campaign_id': campaign_id, 'leg_type': leg_type}) ChangeList = self.get_changelist(request) try: cl = ChangeList(request, self.model, self.list_display, self.list_display_links, self.list_filter, self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_max_show_all, self.list_editable, self) except IncorrectLookupParameters: if ERROR_FLAG in request.GET.keys(): return render_to_response('admin/invalid_setup.html', {'title': _('Database error')}) return HttpResponseRedirect('%s?%s=1' % (request.path, ERROR_FLAG)) if request.META['QUERY_STRING'] == '': # Default # Session variable get record set with searched option into export file request.session['admin_voipcall_record_kwargs'] = voipcall_record_common_fun(request) query_string = voipcall_search_admin_form_fun(request) return HttpResponseRedirect("/admin/%s/%s/?%s" % (opts.app_label, opts.object_name.lower(), query_string)) cl.formset = None selection_note_all = ungettext('%(total_count)s selected', 'All %(total_count)s selected', cl.result_count) ctx = { 'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)}, 'selection_note_all': selection_note_all % {'total_count': cl.result_count}, 'cl': cl, 'form': form, 'opts': opts, 'model_name': opts.object_name.lower(), 'app_label': APP_LABEL, 'title': _('call report'), } return super(VoIPCallAdmin, self).changelist_view(request, extra_context=ctx)
def voipcall_report(request): """VoIP Call Report **Attributes**: * ``form`` - VoipSearchForm * ``template`` - frontend/report/voipcall_report.html **Logic Description**: * Get VoIP call list according to search parameters for loggedin user **Important variable**: * ``request.session['voipcall_record_qs']`` - stores voipcall query set """ kwargs = {} kwargs['user'] = request.user from_date = '' to_date = '' disposition = variable_value(request, 'status') form = VoipSearchForm() if request.method == 'POST': if request.POST['from_date'] != "": from_date = request.POST['from_date'] if request.POST['to_date'] != "": to_date = request.POST['to_date'] form = VoipSearchForm(request.POST) kwargs = voipcall_record_common_fun(request) else: tday = datetime.today() kwargs['starting_date__gte'] = datetime(tday.year, tday.month, tday.day, 0, 0, 0, 0) voipcall_list = \ VoIPCall.objects.values('user', 'callid', 'callerid', 'phone_number', 'starting_date', 'duration', 'billsec', 'disposition', 'hangup_cause', 'hangup_cause_q850', 'used_gateway').filter(**kwargs).order_by('-starting_date') # Session variable is used to get record set with searched option # into export file request.session['voipcall_record_qs'] = voipcall_list select_data = \ {"starting_date": "SUBSTR(CAST(starting_date as CHAR(30)),1,10)"} total_data = '' # Get Total Rrecords from VoIPCall Report table for Daily Call Report total_data = VoIPCall.objects.extra(select=select_data)\ .values('starting_date')\ .filter(**kwargs).annotate(Count('starting_date'))\ .annotate(Sum('duration'))\ .annotate(Avg('duration'))\ .order_by('-starting_date') # Following code will count total voip calls, duration if total_data.count() != 0: max_duration = \ max([x['duration__sum'] for x in total_data]) total_duration = \ sum([x['duration__sum'] for x in total_data]) total_calls = sum([x['starting_date__count'] for x in total_data]) total_avg_duration = \ (sum([x['duration__avg']\ for x in total_data])) / total_data.count() else: max_duration = 0 total_duration = 0 total_calls = 0 total_avg_duration = 0 template = 'frontend/report/voipcall_report.html' data = { 'form': form, 'from_date': from_date, 'to_date': to_date, 'disposition': disposition, 'total_data': total_data.reverse(), 'total_duration': total_duration, 'total_calls': total_calls, 'total_avg_duration': total_avg_duration, 'max_duration': max_duration, 'module': current_view(request), 'notice_count': notice_count(request), 'dialer_setting_msg': user_dialer_setting_msg(request.user), } return render_to_response(template, data, context_instance=RequestContext(request))
def voipcall_report(request): """VoIP Call Report **Attributes**: * ``form`` - VoipSearchForm * ``template`` - frontend/report/voipcall_report.html **Logic Description**: * Get VoIP call list according to search parameters for loggedin user **Important variable**: * ``request.session['voipcall_record_qs']`` - stores voipcall query set """ kwargs = {} kwargs['user'] = User.objects.get(username=request.user) from_date = '' to_date = '' disposition = variable_value(request, 'status') form = VoipSearchForm() if request.method == 'POST': if request.POST['from_date'] != "": from_date = request.POST['from_date'] if request.POST['to_date'] != "": to_date = request.POST['to_date'] form = VoipSearchForm(request.POST) kwargs = voipcall_record_common_fun(request) else: tday = datetime.today() kwargs['starting_date__gte'] = datetime(tday.year, tday.month, tday.day, 0, 0, 0, 0) voipcall_list = \ VoIPCall.objects.filter(**kwargs).order_by('-starting_date') # Session variable is used to get record set with searched option # into export file request.session['voipcall_record_qs'] = voipcall_list select_data = \ {"starting_date": "SUBSTR(CAST(starting_date as CHAR(30)),1,10)"} # Get Total Rrecords from VoIPCall Report table for Daily Call Report total_data = VoIPCall.objects.extra(select=select_data)\ .values('starting_date')\ .filter(**kwargs).annotate(Count('starting_date'))\ .annotate(Sum('duration'))\ .annotate(Avg('duration'))\ .order_by('-starting_date') # Following code will count total voip calls, duration if total_data.count() != 0: max_duration = \ max([x['duration__sum'] for x in total_data]) total_duration = \ sum([x['duration__sum'] for x in total_data]) total_calls = \ sum([x['starting_date__count'] for x in total_data]) total_avg_duration = \ (sum([x['duration__avg']\ for x in total_data])) / total_data.count() else: max_duration = 0 total_duration = 0 total_calls = 0 total_avg_duration = 0 template = 'frontend/report/voipcall_report.html' data = { 'form': form, 'from_date': from_date, 'to_date': to_date, 'disposition': disposition, 'total_data': total_data.reverse(), 'total_duration': total_duration, 'total_calls': total_calls, 'total_avg_duration': total_avg_duration, 'max_duration': max_duration, 'module': current_view(request), 'notice_count': notice_count(request), 'dialer_setting_msg': user_dialer_setting_msg(request.user), } return render_to_response(template, data, context_instance=RequestContext(request))
def changelist_view(self, request, extra_context=None): """ Override changelist_view method of django-admin for search parameters **Attributes**: * ``form`` - AdminVoipSearchForm * ``template`` - admin/dialer_cdr/voipcall/change_list.html **Logic Description**: * VoIP report Record Listing with search option & Daily Call Report search Parameters: by date, by status and by billed. """ opts = VoIPCall._meta query_string = "" form = AdminVoipSearchForm() if request.method == "POST": # Session variable get record set with searched option into export file request.session["admin_voipcall_record_kwargs"] = voipcall_record_common_fun(request) query_string = voipcall_search_admin_form_fun(request) return HttpResponseRedirect("/admin/%s/%s/?%s" % (opts.app_label, opts.object_name.lower(), query_string)) else: disposition = "" from_date = "" to_date = "" campaign_id = "" leg_type = "" from_date = getvar(request, "starting_date__gte") to_date = getvar(request, "starting_date__lte")[0:10] disposition = getvar(request, "disposition__exact") campaign_id = getvar(request, "callrequest__campaign_id") leg_type = getvar(request, "leg_type__exact") form = AdminVoipSearchForm( initial={ "disposition": disposition, "from_date": from_date, "to_date": to_date, "campaign_id": campaign_id, "leg_type": leg_type, } ) ChangeList = self.get_changelist(request) try: cl = ChangeList( request, self.model, self.list_display, self.list_display_links, self.list_filter, self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_max_show_all, self.list_editable, self, ) except IncorrectLookupParameters: if ERROR_FLAG in request.GET.keys(): return render_to_response("admin/invalid_setup.html", {"title": _("Database error")}) return HttpResponseRedirect("%s?%s=1" % (request.path, ERROR_FLAG)) if request.META["QUERY_STRING"] == "": # Default # Session variable get record set with searched option into export file request.session["admin_voipcall_record_kwargs"] = voipcall_record_common_fun(request) query_string = voipcall_search_admin_form_fun(request) return HttpResponseRedirect("/admin/%s/%s/?%s" % (opts.app_label, opts.object_name.lower(), query_string)) cl.formset = None selection_note_all = ungettext("%(total_count)s selected", "All %(total_count)s selected", cl.result_count) ctx = { "selection_note": _("0 of %(cnt)s selected") % {"cnt": len(cl.result_list)}, "selection_note_all": selection_note_all % {"total_count": cl.result_count}, "cl": cl, "form": form, "opts": opts, "model_name": opts.object_name.lower(), "app_label": APP_LABEL, "title": _("call report"), } return super(VoIPCallAdmin, self).changelist_view(request, extra_context=ctx)