Esempio n. 1
0
def subscriber_export(request):
    """Export CSV file of subscriber record

    **Important variable**:

        * ``request.session['subscriber_list_kwargs']`` - stores subscriber_list kwargs

    **Exported fields**: ['contact', 'updated_date', 'count_attempt',
                          'completion_count_attempt', 'status', 'disposition',
                          'collected_data', 'agent']
    """
    format_type = request.GET['format']
    # get the response object, this can be used as a stream.
    response = HttpResponse(mimetype='text/%s' % format_type)

    # force download.
    response['Content-Disposition'] = 'attachment;filename=export.%s' % format_type

    if request.session.get('subscriber_list_kwargs'):
        kwargs = request.session['subscriber_list_kwargs']
        if request.user.is_superuser:
            subscriber_list = Subscriber.objects.all()
        else:
            subscriber_list = Subscriber.objects.filter(campaign__user=request.user)

        if kwargs:
            subscriber_list = subscriber_list.filter(**kwargs)

        headers = ('contact', 'updated_date', 'count_attempt', 'completion_count_attempt',
                   'status', 'disposition', 'collected_data', )  # 'agent',

        list_val = []
        for i in subscriber_list:
            updated_date = i.updated_date
            if format_type == Export_choice.JSON or Export_choice.XLS:
                updated_date = str(i.updated_date)

            list_val.append((
                i.contact.contact,
                updated_date,
                i.count_attempt,
                i.completion_count_attempt,
                get_subscriber_status(i.status),
                get_subscriber_disposition(i.campaign_id, i.disposition),
                i.collected_data,
                # i.agent,
            ))

        data = tablib.Dataset(*list_val, headers=headers)

        if format_type == Export_choice.XLS:
            response.write(data.xls)
        elif format_type == Export_choice.CSV:
            response.write(data.csv)
        elif format_type == Export_choice.JSON:
            response.write(data.json)

    return response
Esempio n. 2
0
def subscriber_export(request):
    """Export CSV file of subscriber record

    **Important variable**:

        * ``request.session['subscriber_list_kwargs']`` - stores subscriber_list kwargs

    **Exported fields**: ['contact', 'updated_date', 'count_attempt',
                          'completion_count_attempt', 'status', 'disposition',
                          'collected_data', 'agent']
    """
    format = request.GET["format"]
    # get the response object, this can be used as a stream.
    response = HttpResponse(mimetype="text/" + format)

    # force download.
    response["Content-Disposition"] = "attachment;filename=export." + format

    if request.session.get("subscriber_list_kwargs"):
        kwargs = request.session["subscriber_list_kwargs"]
        if request.user.is_superuser:
            subscriber_list = Subscriber.objects.all()
        else:
            subscriber_list = Subscriber.objects.filter(campaign__user=request.user)

        if kwargs:
            subscriber_list = subscriber_list.filter(**kwargs)

        headers = (
            "contact",
            "updated_date",
            "count_attempt",
            "completion_count_attempt",
            "status",
            "disposition",
            "collected_data",
            "agent",
        )

        list_val = []
        for i in subscriber_list:
            updated_date = i.updated_date
            if format == "json" or format == "xls":
                updated_date = str(i.updated_date)

            list_val.append(
                (
                    i.contact.contact,
                    updated_date,
                    i.count_attempt,
                    i.completion_count_attempt,
                    get_subscriber_status(i.status),
                    get_subscriber_disposition(i.campaign_id, i.disposition),
                    i.collected_data,
                    i.agent,
                )
            )

        data = tablib.Dataset(*list_val, headers=headers)

        if format == "xls":
            response.write(data.xls)

        if format == "csv":
            response.write(data.csv)

        if format == "json":
            response.write(data.json)

    return response
def subscriber_disposition(campaign_id, val):
    """To get subscriber disposition name from campaign's
    lead_disposition string"""
    return get_subscriber_disposition(campaign_id, val)
Esempio n. 4
0
def subscriber_disposition(campaign_id, val):
    """To get subscriber disposition name from campaign's
    lead_disposition string"""
    return get_subscriber_disposition(campaign_id, val)