From d6cec56fdbcab6e246af5194d255632fd5c1f9e5 Mon Sep 17 00:00:00 2001 From: Brody Wilton <brodywilton@192.168.1.227> Date: Sat, 2 Mar 2024 00:49:15 +0000 Subject: [PATCH] Implement basic version of report generation --- myproject/myapp/templates/user_page.html | 2 ++ myproject/myapp/urls.py | 4 +++- myproject/myapp/views.py | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/myproject/myapp/templates/user_page.html b/myproject/myapp/templates/user_page.html index 2e621e8..c9f63db 100644 --- a/myproject/myapp/templates/user_page.html +++ b/myproject/myapp/templates/user_page.html @@ -232,12 +232,14 @@ required /> </div> + <a href="{% url 'generate_pdf' %}" <button type="submit" class="p-2 bg-blue-500 text-white rounded-md hover:bg-blue-600" > Download Financial Statement </button> + </a> </form> {% comment %} REPLACE WITH LOGIC TO CHECK PROPER USER {% endcomment %} </div> diff --git a/myproject/myapp/urls.py b/myproject/myapp/urls.py index 4b7449c..28a9503 100644 --- a/myproject/myapp/urls.py +++ b/myproject/myapp/urls.py @@ -12,6 +12,7 @@ from .views import handling_music_file from .views import pricing +from .views import generate_pdf urlpatterns = [ # path('', index, name='index'), <- uncomment when index/main page will be ready @@ -26,5 +27,6 @@ urlpatterns = [ path('pricay_policy/', privacy_policy, name='privacy_policy'), path('pricing/', pricing, name='pricing'), path('uploading_file/', handling_music_file, name='uploading_file'), - +, + path('generate_pdf/', generate_pdf, name='generate_pdf') ] diff --git a/myproject/myapp/views.py b/myproject/myapp/views.py index 25eaefc..315c0a1 100644 --- a/myproject/myapp/views.py +++ b/myproject/myapp/views.py @@ -77,3 +77,15 @@ def privacy_policy(request): def pricing(request): return render(request, 'pricing.html') + +#For testing the receipts ONLY. TODO: delete when working +def generate_pdf(request): + response = HttpResponse(content_type='application/pdf') + response['Content-Disposition'] = 'attachment; filename="example.pdf"' + + p = canvas.Canvas(response) + p.drawString(100, 800, "Hello, this is a PDF!") + p.showPage() + p.save() + + return response -- GitLab