Le repo des sources pour le site web des JM2L
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

531 lines
19 KiB

  1. # -*- coding: utf8 -*-
  2. from pyramid.httpexceptions import HTTPNotFound
  3. from pyramid.response import Response
  4. import cStringIO as StringIO
  5. from pyramid.view import view_config
  6. from .models import User
  7. from reportlab.pdfgen import canvas
  8. from reportlab.pdfbase import pdfmetrics
  9. from reportlab.pdfbase.ttfonts import TTFont
  10. from reportlab.lib.units import mm
  11. import qrcode
  12. import subprocess
  13. from .upload import MediaPath
  14. # Create PDF container
  15. EXPIRATION_TIME = 300 # seconds
  16. WIDTH = 85 * mm
  17. HEIGHT = 60 * mm
  18. ICONSIZE = 9 * mm
  19. def Ribbon35(DispUser, canvas):
  20. canvas.saveState()
  21. canvas.rotate(35)
  22. offset_u=0
  23. if DispUser.Staff:
  24. # Staff
  25. canvas.setFillColorRGB(1,.2,.2)
  26. canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1)
  27. canvas.setFillColorRGB(1,1,1)
  28. canvas.setFont('Liberation', 20)
  29. canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+5, "STAFF")
  30. elif DispUser.is_Intervenant:
  31. # Intervenant
  32. canvas.setFillColorRGB(.3,.3,1)
  33. canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1)
  34. canvas.setFillColorRGB(1,1,1)
  35. canvas.setFont('Liberation', 15)
  36. canvas.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+10, "Intervenant")
  37. else:
  38. # Visiteur
  39. canvas.setFillColorRGB(.8,.8,.8)
  40. canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1)
  41. canvas.setFillColorRGB(0,0,0)
  42. canvas.setFont('Liberation', 12)
  43. canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+7, "Visiteur")
  44. canvas.restoreState()
  45. return canvas
  46. def Ribbon45(DispUser, canvas):
  47. canvas.saveState()
  48. canvas.rotate(45)
  49. offset_u=0
  50. if DispUser.Staff:
  51. # Staff
  52. canvas.setFillColorRGB(1,.2,.2)
  53. canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1)
  54. canvas.setFillColorRGB(1,1,1)
  55. canvas.setFont('Liberation', 20)
  56. canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+5, "STAFF")
  57. elif DispUser.is_Intervenant:
  58. # Intervenant
  59. canvas.setFillColorRGB(.3,.3,1)
  60. canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1)
  61. canvas.setFillColorRGB(1,1,1)
  62. canvas.setFont('Liberation', 15)
  63. canvas.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+10, "Intervenant")
  64. else:
  65. # Visiteur
  66. canvas.setFillColorRGB(.8,.8,.8)
  67. canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1)
  68. canvas.setFillColorRGB(0,0,0)
  69. canvas.setFont('Liberation', 12)
  70. canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+7, "Visiteur")
  71. canvas.restoreState()
  72. return canvas
  73. def Ribbon90(DispUser, canvas):
  74. canvas.saveState()
  75. canvas.rotate(90)
  76. offset_u=0
  77. if DispUser.Staff:
  78. # Staff
  79. canvas.setFillColorRGB(1,.2,.2)
  80. canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1)
  81. canvas.setFillColorRGB(1,1,1)
  82. canvas.setFont('Liberation', 20)
  83. canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+5, "STAFF")
  84. elif DispUser.is_Intervenant:
  85. # Intervenant
  86. canvas.setFillColorRGB(.3,.3,1)
  87. canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1)
  88. canvas.setFillColorRGB(1,1,1)
  89. canvas.setFont('Liberation', 15)
  90. canvas.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+10, "Intervenant")
  91. else:
  92. # Visiteur
  93. canvas.setFillColorRGB(.8,.8,.8)
  94. canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1)
  95. canvas.setFillColorRGB(0,0,0)
  96. canvas.setFont('Liberation', 12)
  97. canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+7, "Visiteur")
  98. canvas.restoreState()
  99. return canvas
  100. def JM2L_Logo(canvas, Position="Up"):
  101. # Import font
  102. ttfFile_Logo = "jm2l/static/fonts/PWTinselLetters.ttf"
  103. pdfmetrics.registerFont(TTFont("Logo", ttfFile_Logo))
  104. if Position=="Up":
  105. logoobject = canvas.beginText()
  106. logoobject.setFont('Logo', 52)
  107. logoobject.setFillColorRGB(.83,0,.33)
  108. logoobject.setTextOrigin(55, HEIGHT-50)
  109. logoobject.textLines("JM2L")
  110. canvas.drawText(logoobject)
  111. yearobject = canvas.beginText()
  112. yearobject.setFont("Helvetica-Bold", 15)
  113. yearobject.setFillColorRGB(1,1,1)
  114. yearobject.setTextOrigin(67, HEIGHT-20)
  115. yearobject.setWordSpace(21)
  116. yearobject.textLines("2 0 1 5")
  117. canvas.drawText(yearobject)
  118. elif Position=="Down":
  119. logoobject = canvas.beginText()
  120. logoobject.setFont('Logo', 32)
  121. logoobject.setFillColorRGB(.83,0,.33)
  122. logoobject.setTextOrigin(2, 17)
  123. logoobject.textLines("JM2L")
  124. canvas.drawText(logoobject)
  125. yearobject = canvas.beginText()
  126. yearobject.setFont("Helvetica-Bold", 10)
  127. yearobject.setFillColorRGB(1,1,1)
  128. #yearobject.setLineWidth(.1)
  129. #yearobject.setStrokeColorRGB(.5,.5,.5)
  130. yearobject.setTextRenderMode(0)
  131. #yearobject.setStrokeOverprint(.2)
  132. yearobject.setTextOrigin(9 , 35)
  133. yearobject.setWordSpace(13)
  134. yearobject.textLines("2 0 1 5")
  135. canvas.drawText(yearobject)
  136. def Tiers_Logo(canvas, DispUser, StartPos=None):
  137. Border = 0
  138. if StartPos is None:
  139. StartPos = ( 30 * mm, 2 )
  140. StartX, StartY = StartPos
  141. MaxX, MaxY = 34*mm, 18*mm
  142. num = 0
  143. canvas.setStrokeColorRGB(0.5,0.5,0.5)
  144. Logos = filter(lambda x:x.ThumbLinks, DispUser.tiers)[:3]
  145. # Should We compute a better positionning for logos ?
  146. DicPos = {}
  147. DicPos[1] = { 0:(1./2, 1./2) }
  148. DicPos[2] = { 0:(1./3, 1./2), 1:(2./3, 1./2) }
  149. DicPos[3] = { 0:(1./2, 1./4), 1:(1./3, 3./4), 2:(2./3, 3./4) }
  150. DicPos[4] = { 0:(1./3, 1./4), 1:(2./3, 1./4), 2:(1./3, 3./4),
  151. 3:(2./3, 3./4) }
  152. DicPos[5] = { 0:(1./3, 1./4), 1:(2./3, 1./4), 2:(1./6, 3./4),
  153. 3:(3./6, 3./4), 4:(5./6, 3./4) }
  154. DicPos[6] = { 0:(1./6, 1./4), 1:(3./6, 1./4), 2:(5./6, 1./4),
  155. 3:(1./6, 3./4), 4:(3./6, 3./4), 5:(5./6, 3./4) }
  156. DicPos[7] = { 0:(1./6, 1./4), 1:(3./6, 1./4), 2:(5./6, 1./4),
  157. 3:(1./8, 3./4), 4:(3./8, 3./4), 5:(5./8, 3./4),
  158. 6:(7./8, 3./4) }
  159. DicPos[8] = { 0:(1./8, 1./4), 1:(3./8, 1./4), 2:(5./8, 1./4),
  160. 3:(7./8, 1./4), 4:(1./8, 3./4), 5:(3./8, 3./4),
  161. 6:(5./8, 3./4), 7:(7./8, 3./4) }
  162. # draw overall border
  163. # canvas.roundRect(StartX, StartY, MaxX, MaxY, radius=2, stroke=True)
  164. for tiers in Logos:
  165. FileName = tiers.ThumbLinks.pop().split("/")[-1]
  166. ImagePath = "jm2l/upload/images/tiers/%s/%s" % (tiers.slug, FileName)
  167. PosX = StartX + DicPos[len(Logos)][num][0] * MaxX - (ICONSIZE+Border)/2
  168. PosY = StartY + DicPos[len(Logos)][num][1] * MaxY - (ICONSIZE+Border)/2
  169. canvas.setLineWidth(.1)
  170. canvas.drawImage(ImagePath,
  171. PosX, PosY, ICONSIZE, ICONSIZE,\
  172. preserveAspectRatio=True,
  173. anchor='c',
  174. mask='auto'
  175. )
  176. # draw icon border
  177. # canvas.roundRect(PosX, PosY, ICONSIZE, ICONSIZE, radius=2, stroke=True)
  178. num+=1
  179. def QRCode(DispUser):
  180. qr = qrcode.QRCode(
  181. version=1,
  182. error_correction=qrcode.constants.ERROR_CORRECT_L,
  183. box_size=10,
  184. border=2,
  185. )
  186. # Data of QR code
  187. qr.add_data('http://jm2l.linux-azur.org/user/%s' % DispUser.slug)
  188. qr.make(fit=True)
  189. return qr.make_image()
  190. @view_config(route_name='badge_user', http_cache = (EXPIRATION_TIME, {'public':True}))
  191. def badge_user(request):
  192. isoutpng = request.params.get('png')
  193. user_slug = request.matchdict.get('user_slug', None)
  194. if user_slug is None or len(user_slug)==0:
  195. raise HTTPNotFound(u"Cet utilisateur n'a pas été reconnu")
  196. # Query database
  197. DispUser = User.by_slug(user_slug)
  198. if DispUser is None:
  199. raise HTTPNotFound()
  200. # Ok let's generate a PDF Badge
  201. # Register LiberationMono font
  202. ttfFile = "jm2l/static/fonts/LiberationMono-Regular.ttf"
  203. pdfmetrics.registerFont(TTFont("Liberation", ttfFile))
  204. pdf = StringIO.StringIO()
  205. out_img = StringIO.StringIO()
  206. c = canvas.Canvas( pdf, pagesize=(WIDTH, HEIGHT) )
  207. c.translate(mm, mm)
  208. # Feed some metadata
  209. c.setCreator("linux-azur.org")
  210. c.setTitle("Badge")
  211. c.saveState()
  212. # Logo on Top
  213. JM2L_Logo(c, "Down")
  214. if DispUser.Staff:
  215. # Staff
  216. c.setFillColorRGB(.83,0,.33)
  217. c.rect(-3, HEIGHT-30, WIDTH, HEIGHT, fill=1, stroke=0)
  218. c.setFillColorRGB(1,1,1)
  219. c.setFont('Liberation', 30)
  220. c.drawCentredString(WIDTH/2, HEIGHT-26, "STAFF")
  221. elif DispUser.is_Intervenant:
  222. # Intervenant
  223. c.setFillColorRGB(.21,.67,.78)
  224. c.rect(-3, HEIGHT-30, WIDTH, HEIGHT, fill=1, stroke=0)
  225. c.setFillColorRGB(1,1,1)
  226. c.setFont('Liberation', 30)
  227. c.drawCentredString(WIDTH/2, HEIGHT-26, "Intervenant")
  228. else:
  229. # Visiteur
  230. c.setFillColorRGB(.8,.8,.8)
  231. c.rect(-3, HEIGHT-30, WIDTH, HEIGHT, fill=1, stroke=0)
  232. c.setFillColorRGB(1,1,1)
  233. c.setFont('Liberation', 30)
  234. c.drawCentredString(WIDTH/2, HEIGHT-26, "Visiteur")
  235. c.restoreState()
  236. c.setFont('Liberation', 18)
  237. c.setStrokeColorRGB(0,0,0)
  238. c.setFillColorRGB(0,0,0)
  239. # Feed Name and SurName
  240. if len(DispUser.prenom) + len(DispUser.nom)>18:
  241. if DispUser.pseudo:
  242. c.drawCentredString(WIDTH/2, HEIGHT/2 + 0 * mm , "%s" % DispUser.prenom )
  243. c.setFont('Courier', 17)
  244. c.drawCentredString(WIDTH/2, HEIGHT/2 - 8 * mm , "%s" % DispUser.nom )
  245. else:
  246. c.drawCentredString(WIDTH/2, HEIGHT/2 + 4 * mm , "%s" % DispUser.prenom )
  247. c.setFont('Courier', 17)
  248. c.drawCentredString(WIDTH/2, HEIGHT/2 - 8 * mm , "%s" % DispUser.nom )
  249. else:
  250. c.drawCentredString(WIDTH/2, HEIGHT/2 + 0 * mm , "%s %s" % (DispUser.prenom, DispUser.nom) )
  251. if DispUser.pseudo:
  252. c.setFont("Helvetica-Oblique", 18)
  253. c.drawCentredString(WIDTH/2, HEIGHT/2 + 10 * mm , "%s" % DispUser.pseudo )
  254. # Put QR code to user profile
  255. c.drawInlineImage(QRCode(DispUser), \
  256. WIDTH - 20 * mm - 7, 0, \
  257. 20 * mm, 20 * mm, \
  258. preserveAspectRatio=True, \
  259. anchor='s')
  260. Tiers_Logo(c, DispUser)
  261. c.showPage()
  262. c.save()
  263. pdf.seek(0)
  264. if isoutpng:
  265. OutPDF = MediaPath().get_mediapath("badge", DispUser.uid, 'badge.pdf')
  266. OutPNG = MediaPath().get_mediapath("badge", DispUser.uid, 'badge.png')
  267. # Let's generate a png file for website
  268. with open( OutPDF ,'wb') as pdff:
  269. pdff.write(pdf.read())
  270. Command = ["convert","-density","150x150", OutPDF, OutPNG]
  271. subprocess.call(Command)
  272. with open( OutPNG, 'rb') as pngfile:
  273. out_img.write(pngfile.read())
  274. out_img.seek(0)
  275. return Response(app_iter=out_img, content_type = 'image/png' )
  276. else:
  277. return Response(app_iter=pdf, content_type = 'application/pdf' )
  278. @view_config(route_name='badge_user1')
  279. def badge_user1(request):
  280. user_slug = request.matchdict.get('user_slug', None)
  281. if user_slug is None or len(user_slug)==0:
  282. raise HTTPNotFound(u"Cet utilisateur n'a pas été reconnu")
  283. # Query database
  284. DispUser = User.by_slug(user_slug)
  285. if DispUser is None:
  286. raise HTTPNotFound()
  287. # Ok let's generate a PDF Badge
  288. ttfFile = "jm2l/static/fonts/LiberationMono-Regular.ttf"
  289. ttfFile_Logo = "jm2l/static/fonts/PWTinselLetters.ttf"
  290. pdfmetrics.registerFont(TTFont("Liberation", ttfFile))
  291. pdfmetrics.registerFont(TTFont("Logo", ttfFile_Logo))
  292. pdf = StringIO.StringIO()
  293. c = canvas.Canvas( pdf, pagesize=(WIDTH, HEIGHT) )
  294. c.translate(mm, mm)
  295. # Feed some metadata
  296. c.setCreator("linux-azur.org")
  297. c.setTitle("Badge")
  298. c.saveState()
  299. logoobject = c.beginText()
  300. logoobject.setFont('Logo', 52)
  301. logoobject.setFillColorRGB(.83,0,.33)
  302. logoobject.setTextOrigin(55, HEIGHT-50)
  303. logoobject.textLines("JM2L")
  304. c.drawText(logoobject)
  305. yearobject = c.beginText()
  306. yearobject.setFont("Helvetica-Bold", 15)
  307. yearobject.setFillColorRGB(1,1,1)
  308. yearobject.setTextOrigin(67, HEIGHT-20)
  309. yearobject.setWordSpace(21)
  310. yearobject.textLines("2 0 1 5")
  311. c.drawText(yearobject)
  312. Tiers_Logo(c, DispUser)
  313. if 1:
  314. Ribbon90(DispUser, c)
  315. if 0:
  316. c.rotate(90)
  317. offset_u=111
  318. if DispUser.Staff:
  319. # Staff
  320. c.setFillColorRGB(1,.2,.2)
  321. c.rect(-5, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1)
  322. c.setFillColorRGB(1,1,1)
  323. c.setFont('Liberation', 30)
  324. c.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+5, "STAFF")
  325. elif DispUser.is_Intervenant:
  326. # Intervenant
  327. c.setFillColorRGB(.3,.3,1)
  328. c.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1)
  329. c.setFillColorRGB(1,1,1)
  330. c.setFont('Liberation', 15)
  331. c.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+10, "Intervenant")
  332. else:
  333. # Visiteur
  334. c.setFillColorRGB(.8,.8,.8)
  335. c.rect(-5, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1)
  336. c.setFillColorRGB(0,0,0)
  337. c.setFont('Liberation', 19)
  338. c.drawCentredString(WIDTH/2, HEIGHT/2-offset_u+7, "Visiteur")
  339. c.restoreState()
  340. c.setFont('Courier', 18)
  341. c.setStrokeColorRGB(0,0,0)
  342. c.setFillColorRGB(0,0,0)
  343. # Feed Name and SurName
  344. if len(DispUser.prenom) + len(DispUser.nom)>18:
  345. if DispUser.pseudo:
  346. c.drawCentredString(WIDTH/2, HEIGHT/2 + 4 * mm , "%s" % DispUser.prenom )
  347. c.setFont('Courier', 17)
  348. c.drawCentredString(WIDTH/2, HEIGHT/2 - 2 * mm , "%s" % DispUser.nom )
  349. else:
  350. c.drawCentredString(WIDTH/2, HEIGHT/2 + 2 * mm , "%s" % DispUser.prenom )
  351. c.setFont('Courier', 17)
  352. c.drawCentredString(WIDTH/2, HEIGHT/2 - 6 * mm , "%s" % DispUser.nom )
  353. else:
  354. c.drawCentredString(WIDTH/2, HEIGHT/2 + 0 * mm , "%s %s" % (DispUser.prenom, DispUser.nom) )
  355. #c.drawCentredString(WIDTH/2, HEIGHT - 22 * mm, )
  356. if DispUser.pseudo:
  357. #c.setFont('Liberation', 14)
  358. c.setFont("Helvetica-Oblique", 14)
  359. c.drawCentredString(WIDTH/2, HEIGHT/2 - 8 * mm , "\"%s\"" % DispUser.pseudo )
  360. #c.restoreState()
  361. # Put QR code to user profile
  362. c.drawInlineImage(QRCode(DispUser), \
  363. WIDTH - 20 * mm - 7, 0, \
  364. 20 * mm, 20 * mm, \
  365. preserveAspectRatio=True, \
  366. anchor='s')
  367. c.showPage()
  368. c.save()
  369. pdf.seek(0)
  370. return Response(app_iter=pdf, content_type = 'application/pdf' )
  371. @view_config(route_name='badge_user2')
  372. def badge_user2(request):
  373. user_slug = request.matchdict.get('user_slug', None)
  374. if user_slug is None or len(user_slug)==0:
  375. raise HTTPNotFound(u"Cet utilisateur n'a pas été reconnu")
  376. # Query database
  377. DispUser = User.by_slug(user_slug)
  378. if DispUser is None:
  379. raise HTTPNotFound()
  380. # Ok let's generate a PDF Badge
  381. ttfFile = "jm2l/static/fonts/LiberationMono-Regular.ttf"
  382. ttfFile_Logo = "jm2l/static/fonts/PWTinselLetters.ttf"
  383. pdfmetrics.registerFont(TTFont("Liberation", ttfFile))
  384. pdfmetrics.registerFont(TTFont("Logo", ttfFile_Logo))
  385. pdf = StringIO.StringIO()
  386. qr = qrcode.QRCode(
  387. version=1,
  388. error_correction=qrcode.constants.ERROR_CORRECT_L,
  389. box_size=10,
  390. border=2,
  391. )
  392. # Data of QR code
  393. qr.add_data('http://jm2l.linux-azur.org/user/%s' % DispUser.slug)
  394. qr.make(fit=True)
  395. img = qr.make_image()
  396. # Create PDF container
  397. WIDTH = 85 * mm
  398. HEIGHT = 60 * mm
  399. ICONSIZE = 10 * mm
  400. c = canvas.Canvas( pdf, pagesize=(WIDTH, HEIGHT) )
  401. c.translate(mm, mm)
  402. # Feed some metadata
  403. c.setCreator("linux-azur.org")
  404. c.setTitle("Badge")
  405. c.saveState()
  406. logoobject = c.beginText()
  407. logoobject.setFont('Logo', 52)
  408. logoobject.setFillColorRGB(.83,0,.33)
  409. logoobject.setTextOrigin(55, HEIGHT-50)
  410. logoobject.textLines("JM2L")
  411. c.drawText(logoobject)
  412. yearobject = c.beginText()
  413. yearobject.setFont("Helvetica-Bold", 15)
  414. yearobject.setFillColorRGB(1,1,1)
  415. yearobject.setTextOrigin(67, HEIGHT-20)
  416. yearobject.setWordSpace(21)
  417. yearobject.textLines("2 0 1 5")
  418. c.drawText(yearobject)
  419. if 1:
  420. c.rotate(-35)
  421. c.translate(-100, -70)
  422. offset_u=0
  423. if DispUser.Staff:
  424. # Staff
  425. c.setFillColorRGB(1,.2,.2)
  426. c.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1)
  427. c.setFillColorRGB(1,1,1)
  428. c.setFont('Liberation', 20)
  429. c.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+5, "STAFF")
  430. elif DispUser.is_Intervenant:
  431. # Intervenant
  432. c.setFillColorRGB(.21,.3,1)
  433. c.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1)
  434. c.setFillColorRGB(1,1,1)
  435. c.setFont('Liberation', 15)
  436. c.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+10, "Intervenant")
  437. else:
  438. # Visiteur
  439. c.setFillColorRGB(.8,.8,.8)
  440. c.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1)
  441. c.setFillColorRGB(0,0,0)
  442. c.setFont('Liberation', 12)
  443. c.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+7, "Visiteur")
  444. c.restoreState()
  445. c.setFont('Courier', 18)
  446. c.setStrokeColorRGB(0,0,0)
  447. c.setFillColorRGB(0,0,0)
  448. # Feed Name and SurName
  449. if len(DispUser.prenom) + len(DispUser.nom)>18:
  450. if DispUser.pseudo:
  451. c.drawCentredString(WIDTH/2, HEIGHT/2 + 4 * mm , "%s" % DispUser.prenom )
  452. c.setFont('Courier', 17)
  453. c.drawCentredString(WIDTH/2, HEIGHT/2 - 2 * mm , "%s" % DispUser.nom )
  454. else:
  455. c.drawCentredString(WIDTH/2, HEIGHT/2 + 2 * mm , "%s" % DispUser.prenom )
  456. c.setFont('Courier', 17)
  457. c.drawCentredString(WIDTH/2, HEIGHT/2 - 6 * mm , "%s" % DispUser.nom )
  458. else:
  459. c.drawCentredString(WIDTH/2, HEIGHT/2 + 0 * mm , "%s %s" % (DispUser.prenom, DispUser.nom) )
  460. #c.drawCentredString(WIDTH/2, HEIGHT - 22 * mm, )
  461. if DispUser.pseudo:
  462. #c.setFont('Liberation', 14)
  463. c.setFont("Helvetica-Oblique", 14)
  464. c.drawCentredString(WIDTH/2, HEIGHT/2 - 8 * mm , "\"%s\"" % DispUser.pseudo )
  465. #c.restoreState()
  466. # Put Tiers logos
  467. Tiers_Logo(c, DispUser)
  468. # Put QR code to user profile
  469. c.drawInlineImage(img, WIDTH - 20 * mm - 7, 0, 20 * mm, 20 * mm, preserveAspectRatio=True, anchor='s')
  470. c.showPage()
  471. c.save()
  472. pdf.seek(0)
  473. return Response(app_iter=pdf, content_type = 'application/pdf' )