Exemplo n.º 1
0
def enterprise_dashboard_email(request, domain, slug):
    account = get_account_or_404(request, domain)
    report = EnterpriseReport.create(slug, account.id, request.couch_user)
    email_enterprise_report.delay(domain, slug, request.couch_user)
    message = _(
        "Generating {title} report, will email to {email} when complete."
    ).format(**{
        'title': report.title,
        'email': request.couch_user.username,
    })
    return JsonResponse({'message': message})
Exemplo n.º 2
0
def enterprise_dashboard_download(request, domain, slug, export_hash):
    account = get_account_or_404(request, domain)
    report = EnterpriseReport.create(slug, account.id, request.couch_user)

    redis = get_redis_client()
    content = redis.get(export_hash)

    if content:
        file = ContentFile(content)
        response = HttpResponse(file, Format.FORMAT_DICT[Format.UNZIPPED_CSV])
        response['Content-Length'] = file.size
        response['Content-Disposition'] = 'attachment; filename="{}"'.format(
            report.filename)
        return response

    return HttpResponseNotFound(
        _("That report was not found. Please remember that "
          "download links expire after 24 hours."))
Exemplo n.º 3
0
    def _write_file(self, slug):
        report = EnterpriseReport.create(slug, self.account_id,
                                         self.couch_user)

        row_count = 0
        csv_file = io.StringIO()
        writer = csv.writer(csv_file)
        writer.writerow(report.headers)

        rows = report.rows
        row_count = len(rows)
        writer.writerows(rows)

        print('Wrote {} lines of {}'.format(row_count, slug))
        attachment = {
            'title': report.filename,
            'mimetype': 'text/csv',
            'file_obj': csv_file,
        }
        return (attachment, row_count)
Exemplo n.º 4
0
def enterprise_dashboard_total(request, domain, slug):
    account = get_account_or_404(request, domain)
    report = EnterpriseReport.create(slug, account.id, request.couch_user)
    return JsonResponse({'total': report.total})