Commits

ro...@localhost.localdomain  committed 55ad661 Merge

merged

  • Participants
  • Parent commits 06e6525, 99426f5

Comments (0)

Files changed (3)

File web/idcards.py

 from reportlab.pdfgen import canvas, textobject, pdfimages
 from reportlab.lib.units import cm
 from reportlab.lib.pagesizes import A4
+from cStringIO import StringIO
+
  
  
 cheight = 8 * cm # Card is 8 cm heigh
     
 def draw_image(c):
     """Draws the logo image at the correct position"""
-    c.drawImage("/home/pycon/conference/sitemedia/pics/PyconLogo.jpg",cwidth/2 + cm, 0 + cm, width = 3*cm, height = 3*cm, preserveAspectRatio = True)
+    c.drawImage("/home/lawgon/conference/sitemedia/pics/PyconLogo.jpg",cwidth/2 + cm, 0 + cm, width = 3*cm, height = 3*cm, preserveAspectRatio = True)
  
 def write_details(c,name,org,regno):
     """Writes the registration details. Name, org and regno with
     url(r'^deleteslot/(?P<slot>\d+)/$', 'deleteslot', name='delete_slot'),
     url(r'^sorry/$', 'sorry', name='sorry'),
     url(r'^idcard/$', 'idcard', name='idcard'),
+    url(r'^getdelegates/$', 'get_delegates', name='getdelegates'),
     #talk
     url(r'^talks/$', 'talks', name='talks'),
     url(r'^talkfull/(?P<id>\d+)/$', 'talkfull', name='talk_by_id'),

File web/views.py

 from conference.web.forms import *
 from django.http import Http404
 from idcards import *
+import csv
 
 
 class menu_enabled(object):
     # Create the HttpResponse object with the appropriate PDF headers.
     response = HttpResponse(mimetype='application/pdf')
     response['Content-Disposition'] = 'attachment; filename=somefilename.pdf'
+    buffer = StringIO()
     p = Delegate.objects.get(username=request.user)
     tak= Talk.objects.filter(speaker=p).order_by('title')
     defph = ''
         defph = str(p.photo)
     
     # Create the PDF object, using the response object as its "file."
-    c = canvas.Canvas(response, bottomup = 1, pagesize = A4)
+    c = canvas.Canvas(buffer, bottomup = 1, pagesize = A4)
     c.translate(2*cm,2*cm)
     draw_borders(c)
     draw_banner(c)
     draw_image(c)
-    c.drawImage("/home/pycon/media/"+defph,0 + cm, 0 + cm, width = 2.5*cm, height = 2.5*cm, preserveAspectRatio = True)
+    c.drawImage("/home/lawgon/media/"+defph,0 + cm, 0 + cm, width = 2.5*cm, height = 2.5*cm, preserveAspectRatio = True)
     jndte="Registered on %d/%d/%d" %(p.joindate.day,p.joindate.month,p.joindate.year)
     write_details(c,str(getname(p)),p.organisation,jndte)
 
     # Close the PDF object cleanly, and we're done.
     c.showPage()
     c.save()
+    pdf = buffer.getvalue()
+    buffer.close()
+    response.write(pdf)
     return response
 
+@user_passes_test(lambda u: isingroup(u,'committee') == True,login_url="/login/")    
+def get_delegates(request):
+    # Create the HttpResponse object with the appropriate CSV header.
+    response = HttpResponse(mimetype='text/csv')
+    response['Content-Disposition'] = 'attachment; filename=delegates.csv'
+    dels = Delegate.objects.exclude(private=True)
+    writer = csv.writer(response)
+    writer.writerow(['Name', 'Email', 'City', 'Occupation','organisation','bio'])
+    for dl in dels:
+        writer.writerow([getname(dl),dl.username.email,dl.city,
+        dl.occupation,dl.organisation,dl.bio])
+
+    return response
+
+