|
|
@@ -0,0 +1,561 @@ |
|
|
|
# -*- coding: utf8 -*- |
|
|
|
from pyramid.httpexceptions import HTTPNotFound |
|
|
|
from pyramid.response import Response |
|
|
|
import cStringIO as StringIO |
|
|
|
from pyramid.view import view_config |
|
|
|
from .models import User |
|
|
|
|
|
|
|
from reportlab.pdfgen import canvas |
|
|
|
from reportlab.pdfbase import pdfmetrics |
|
|
|
from reportlab.pdfbase.ttfonts import TTFont |
|
|
|
from reportlab.lib.units import mm |
|
|
|
import qrcode |
|
|
|
|
|
|
|
# Create PDF container |
|
|
|
WIDTH = 85 * mm |
|
|
|
HEIGHT = 60 * mm |
|
|
|
ICONSIZE = 8 * mm |
|
|
|
|
|
|
|
def Ribbon35(DispUser, canvas): |
|
|
|
canvas.saveState() |
|
|
|
canvas.rotate(35) |
|
|
|
offset_u=0 |
|
|
|
if DispUser.Staff: |
|
|
|
# Staff |
|
|
|
canvas.setFillColorRGB(1,.2,.2) |
|
|
|
canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
canvas.setFillColorRGB(1,1,1) |
|
|
|
canvas.setFont('Liberation', 20) |
|
|
|
canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+5, "STAFF") |
|
|
|
elif DispUser.is_Intervenant: |
|
|
|
# Intervenant |
|
|
|
canvas.setFillColorRGB(.3,.3,1) |
|
|
|
canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
canvas.setFillColorRGB(1,1,1) |
|
|
|
canvas.setFont('Liberation', 15) |
|
|
|
canvas.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+10, "Intervenant") |
|
|
|
else: |
|
|
|
# Visiteur |
|
|
|
canvas.setFillColorRGB(.8,.8,.8) |
|
|
|
canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
canvas.setFillColorRGB(0,0,0) |
|
|
|
canvas.setFont('Liberation', 12) |
|
|
|
canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+7, "Visiteur") |
|
|
|
canvas.restoreState() |
|
|
|
return canvas |
|
|
|
|
|
|
|
def Ribbon45(DispUser, canvas): |
|
|
|
canvas.saveState() |
|
|
|
canvas.rotate(45) |
|
|
|
offset_u=0 |
|
|
|
if DispUser.Staff: |
|
|
|
# Staff |
|
|
|
canvas.setFillColorRGB(1,.2,.2) |
|
|
|
canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
canvas.setFillColorRGB(1,1,1) |
|
|
|
canvas.setFont('Liberation', 20) |
|
|
|
canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+5, "STAFF") |
|
|
|
elif DispUser.is_Intervenant: |
|
|
|
# Intervenant |
|
|
|
canvas.setFillColorRGB(.3,.3,1) |
|
|
|
canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
canvas.setFillColorRGB(1,1,1) |
|
|
|
canvas.setFont('Liberation', 15) |
|
|
|
canvas.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+10, "Intervenant") |
|
|
|
else: |
|
|
|
# Visiteur |
|
|
|
canvas.setFillColorRGB(.8,.8,.8) |
|
|
|
canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
canvas.setFillColorRGB(0,0,0) |
|
|
|
canvas.setFont('Liberation', 12) |
|
|
|
canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+7, "Visiteur") |
|
|
|
canvas.restoreState() |
|
|
|
return canvas |
|
|
|
|
|
|
|
def Ribbon90(DispUser, canvas): |
|
|
|
canvas.saveState() |
|
|
|
canvas.rotate(90) |
|
|
|
offset_u=0 |
|
|
|
if DispUser.Staff: |
|
|
|
# Staff |
|
|
|
canvas.setFillColorRGB(1,.2,.2) |
|
|
|
canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
canvas.setFillColorRGB(1,1,1) |
|
|
|
canvas.setFont('Liberation', 20) |
|
|
|
canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+5, "STAFF") |
|
|
|
elif DispUser.is_Intervenant: |
|
|
|
# Intervenant |
|
|
|
canvas.setFillColorRGB(.3,.3,1) |
|
|
|
canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
canvas.setFillColorRGB(1,1,1) |
|
|
|
canvas.setFont('Liberation', 15) |
|
|
|
canvas.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+10, "Intervenant") |
|
|
|
else: |
|
|
|
# Visiteur |
|
|
|
canvas.setFillColorRGB(.8,.8,.8) |
|
|
|
canvas.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
canvas.setFillColorRGB(0,0,0) |
|
|
|
canvas.setFont('Liberation', 12) |
|
|
|
canvas.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+7, "Visiteur") |
|
|
|
canvas.restoreState() |
|
|
|
return canvas |
|
|
|
|
|
|
|
def JM2L_Logo(canvas, Position="Up"): |
|
|
|
# Import font |
|
|
|
ttfFile_Logo = "jm2l/static/fonts/PWTinselLetters.ttf" |
|
|
|
pdfmetrics.registerFont(TTFont("Logo", ttfFile_Logo)) |
|
|
|
|
|
|
|
if Position=="Up": |
|
|
|
logoobject = canvas.beginText() |
|
|
|
logoobject.setFont('Logo', 52) |
|
|
|
logoobject.setFillColorRGB(.83,0,.33) |
|
|
|
logoobject.setTextOrigin(55, HEIGHT-50) |
|
|
|
logoobject.textLines("JM2L") |
|
|
|
canvas.drawText(logoobject) |
|
|
|
|
|
|
|
yearobject = canvas.beginText() |
|
|
|
yearobject.setFont("Helvetica-Bold", 15) |
|
|
|
yearobject.setFillColorRGB(1,1,1) |
|
|
|
yearobject.setTextOrigin(67, HEIGHT-20) |
|
|
|
yearobject.setWordSpace(21) |
|
|
|
yearobject.textLines("2 0 1 5") |
|
|
|
canvas.drawText(yearobject) |
|
|
|
elif Position=="Down": |
|
|
|
logoobject = canvas.beginText() |
|
|
|
logoobject.setFont('Logo', 32) |
|
|
|
logoobject.setFillColorRGB(.83,0,.33) |
|
|
|
logoobject.setTextOrigin(2, 17) |
|
|
|
logoobject.textLines("JM2L") |
|
|
|
canvas.drawText(logoobject) |
|
|
|
|
|
|
|
yearobject = canvas.beginText() |
|
|
|
yearobject.setFont("Helvetica-Bold", 10) |
|
|
|
yearobject.setFillColorRGB(1,1,1) |
|
|
|
#yearobject.setLineWidth(.1) |
|
|
|
#yearobject.setStrokeColorRGB(.5,.5,.5) |
|
|
|
yearobject.setTextRenderMode(0) |
|
|
|
#yearobject.setStrokeOverprint(.2) |
|
|
|
yearobject.setTextOrigin(9 , 35) |
|
|
|
yearobject.setWordSpace(13) |
|
|
|
yearobject.textLines("2 0 1 5") |
|
|
|
canvas.drawText(yearobject) |
|
|
|
|
|
|
|
def Tiers_Logo(canvas, DispUser, LWidth=4, StartPos=None): |
|
|
|
Border = 1 |
|
|
|
if StartPos is None: |
|
|
|
StartPos = ( WIDTH -70, 0 ) |
|
|
|
StartX, StartY = StartPos |
|
|
|
num = 0 |
|
|
|
canvas.setStrokeColorRGB(0.5,0.5,0.5) |
|
|
|
Logos = filter(lambda x:x.ThumbLinks, DispUser.tiers) |
|
|
|
for tiers in Logos: |
|
|
|
FileName = tiers.ThumbLinks.pop().split("/")[-1] |
|
|
|
ImagePath = "jm2l/upload/images/tiers/%s/%s" % (tiers.slug, FileName) |
|
|
|
# Should We compute a better positionning for logos ? |
|
|
|
#PosX = StartX + (( (2.0*num+1) / 2*len(Logos) )*(ICONSIZE+Border) - ((ICONSIZE+Border)/2)) |
|
|
|
PosX = StartX + (num % LWidth) * (ICONSIZE+Border) |
|
|
|
if len(Logos)<=LWidth: |
|
|
|
# Middle of line |
|
|
|
PosY = StartY + 0.5 * (ICONSIZE+Border) |
|
|
|
else: |
|
|
|
# in two or more lines |
|
|
|
PosY = StartY + (num / LWidth) * (ICONSIZE+Border) |
|
|
|
canvas.setLineWidth(.1) |
|
|
|
canvas.drawImage(ImagePath, |
|
|
|
PosX, PosY, ICONSIZE, ICONSIZE,\ |
|
|
|
preserveAspectRatio=True, |
|
|
|
anchor='c', |
|
|
|
mask=[0,3,0,3,0,3] |
|
|
|
) |
|
|
|
canvas.roundRect(PosX, PosY, ICONSIZE, ICONSIZE, radius=2, stroke=True) |
|
|
|
num+=1 |
|
|
|
|
|
|
|
def QRCode(DispUser): |
|
|
|
qr = qrcode.QRCode( |
|
|
|
version=1, |
|
|
|
error_correction=qrcode.constants.ERROR_CORRECT_L, |
|
|
|
box_size=10, |
|
|
|
border=2, |
|
|
|
) |
|
|
|
# Data of QR code |
|
|
|
qr.add_data('http://jm2l.linux-azur.org/user/%s' % DispUser.slug) |
|
|
|
qr.make(fit=True) |
|
|
|
|
|
|
|
return qr.make_image() |
|
|
|
|
|
|
|
@view_config(route_name='badge_user') |
|
|
|
def badge_user(request): |
|
|
|
user_slug = request.matchdict.get('user_slug', None) |
|
|
|
if user_slug is None or len(user_slug)==0: |
|
|
|
raise HTTPNotFound(u"Cet utilisateur n'a pas été reconnu") |
|
|
|
# Query database |
|
|
|
DispUser = User.by_slug(user_slug) |
|
|
|
if DispUser is None: |
|
|
|
raise HTTPNotFound() |
|
|
|
|
|
|
|
# Ok let's generate a PDF Badge |
|
|
|
|
|
|
|
# Register LiberationMono font |
|
|
|
ttfFile = "jm2l/static/fonts/LiberationMono-Regular.ttf" |
|
|
|
pdfmetrics.registerFont(TTFont("Liberation", ttfFile)) |
|
|
|
|
|
|
|
pdf = StringIO.StringIO() |
|
|
|
|
|
|
|
c = canvas.Canvas( pdf, pagesize=(WIDTH, HEIGHT) ) |
|
|
|
c.translate(mm, mm) |
|
|
|
|
|
|
|
# Feed some metadata |
|
|
|
c.setCreator("linux-azur.org") |
|
|
|
c.setTitle("Badge") |
|
|
|
|
|
|
|
c.saveState() |
|
|
|
# Logo on Top |
|
|
|
JM2L_Logo(c, "Down") |
|
|
|
|
|
|
|
if DispUser.Staff: |
|
|
|
# Staff |
|
|
|
c.setFillColorRGB(.83,0,.33) |
|
|
|
c.rect(-3, HEIGHT-30, WIDTH, HEIGHT, fill=1) |
|
|
|
c.setFillColorRGB(1,1,1) |
|
|
|
c.setFont('Liberation', 30) |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT-26, "STAFF") |
|
|
|
elif DispUser.is_Intervenant: |
|
|
|
# Intervenant |
|
|
|
c.setFillColorRGB(.3,.3,1) |
|
|
|
c.rect(-3, HEIGHT-30, WIDTH, HEIGHT, fill=1) |
|
|
|
c.setFillColorRGB(1,1,1) |
|
|
|
c.setFont('Liberation', 30) |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT-26, "Intervenant") |
|
|
|
else: |
|
|
|
# Visiteur |
|
|
|
c.setFillColorRGB(.8,.8,.8) |
|
|
|
c.rect(-3, HEIGHT-30, WIDTH, HEIGHT, fill=1) |
|
|
|
c.setFillColorRGB(1,1,1) |
|
|
|
c.setFont('Liberation', 30) |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT-26, "Visiteur") |
|
|
|
|
|
|
|
c.restoreState() |
|
|
|
|
|
|
|
c.setFont('Liberation', 18) |
|
|
|
c.setStrokeColorRGB(0,0,0) |
|
|
|
c.setFillColorRGB(0,0,0) |
|
|
|
# Feed Name and SurName |
|
|
|
if len(DispUser.prenom) + len(DispUser.nom)>18: |
|
|
|
if DispUser.pseudo: |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 + 4 * mm , "%s" % DispUser.prenom ) |
|
|
|
c.setFont('Courier', 17) |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 - 2 * mm , "%s" % DispUser.nom ) |
|
|
|
else: |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 + 2 * mm , "%s" % DispUser.prenom ) |
|
|
|
c.setFont('Courier', 17) |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 - 6 * mm , "%s" % DispUser.nom ) |
|
|
|
else: |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 + 0 * mm , "%s %s" % (DispUser.prenom, DispUser.nom) ) |
|
|
|
|
|
|
|
if DispUser.pseudo: |
|
|
|
c.setFont("Helvetica-Oblique", 14) |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 - 8 * mm , "%s" % DispUser.pseudo ) |
|
|
|
|
|
|
|
# Put QR code to user profile |
|
|
|
c.drawInlineImage(QRCode(DispUser), \ |
|
|
|
WIDTH - 20 * mm - 7, 0, \ |
|
|
|
20 * mm, 20 * mm, \ |
|
|
|
preserveAspectRatio=True, \ |
|
|
|
anchor='s') |
|
|
|
|
|
|
|
Tiers_Logo(c, DispUser, 4, ( 30 * mm, 2 )) |
|
|
|
|
|
|
|
c.showPage() |
|
|
|
c.save() |
|
|
|
pdf.seek(0) |
|
|
|
return Response(app_iter=pdf, content_type = 'application/pdf' ) |
|
|
|
|
|
|
|
@view_config(route_name='badge_user1') |
|
|
|
def badge_user1(request): |
|
|
|
user_slug = request.matchdict.get('user_slug', None) |
|
|
|
if user_slug is None or len(user_slug)==0: |
|
|
|
raise HTTPNotFound(u"Cet utilisateur n'a pas été reconnu") |
|
|
|
# Query database |
|
|
|
DispUser = User.by_slug(user_slug) |
|
|
|
if DispUser is None: |
|
|
|
raise HTTPNotFound() |
|
|
|
|
|
|
|
# Ok let's generate a PDF Badge |
|
|
|
ttfFile = "jm2l/static/fonts/LiberationMono-Regular.ttf" |
|
|
|
ttfFile_Logo = "jm2l/static/fonts/PWTinselLetters.ttf" |
|
|
|
pdfmetrics.registerFont(TTFont("Liberation", ttfFile)) |
|
|
|
pdfmetrics.registerFont(TTFont("Logo", ttfFile_Logo)) |
|
|
|
pdf = StringIO.StringIO() |
|
|
|
|
|
|
|
c = canvas.Canvas( pdf, pagesize=(WIDTH, HEIGHT) ) |
|
|
|
c.translate(mm, mm) |
|
|
|
|
|
|
|
# Feed some metadata |
|
|
|
c.setCreator("linux-azur.org") |
|
|
|
c.setTitle("Badge") |
|
|
|
|
|
|
|
c.saveState() |
|
|
|
|
|
|
|
logoobject = c.beginText() |
|
|
|
logoobject.setFont('Logo', 52) |
|
|
|
logoobject.setFillColorRGB(.83,0,.33) |
|
|
|
logoobject.setTextOrigin(55, HEIGHT-50) |
|
|
|
logoobject.textLines("JM2L") |
|
|
|
c.drawText(logoobject) |
|
|
|
|
|
|
|
|
|
|
|
yearobject = c.beginText() |
|
|
|
yearobject.setFont("Helvetica-Bold", 15) |
|
|
|
yearobject.setFillColorRGB(1,1,1) |
|
|
|
yearobject.setTextOrigin(67, HEIGHT-20) |
|
|
|
yearobject.setWordSpace(21) |
|
|
|
yearobject.textLines("2 0 1 5") |
|
|
|
c.drawText(yearobject) |
|
|
|
|
|
|
|
num = 0 |
|
|
|
for tiers in DispUser.tiers: |
|
|
|
if tiers.ThumbLinks: |
|
|
|
FileName = tiers.ThumbLinks.pop().split("/")[-1] |
|
|
|
num+=1 |
|
|
|
ImagePath = "jm2l/upload/images/tiers/%s/%s" % (tiers.slug, FileName) |
|
|
|
if num<6: |
|
|
|
c.drawImage(ImagePath, |
|
|
|
WIDTH -5 - num * (ICONSIZE+5), 5, ICONSIZE, ICONSIZE,\ |
|
|
|
preserveAspectRatio=True, |
|
|
|
anchor='c', |
|
|
|
mask=[0,3,0,3,0,3]) |
|
|
|
else: |
|
|
|
c.drawImage(ImagePath, |
|
|
|
WIDTH -5 - (num-5) * (ICONSIZE+5), 5 + ICONSIZE, ICONSIZE, ICONSIZE,\ |
|
|
|
preserveAspectRatio=True, |
|
|
|
anchor='c', |
|
|
|
mask=[0,3,0,3,0,3]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if 1: |
|
|
|
Ribbon90(DispUser, c) |
|
|
|
|
|
|
|
if 0: |
|
|
|
c.rotate(90) |
|
|
|
offset_u=111 |
|
|
|
if DispUser.Staff: |
|
|
|
# Staff |
|
|
|
c.setFillColorRGB(1,.2,.2) |
|
|
|
c.rect(-5, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
c.setFillColorRGB(1,1,1) |
|
|
|
c.setFont('Liberation', 30) |
|
|
|
c.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+5, "STAFF") |
|
|
|
elif DispUser.is_Intervenant: |
|
|
|
# Intervenant |
|
|
|
c.setFillColorRGB(.3,.3,1) |
|
|
|
c.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
c.setFillColorRGB(1,1,1) |
|
|
|
c.setFont('Liberation', 15) |
|
|
|
c.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+10, "Intervenant") |
|
|
|
else: |
|
|
|
# Visiteur |
|
|
|
c.setFillColorRGB(.8,.8,.8) |
|
|
|
c.rect(-5, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
c.setFillColorRGB(0,0,0) |
|
|
|
c.setFont('Liberation', 19) |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2-offset_u+7, "Visiteur") |
|
|
|
c.restoreState() |
|
|
|
|
|
|
|
c.setFont('Courier', 18) |
|
|
|
c.setStrokeColorRGB(0,0,0) |
|
|
|
c.setFillColorRGB(0,0,0) |
|
|
|
# Feed Name and SurName |
|
|
|
if len(DispUser.prenom) + len(DispUser.nom)>18: |
|
|
|
if DispUser.pseudo: |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 + 4 * mm , "%s" % DispUser.prenom ) |
|
|
|
c.setFont('Courier', 17) |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 - 2 * mm , "%s" % DispUser.nom ) |
|
|
|
else: |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 + 2 * mm , "%s" % DispUser.prenom ) |
|
|
|
c.setFont('Courier', 17) |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 - 6 * mm , "%s" % DispUser.nom ) |
|
|
|
else: |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 + 0 * mm , "%s %s" % (DispUser.prenom, DispUser.nom) ) |
|
|
|
#c.drawCentredString(WIDTH/2, HEIGHT - 22 * mm, ) |
|
|
|
if DispUser.pseudo: |
|
|
|
#c.setFont('Liberation', 14) |
|
|
|
c.setFont("Helvetica-Oblique", 14) |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 - 8 * mm , "\"%s\"" % DispUser.pseudo ) |
|
|
|
#c.restoreState() |
|
|
|
|
|
|
|
# Put QR code to user profile |
|
|
|
c.drawInlineImage(QRCode(DispUser), \ |
|
|
|
WIDTH - 20 * mm - 7, 0, \ |
|
|
|
20 * mm, 20 * mm, \ |
|
|
|
preserveAspectRatio=True, \ |
|
|
|
anchor='s') |
|
|
|
|
|
|
|
c.showPage() |
|
|
|
c.save() |
|
|
|
pdf.seek(0) |
|
|
|
return Response(app_iter=pdf, content_type = 'application/pdf' ) |
|
|
|
|
|
|
|
|
|
|
|
@view_config(route_name='badge_user2') |
|
|
|
def badge_user2(request): |
|
|
|
user_slug = request.matchdict.get('user_slug', None) |
|
|
|
if user_slug is None or len(user_slug)==0: |
|
|
|
raise HTTPNotFound(u"Cet utilisateur n'a pas été reconnu") |
|
|
|
# Query database |
|
|
|
DispUser = User.by_slug(user_slug) |
|
|
|
if DispUser is None: |
|
|
|
raise HTTPNotFound() |
|
|
|
|
|
|
|
# Ok let's generate a PDF Badge |
|
|
|
ttfFile = "jm2l/static/fonts/LiberationMono-Regular.ttf" |
|
|
|
ttfFile_Logo = "jm2l/static/fonts/PWTinselLetters.ttf" |
|
|
|
pdfmetrics.registerFont(TTFont("Liberation", ttfFile)) |
|
|
|
pdfmetrics.registerFont(TTFont("Logo", ttfFile_Logo)) |
|
|
|
pdf = StringIO.StringIO() |
|
|
|
|
|
|
|
qr = qrcode.QRCode( |
|
|
|
version=1, |
|
|
|
error_correction=qrcode.constants.ERROR_CORRECT_L, |
|
|
|
box_size=10, |
|
|
|
border=2, |
|
|
|
) |
|
|
|
# Data of QR code |
|
|
|
qr.add_data('http://jm2l.linux-azur.org/user/%s' % DispUser.slug) |
|
|
|
qr.make(fit=True) |
|
|
|
|
|
|
|
img = qr.make_image() |
|
|
|
# Create PDF container |
|
|
|
WIDTH = 85 * mm |
|
|
|
HEIGHT = 60 * mm |
|
|
|
ICONSIZE = 10 * mm |
|
|
|
c = canvas.Canvas( pdf, pagesize=(WIDTH, HEIGHT) ) |
|
|
|
c.translate(mm, mm) |
|
|
|
|
|
|
|
# Feed some metadata |
|
|
|
c.setCreator("linux-azur.org") |
|
|
|
c.setTitle("Badge") |
|
|
|
|
|
|
|
c.saveState() |
|
|
|
|
|
|
|
logoobject = c.beginText() |
|
|
|
logoobject.setFont('Logo', 52) |
|
|
|
logoobject.setFillColorRGB(.83,0,.33) |
|
|
|
logoobject.setTextOrigin(55, HEIGHT-50) |
|
|
|
logoobject.textLines("JM2L") |
|
|
|
c.drawText(logoobject) |
|
|
|
|
|
|
|
|
|
|
|
yearobject = c.beginText() |
|
|
|
yearobject.setFont("Helvetica-Bold", 15) |
|
|
|
yearobject.setFillColorRGB(1,1,1) |
|
|
|
yearobject.setTextOrigin(67, HEIGHT-20) |
|
|
|
yearobject.setWordSpace(21) |
|
|
|
yearobject.textLines("2 0 1 5") |
|
|
|
c.drawText(yearobject) |
|
|
|
|
|
|
|
num = 0 |
|
|
|
for tiers in DispUser.tiers: |
|
|
|
if tiers.ThumbLinks: |
|
|
|
FileName = tiers.ThumbLinks.pop().split("/")[-1] |
|
|
|
num+=1 |
|
|
|
ImagePath = "jm2l/upload/images/tiers/%s/%s" % (tiers.slug, FileName) |
|
|
|
if num<6: |
|
|
|
c.drawImage(ImagePath, |
|
|
|
WIDTH -5 - num * (ICONSIZE+5), 5, ICONSIZE, ICONSIZE,\ |
|
|
|
preserveAspectRatio=True, |
|
|
|
anchor='c', |
|
|
|
mask=[0,3,0,3,0,3]) |
|
|
|
else: |
|
|
|
c.drawImage(ImagePath, |
|
|
|
WIDTH -5 - (num-5) * (ICONSIZE+5), 5 + ICONSIZE, ICONSIZE, ICONSIZE,\ |
|
|
|
preserveAspectRatio=True, |
|
|
|
anchor='c', |
|
|
|
mask=[0,3,0,3,0,3]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if 1: |
|
|
|
c.rotate(35) |
|
|
|
offset_u=0 |
|
|
|
if DispUser.Staff: |
|
|
|
# Staff |
|
|
|
c.setFillColorRGB(1,.2,.2) |
|
|
|
c.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
c.setFillColorRGB(1,1,1) |
|
|
|
c.setFont('Liberation', 20) |
|
|
|
c.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+5, "STAFF") |
|
|
|
elif DispUser.is_Intervenant: |
|
|
|
# Intervenant |
|
|
|
c.setFillColorRGB(.3,.3,1) |
|
|
|
c.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
c.setFillColorRGB(1,1,1) |
|
|
|
c.setFont('Liberation', 15) |
|
|
|
c.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+10, "Intervenant") |
|
|
|
else: |
|
|
|
# Visiteur |
|
|
|
c.setFillColorRGB(.8,.8,.8) |
|
|
|
c.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
c.setFillColorRGB(0,0,0) |
|
|
|
c.setFont('Liberation', 12) |
|
|
|
c.drawCentredString(WIDTH/2-10, HEIGHT/2-offset_u+7, "Visiteur") |
|
|
|
|
|
|
|
if 0: |
|
|
|
c.rotate(90) |
|
|
|
offset_u=111 |
|
|
|
if DispUser.Staff: |
|
|
|
# Staff |
|
|
|
c.setFillColorRGB(1,.2,.2) |
|
|
|
c.rect(-5, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
c.setFillColorRGB(1,1,1) |
|
|
|
c.setFont('Liberation', 30) |
|
|
|
c.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+5, "STAFF") |
|
|
|
elif DispUser.is_Intervenant: |
|
|
|
# Intervenant |
|
|
|
c.setFillColorRGB(.3,.3,1) |
|
|
|
c.rect(0, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
c.setFillColorRGB(1,1,1) |
|
|
|
c.setFont('Liberation', 15) |
|
|
|
c.drawCentredString(WIDTH/2-15, HEIGHT/2-offset_u+10, "Intervenant") |
|
|
|
else: |
|
|
|
# Visiteur |
|
|
|
c.setFillColorRGB(.8,.8,.8) |
|
|
|
c.rect(-5, HEIGHT/2-offset_u, WIDTH, 10*mm, fill=1) |
|
|
|
c.setFillColorRGB(0,0,0) |
|
|
|
c.setFont('Liberation', 19) |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2-offset_u+7, "Visiteur") |
|
|
|
|
|
|
|
|
|
|
|
c.restoreState() |
|
|
|
|
|
|
|
c.setFont('Courier', 18) |
|
|
|
c.setStrokeColorRGB(0,0,0) |
|
|
|
c.setFillColorRGB(0,0,0) |
|
|
|
# Feed Name and SurName |
|
|
|
if len(DispUser.prenom) + len(DispUser.nom)>18: |
|
|
|
if DispUser.pseudo: |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 + 4 * mm , "%s" % DispUser.prenom ) |
|
|
|
c.setFont('Courier', 17) |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 - 2 * mm , "%s" % DispUser.nom ) |
|
|
|
else: |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 + 2 * mm , "%s" % DispUser.prenom ) |
|
|
|
c.setFont('Courier', 17) |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 - 6 * mm , "%s" % DispUser.nom ) |
|
|
|
else: |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 + 0 * mm , "%s %s" % (DispUser.prenom, DispUser.nom) ) |
|
|
|
#c.drawCentredString(WIDTH/2, HEIGHT - 22 * mm, ) |
|
|
|
if DispUser.pseudo: |
|
|
|
#c.setFont('Liberation', 14) |
|
|
|
c.setFont("Helvetica-Oblique", 14) |
|
|
|
c.drawCentredString(WIDTH/2, HEIGHT/2 - 8 * mm , "\"%s\"" % DispUser.pseudo ) |
|
|
|
#c.restoreState() |
|
|
|
|
|
|
|
# Put QR code to user profile |
|
|
|
c.drawInlineImage(img, WIDTH - 20 * mm - 7, 0, 20 * mm, 20 * mm, preserveAspectRatio=True, anchor='s') |
|
|
|
|
|
|
|
c.showPage() |
|
|
|
c.save() |
|
|
|
pdf.seek(0) |
|
|
|
return Response(app_iter=pdf, content_type = 'application/pdf' ) |