Le repo des sources pour le site web des JM2L
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

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