Пример #1
0
def survey_grid(request):
    """Survey list in json format for flexigrid.

    **Model**: SurveyApp

    **Fields**: [id, name, description, updated_date]
    """
    page = variable_value(request, 'page')
    rp = variable_value(request, 'rp')
    sortname = variable_value(request, 'sortname')
    sortorder = variable_value(request, 'sortorder')
    query = variable_value(request, 'query')
    qtype = variable_value(request, 'qtype')

    # page index
    if int(page) > 1:
        start_page = (int(page) - 1) * int(rp)
        end_page = start_page + int(rp)
    else:
        start_page = int(0)
        end_page = int(rp)


    #survey_list = []
    sortorder_sign = ''
    if sortorder == 'desc':
        sortorder_sign = '-'

    survey_list = SurveyApp.objects\
                     .values('id', 'name', 'description', 'updated_date')\
                     .filter(user=request.user)
    
    count = survey_list.count()
    survey_list = \
        survey_list.order_by(sortorder_sign + sortname)[start_page:end_page]

    update_style = 'style="text-decoration:none;background-image:url(' + \
                    settings.STATIC_URL + 'newfies/icons/page_edit.png);"'
    delete_style = 'style="text-decoration:none;background-image:url(' + \
                    settings.STATIC_URL + 'newfies/icons/delete.png);"'

    rows = [{'id': row['id'],
             'cell': ['<input type="checkbox" name="select" class="checkbox"\
                      value="' + str(row['id']) + '" />',
                      row['name'],
                      row['description'],
                      row['updated_date'].strftime('%Y-%m-%d %H:%M:%S'),
                      '<a href="' + str(row['id']) + '/" class="icon" ' \
                      + update_style + ' title="' + _('Update survey') + '">&nbsp;</a>' +
                      '<a href="del/' + str(row['id']) + '/" class="icon" ' \
                      + delete_style + ' onClick="return get_alert_msg(' +
                      str(row['id']) +
                      ');"  title="' + _('Delete survey') + '">&nbsp;</a>']}\
                      for row in survey_list]

    data = {'rows': rows,
            'page': page,
            'total': count}
    return HttpResponse(simplejson.dumps(data), mimetype='application/json',
                        content_type="application/json")
Пример #2
0
def notification_grid(request):
    """notification list in json format for flexigrid

    **Model**: notification.Notice
    """
    page = variable_value(request, 'page')
    rp = variable_value(request, 'rp')
    sortname = variable_value(request, 'sortname')
    sortorder = variable_value(request, 'sortorder')
    query = variable_value(request, 'query')
    qtype = variable_value(request, 'qtype')

    # page index
    if int(page) > 1:
        start_page = (int(page) - 1) * int(rp)
        end_page = start_page + int(rp)
    else:
        start_page = int(0)
        end_page = int(rp)


    #notification_list = []
    sortorder_sign = ''
    if sortorder == 'desc':
        sortorder_sign = '-'

    user_notification = \
    notification.Notice.objects.filter(recipient=request.user)
    # Search on sender name
    q = (Q(sender=request.user))
    if q:
        user_notification = user_notification.filter(q)

    count = user_notification.count()
    user_notification_list = \
        user_notification.order_by(sortorder_sign + sortname)[start_page:end_page]

    rows = [{'id': row.id,
             'cell': ['<input type="checkbox" name="select" class="checkbox"\
                      value="' + str(row.id) + '" />',
                      row.id,
                      row.message,
                      str(row.notice_type),
                      str(row.sender),
                      str(row.added),
                      str('<a href="../update_notice_status_cust/' + str(row.id) + '/" class="icon" ' \
                          + call_style(row.unseen) + ' ">&nbsp;</a>'),

             ]}for row in user_notification_list ]

    data = {'rows': rows,
            'page': page,
            'total': count}
    
    return HttpResponse(simplejson.dumps(data), mimetype='application/json',
                        content_type="application/json")
Пример #3
0
    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
        app_label = opts.app_label

        query_string = ''
        form = VoipSearchForm()
        if request.method == 'POST':
            query_string = voipcall_search_admin_form_fun(request)
            return HttpResponseRedirect("/admin/"+opts.app_label+"/"+opts.object_name.lower()+"/?"+query_string)
        else:
            status = ''
            from_date = ''
            to_date = ''
            if request.GET.get('starting_date__gte'):
                from_date = variable_value(request, 'starting_date__gte')
            if request.GET.get('starting_date__lte'):
                to_date = variable_value(request, 'starting_date__lte')[0:10]
            if request.GET.get('disposition__exact'):
                status = variable_value(request, 'disposition__exact')
            form = VoipSearchForm(initial={'status': status, 'from_date': from_date, 'to_date': to_date})


        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(request.path + '?' + ERROR_FLAG + '=1')

        kwargs = {}
        if request.META['QUERY_STRING'] == '':
            tday = datetime.today()
            kwargs['starting_date__gte'] = datetime(tday.year,
                                                    tday.month,
                                                    tday.day, 0, 0, 0, 0)
            cl.root_query_set.filter(**kwargs)

        formset = cl.formset = None

        # Session variable is used to get record set with searched option into export file
        request.session['admin_voipcall_record_qs'] = cl.root_query_set

        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': _('VoIP Report'),
            'title': _('Call Report'),
        }
        return super(VoIPCallAdmin, self)\
               .changelist_view(request, extra_context=ctx)
Пример #4
0
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))