# HG changeset patch # User amit@shrike.aero.iitb.ac.in # Date 1291119790 -19800 # Node ID fa3b368d39ea0faafe5392a2aa190e16d0e02133 # Parent 26137e53781eb0c97233406b33304187b3b2ae41# Parent 9414017a55899cd87c3836d6cf6e3e0aaca4ccea Merging heads diff -r 26137e53781e -r fa3b368d39ea project/scipycon/user/views.py --- a/project/scipycon/user/views.py Tue Nov 30 16:21:59 2010 +0530 +++ b/project/scipycon/user/views.py Tue Nov 30 17:53:10 2010 +0530 @@ -34,6 +34,11 @@ #for user_dump creation from project.scipycon.registration.models import Accommodation +#Pdf badge generation +from reportlab.pdfgen import canvas +from reportlab.lib.units import cm +from reportlab.platypus import Image as reportlabImage + @login_required def account(request, scope, template_name="user/account.html"): @@ -319,3 +324,51 @@ else: raise Http404 + + +@login_required +def badge(request,scope): + # Create the HttpResponse object with the appropriate PDF headers. + response = HttpResponse(mimetype='application/pdf') + response['Content-Disposition'] = 'attachment; filename=scipybadge.pdf' + + # Create the PDF object, using the response object as its "file." + c = canvas.Canvas(response) + + ref=5*cm + # Draw things on the PDF. Here's where the PDF generation happens. + # See the ReportLab documentation for the full list of functionality. + c.rect(ref,ref,9.45*cm,6.45*cm) + + im = reportlabImage("project/static/img/scipyshiny_small.png", width=1.75*cm, height=1.75*cm) + im.drawOn(c,(ref+0.8*cm),(ref+4.5*cm)) + c.setFont('Helvetica', 6) + c.drawString((ref+1.0*cm),(ref+4.4*cm),'scipy.in 2010') + c.drawString((ref+1.1*cm),(ref+4.2*cm),'Hyderabad') + + c.setFont('Helvetica', 12) + print request.user.id + reg_obj=Registration.objects.get(registrant=request.user.id) + + c.drawString((ref+5*cm),(ref+5*cm),str(reg_obj.slug)) + c.setFont('Helvetica-Bold', 14) + c.drawString((ref+0.6*cm),(ref+3.5*cm),str(request.user.get_full_name())) + c.setFont('Helvetica', 10) + c.drawString((ref+2.8*cm),(ref+2.8*cm),reg_obj.organisation) + c.setFont('Helvetica', 10) + try: + c.drawString((ref+2.8*cm),(ref+2.3*cm),reg_obj.occupation.split(':')[1]) + except IndexError: + c.drawString((ref+2.8*cm),(ref+2.3*cm),reg_obj.occupation) + + c.setFont('Helvetica', 10) + c.drawString((ref+2.8*cm),(ref+1.8*cm),reg_obj.city) + c.setFont('Helvetica', 10) + c.drawString((ref+2.8*cm),(ref+1*cm),'Delegate') + + + + # Close the PDF object cleanly, and we're done. + c.showPage() + c.save() + return response diff -r 26137e53781e -r fa3b368d39ea project/urls.py --- a/project/urls.py Tue Nov 30 16:21:59 2010 +0530 +++ b/project/urls.py Tue Nov 30 17:53:10 2010 +0530 @@ -74,7 +74,9 @@ url(r'^%s/get-usernames/$' % (SCOPE_ARG_PATTERN), 'get_usernames', name='scipycon_get_usernames'), url(r'^%s/get-user-dump/$' % (SCOPE_ARG_PATTERN), - 'get_user_dump', name='scipycon_get_usernames')) + 'get_user_dump', name='scipycon_get_usernames'), + url(r'^%s/badge/$' % (SCOPE_ARG_PATTERN), + 'badge', name='scipycon_badge')) # Proceedings