Skip to content

Commit

Permalink
Download resume as PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
manjurulhoque committed Nov 3, 2024
1 parent 93256ab commit e0591ac
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
Binary file modified db.sqlite3
Binary file not shown.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@ uritemplate==4.1.1
urllib3==2.2.3
virtualenv==20.26.6
webencodings==0.5.1
weasyprint==63.0
whitenoise==6.7.0
2 changes: 2 additions & 0 deletions resume_cv/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ResumeCVCreateView,
resume_builder,
UserResumeListView,
download_resume,
)

app_name = "resume_cv"
Expand All @@ -14,4 +15,5 @@
path("resume-cv/create", ResumeCVCreateView.as_view(), name="create"),
path("templates/builder/<code>", resume_builder, name="builder"),
path("resumes/", UserResumeListView.as_view(), name="resumes"),
path("download-as-pdf/<int:id>/", download_resume, name="export.pdf"),
]
17 changes: 16 additions & 1 deletion resume_cv/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import json

from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponse, JsonResponse
from django.middleware.csrf import get_token
from django.shortcuts import render, redirect
from django.urls import reverse_lazy
from django.views import View
from django.views.generic import ListView, CreateView
from django.views.generic import ListView
from weasyprint import HTML

from jobsapp.decorators import user_is_employee
# Create your views here.
from jobsapp.mixins import EmployeeRequiredMixin
from resume_cv.forms import ResumeCvForm
Expand Down Expand Up @@ -113,3 +116,15 @@ class UserResumeListView(ListView):

def get_queryset(self):
return self.model.objects.filter(user_id=self.request.user.id).order_by("-id")


@login_required
@user_is_employee
def download_resume(request, id):
resume = ResumeCv.objects.get(id=id)
if resume:
pdf_file = HTML(string=resume.content).write_pdf()
response = HttpResponse(pdf_file, content_type="application/pdf")
response["Content-Disposition"] = f'attachment; filename="{resume.name}.pdf"'
return response
return redirect("resume_cv:resumes")
2 changes: 1 addition & 1 deletion templates/resumes/builder.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h4><b>{{ template.name }}</b></h4>
let urlStore = '{% url 'resume-cv.update.builder' resume.id %}';
let urlLoad = '{% url 'resume-cv.load.builder' resume.id %}';
let back_button_url = "{% url 'resume_cv:templates' %}";
let exportPDF_url = "";
let exportPDF_url = '{% url 'resume_cv:export.pdf' resume.id %}';

let images_url = ['{% static 'img/1875187.jpg' %}'];
let all_fonts = ['Arial', 'Verdana', 'Helvetica', 'Tahoma', 'Trebuchet MS', 'Times New Roman', 'Georgia', 'Garamond', 'Courier New', 'Brush Script MT'];
Expand Down

0 comments on commit e0591ac

Please sign in to comment.