31 |
31 |
32 #User_dump Http404 Error |
32 #User_dump Http404 Error |
33 from django.http import Http404 |
33 from django.http import Http404 |
34 #for user_dump creation |
34 #for user_dump creation |
35 from project.scipycon.registration.models import Accommodation |
35 from project.scipycon.registration.models import Accommodation |
|
36 |
|
37 #Pdf badge generation |
|
38 from reportlab.pdfgen import canvas |
|
39 from reportlab.lib.units import cm |
|
40 from reportlab.platypus import Image as reportlabImage |
36 |
41 |
37 |
42 |
38 @login_required |
43 @login_required |
39 def account(request, scope, template_name="user/account.html"): |
44 def account(request, scope, template_name="user/account.html"): |
40 """Displays the main screen of the current user's account. |
45 """Displays the main screen of the current user's account. |
317 'rows': rows})) |
322 'rows': rows})) |
318 |
323 |
319 |
324 |
320 else: |
325 else: |
321 raise Http404 |
326 raise Http404 |
|
327 |
|
328 |
|
329 @login_required |
|
330 def badge(request,scope): |
|
331 # Create the HttpResponse object with the appropriate PDF headers. |
|
332 response = HttpResponse(mimetype='application/pdf') |
|
333 response['Content-Disposition'] = 'attachment; filename=scipybadge.pdf' |
|
334 |
|
335 # Create the PDF object, using the response object as its "file." |
|
336 c = canvas.Canvas(response) |
|
337 |
|
338 ref=5*cm |
|
339 # Draw things on the PDF. Here's where the PDF generation happens. |
|
340 # See the ReportLab documentation for the full list of functionality. |
|
341 c.rect(ref,ref,9.45*cm,6.45*cm) |
|
342 |
|
343 im = reportlabImage("project/static/img/scipyshiny_small.png", width=1.75*cm, height=1.75*cm) |
|
344 im.drawOn(c,(ref+0.8*cm),(ref+4.5*cm)) |
|
345 c.setFont('Helvetica', 6) |
|
346 c.drawString((ref+1.0*cm),(ref+4.4*cm),'scipy.in 2010') |
|
347 c.drawString((ref+1.1*cm),(ref+4.2*cm),'Hyderabad') |
|
348 |
|
349 c.setFont('Helvetica', 12) |
|
350 print request.user.id |
|
351 reg_obj=Registration.objects.get(registrant=request.user.id) |
|
352 |
|
353 c.drawString((ref+5*cm),(ref+5*cm),str(reg_obj.slug)) |
|
354 c.setFont('Helvetica-Bold', 14) |
|
355 c.drawString((ref+0.6*cm),(ref+3.5*cm),str(request.user.get_full_name())) |
|
356 c.setFont('Helvetica', 10) |
|
357 c.drawString((ref+2.8*cm),(ref+2.8*cm),reg_obj.organisation) |
|
358 c.setFont('Helvetica', 10) |
|
359 try: |
|
360 c.drawString((ref+2.8*cm),(ref+2.3*cm),reg_obj.occupation.split(':')[1]) |
|
361 except IndexError: |
|
362 c.drawString((ref+2.8*cm),(ref+2.3*cm),reg_obj.occupation) |
|
363 |
|
364 c.setFont('Helvetica', 10) |
|
365 c.drawString((ref+2.8*cm),(ref+1.8*cm),reg_obj.city) |
|
366 c.setFont('Helvetica', 10) |
|
367 c.drawString((ref+2.8*cm),(ref+1*cm),'Delegate') |
|
368 |
|
369 |
|
370 |
|
371 # Close the PDF object cleanly, and we're done. |
|
372 c.showPage() |
|
373 c.save() |
|
374 return response |