chore: Remove PDF export functionality

This commit is contained in:
Lord_Devi 2024-09-16 21:17:19 -04:00
parent 0dca3cfcf7
commit 2dfdcbb455
3 changed files with 0 additions and 36 deletions

View file

@ -20,5 +20,4 @@
{% endfor %}
</ul>
<a href="{% url 'lead_create' %}">Add New Lead</a>
<a href="{% url 'export_leads_pdf' %}">Export to PDF</a>
{% endblock %}

View file

@ -7,5 +7,4 @@ urlpatterns = [
path('create/', views.lead_create, name='lead_create'),
path('<int:pk>/update/', views.lead_update, name='lead_update'),
path('<int:pk>/delete/', views.lead_delete, name='lead_delete'),
path('export-pdf/', views.export_leads_pdf, name='export_leads_pdf'),
]

View file

@ -1,12 +1,7 @@
from django.shortcuts import render, redirect, get_object_or_404
from django.db.models import Q
from django.http import HttpResponse
from .models import Lead
from .forms import LeadForm
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.units import inch
from io import BytesIO
def lead_list(request):
query = request.GET.get('q')
@ -51,32 +46,3 @@ def lead_delete(request, pk):
lead.delete()
return redirect('lead_list')
return render(request, 'leads/lead_confirm_delete.html', {'lead': lead})
def export_leads_pdf(request):
# Create a file-like buffer to receive PDF data
buffer = BytesIO()
# Create the PDF object, using the buffer as its "file."
p = canvas.Canvas(buffer, pagesize=letter)
# Draw things on the PDF. Here's where the PDF generation happens.
# See the ReportLab documentation for the full list of functionality.
p.drawString(100, 750, "Leads Report")
leads = Lead.objects.all().order_by('-score')
y = 700
for lead in leads:
p.drawString(100, y, f"{lead.name} - {lead.company} - Score: {lead.score}")
y -= 20
if y < 50: # Start a new page if we're near the bottom
p.showPage()
y = 750
# Close the PDF object cleanly, and we're done.
p.showPage()
p.save()
# FileResponse sets the Content-Disposition header so that browsers
# present the option to save the file.
buffer.seek(0)
return HttpResponse(buffer, content_type='application/pdf')