# HG changeset patch # User Amit Sethi # Date 1291119668 -19800 # Node ID 9414017a55899cd87c3836d6cf6e3e0aaca4ccea # Parent d49cd84fb9c05ab0ffb124eca418babd09ba9622 Added view for automatic badge generation diff -r d49cd84fb9c0 -r 9414017a5589 project/scipycon/user/views.py --- a/project/scipycon/user/views.py Tue Nov 30 15:44:14 2010 +0530 +++ b/project/scipycon/user/views.py Tue Nov 30 17:51:08 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 d49cd84fb9c0 -r 9414017a5589 project/urls.py --- a/project/urls.py Tue Nov 30 15:44:14 2010 +0530 +++ b/project/urls.py Tue Nov 30 17:51:08 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