From cc7e3fd4a03efb3795bacdbbb00c93bc746ea545 Mon Sep 17 00:00:00 2001
From: hardythe1
Date: Wed, 19 Nov 2014 11:47:27 +0530
Subject: added views & templates for certificate generation
---
tbc/templates/base.html | 1 +
tbc/urls.py | 1 +
tbc/views.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 57 insertions(+)
(limited to 'tbc')
diff --git a/tbc/templates/base.html b/tbc/templates/base.html
index e5ad52f..a6e5856 100755
--- a/tbc/templates/base.html
+++ b/tbc/templates/base.html
@@ -108,6 +108,7 @@
Submit Proposal
Submit Sample Notebook
Submit Codes
+ Get Certificate
Update Password
Logout
diff --git a/tbc/urls.py b/tbc/urls.py
index b20b4e4..413374d 100644
--- a/tbc/urls.py
+++ b/tbc/urls.py
@@ -35,6 +35,7 @@ urlpatterns = patterns('',
url(r'^completed-books/(?P.+)$', 'tbc.views.CompletedBooks', name='CompletedBooks'),
url(r'^books-under-progress/$', 'tbc.views.BooksUnderProgress', name='BooksUnderProgress'),
url(r'^redirect-ipynb/(?P.+)$', 'tbc.views.RedirectToIpynb', name='RedirectToIpynb'),
+ url(r'^get-certificate/$', 'tbc.views.GetCertificate', name='GetCertificate'),
url(r'^book-review/$', 'tbc.views.BookReview', name='BookReview'),
diff --git a/tbc/views.py b/tbc/views.py
index cc3d12c..13fe26a 100755
--- a/tbc/views.py
+++ b/tbc/views.py
@@ -16,6 +16,15 @@ import shutil
import string
import random
import json
+import reportlab
+from reportlab.pdfgen import canvas
+from reportlab.lib.pagesizes import letter, landscape, A4, cm
+from reportlab.lib.units import inch
+from reportlab.lib.styles import getSampleStyleSheet
+from reportlab.lib.enums import TA_JUSTIFY, TA_LEFT, TA_CENTER
+from reportlab.lib import colors
+from reportlab.pdfgen import canvas
+from reportlab.platypus import Paragraph, Table, TableStyle
from email.mime.text import MIMEText
@@ -1121,6 +1130,52 @@ def BooksUnderProgress(request):
else:
context['user'] = request.user
return render_to_response('tbc/books_under_progress.html', context)
+
+
+def GetCertificate(request):
+ user = request.user
+ user_profile = Profile.objects.get(user=user)
+ books = Book.objects.filter(contributor=user_profile, approved=True)
+ context = {}
+ context['user'] = user
+ context['books'] = books
+ width, height = A4
+ styles = getSampleStyleSheet()
+ styleN = styles["BodyText"]
+ styleN.alignment = TA_LEFT
+ styleBH = styles["Normal"]
+ styleBH.alignment = TA_CENTER
+ def coord(x, y, unit=1):
+ x, y = x * unit, height - y * unit
+ return x, y
+ # Headers
+ hdescrpcion = Paragraph('''descrpcion''', styleBH)
+ hpartida = Paragraph('''partida''', styleBH)
+ hcandidad = Paragraph('''candidad''', styleBH)
+ hprecio_unitario = Paragraph('''precio_unitario''', styleBH)
+ hprecio_total = Paragraph('''precio_total''', styleBH)
+ # Texts
+ descrpcion = Paragraph('long paragraph', styleN)
+ partida = Paragraph('1', styleN)
+ candidad = Paragraph('120', styleN)
+ precio_unitario = Paragraph('$52.00', styleN)
+ precio_total = Paragraph('$6240.00', styleN)
+ data= [[hdescrpcion, hcandidad,hcandidad, hprecio_unitario, hprecio_total],
+ [partida, candidad, descrpcion, precio_unitario, precio_total]]
+ table = Table(data, colWidths=[2.05 * cm, 2.7 * cm, 5 * cm,
+ 3* cm, 3 * cm])
+ table.setStyle(TableStyle([
+ ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
+ ('BOX', (0,0), (-1,-1), 0.25, colors.black),
+ ]))
+ c = canvas.Canvas("a.pdf", pagesize=A4)
+ table.wrapOn(c, width, height)
+ table.drawOn(c, *coord(1.8, 9.6, cm))
+ c.save()
+ response = HttpResponse(content_type='application/pdf')
+ response['Content-Disposition'] = c
+ # Create the PDF object, using the response object as its "file."
+ return response
def RedirectToIpynb(request, notebook_path=None):
--
cgit