Skip to content

Commit f781040

Browse files
authored
Merge pull request #55 from Xpirix/download_certifying_orgs_certificate
Review Organization's certificate branding
2 parents ac0ea48 + 615215f commit f781040

File tree

7 files changed

+83
-16
lines changed

7 files changed

+83
-16
lines changed
59.8 KB
Binary file not shown.
40.7 KB
Binary file not shown.
42.9 KB
Binary file not shown.
40.8 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

django_project/certification/views/certificate_organisation.py

Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,34 @@ def generate_certificate_pdf(
2626
try:
2727
font_folder = os.path.join(
2828
settings.STATIC_ROOT, 'fonts/times-new-roman')
29+
website_font_folder = os.path.join(
30+
settings.STATIC_ROOT, 'fonts', 'trueno')
2931
bold_ttf_file = os.path.join(
3032
font_folder, 'Times New Roman Gras 700.ttf')
3133
regular_ttf_file = os.path.join(
3234
font_folder, 'Times New Roman 400.ttf')
3335
pdfmetrics.registerFont(TTFont('Noto-Bold', bold_ttf_file))
3436
pdfmetrics.registerFont(TTFont('Noto-Regular', regular_ttf_file))
37+
38+
trueno_extra_bold_ttf_file = os.path.join(
39+
website_font_folder, 'TruenoExBd.ttf')
40+
trueno_regular_ttf_file = os.path.join(
41+
website_font_folder, 'TruenoRg.ttf')
42+
trueno_light_ttf_file = os.path.join(
43+
website_font_folder, 'TruenoLt.ttf')
44+
trueno_light_italic_ttf_file = os.path.join(
45+
website_font_folder, 'TruenoLtIt.ttf')
46+
trueno_ultra_light_ttf_file = os.path.join(
47+
website_font_folder, 'TruenoUlLt.ttf')
48+
trueno_ultra_light_italic_ttf_file = os.path.join(
49+
website_font_folder, 'TruenoUlLtIt.ttf')
50+
pdfmetrics.registerFont(TTFont('Trueno-Extra-Bold', trueno_extra_bold_ttf_file))
51+
pdfmetrics.registerFont(TTFont('Trueno-Regular', trueno_regular_ttf_file))
52+
pdfmetrics.registerFont(TTFont('Trueno-Light', trueno_light_ttf_file))
53+
pdfmetrics.registerFont(TTFont('Trueno-Light-Italic', trueno_light_italic_ttf_file))
54+
pdfmetrics.registerFont(TTFont('Trueno-Ultra-Light', trueno_ultra_light_ttf_file))
55+
pdfmetrics.registerFont(TTFont('Trueno-Ultra-Light-Italic', trueno_ultra_light_italic_ttf_file))
56+
3557
except TTFError:
3658
pass
3759

@@ -44,6 +66,14 @@ def generate_certificate_pdf(
4466
else:
4567
project_logo = None
4668

69+
if certifying_organisation.logo:
70+
if hasattr(certifying_organisation.logo, 'open'):
71+
certifying_organisation.logo.open()
72+
organisation_logo = ImageReader(
73+
certifying_organisation.logo)
74+
else:
75+
organisation_logo = None
76+
4777
if project.project_representative_signature:
4878
project_representative_signature = \
4979
ImageReader(project.project_representative_signature)
@@ -60,6 +90,7 @@ def generate_certificate_pdf(
6090
margin_right = height - 50
6191
margin_left = 50
6292
margin_bottom = 50
93+
max_left = margin_right - 100
6394

6495
# Draw things on the PDF. Here's where the PDF generation happens.
6596
# See the ReportLab documentation for the full list of functionality.
@@ -68,32 +99,69 @@ def generate_certificate_pdf(
6899
background, 0, 0, height=width, width=height,
69100
preserveAspectRatio=True, mask='auto')
70101
page.setFillColorRGB(0.1, 0.1, 0.1)
71-
page.setFont('Times-Roman', 18)
102+
page.setFont('Trueno-Light', 18)
72103

73104
if project_logo is not None:
74105
page.drawImage(
75106
project_logo, 50, 450, width=100, height=100,
76107
preserveAspectRatio=True, mask='auto')
77108

78-
page.setFont('Times-Roman', 12)
79-
date_now = datetime.now()
80-
str_date = date_now.strftime("%m/%d/%Y")
81-
page.drawRightString(
82-
margin_right, width - 50, 'Date issued: {}'.format(str_date))
109+
page.setFont('Trueno-Light', 12)
110+
111+
112+
if organisation_logo is not None:
113+
page.drawImage(
114+
organisation_logo, max_left, 450, height=100, width=100,
115+
preserveAspectRatio=True, anchor='c', mask='auto')
83116

84117
try:
85-
page.setFont('Noto-Bold', 26)
118+
page.setFont('Trueno-Extra-Bold', 32)
86119
except KeyError:
87-
page.setFont('Times-Bold', 26)
120+
page.setFont('Times-Bold', 32)
121+
122+
page.drawCentredString(
123+
center, 400, '{}'.format(certifying_organisation.name))
88124

125+
page.setFont('Trueno-Light', 16)
126+
address = certifying_organisation.address.replace('\n', ', ').replace('\r', '')
89127
page.drawCentredString(
90-
center, 350, '{}'.format(certifying_organisation.name))
91-
page.setFont('Times-Roman', 16)
128+
center, 360,
129+
f'Address: {address}')
130+
131+
if certifying_organisation.url:
132+
page.drawCentredString(
133+
center, 330,
134+
f'Website: {certifying_organisation.url}')
135+
136+
if certifying_organisation.organisation_email:
137+
page.drawCentredString(
138+
center, 300,
139+
f'Contact: {certifying_organisation.organisation_email}')
140+
141+
if certifying_organisation.organisation_phone:
142+
page.drawCentredString(
143+
center, 270,
144+
f'Phone: {certifying_organisation.organisation_phone}')
145+
146+
147+
page.setFont('Trueno-Regular', 24)
92148
page.drawCentredString(
93-
center, 320,
149+
center, 230,
94150
'Is authorized to provide {} training and certification.'.format(
95151
project.name))
96152

153+
page.setFont('Trueno-Regular', 16)
154+
page.drawCentredString(
155+
center, 190,
156+
f'Certificate Reference: {certificate.certificateID}')
157+
158+
date_now = datetime.now()
159+
str_date = date_now.strftime("%d/%m/%Y")
160+
page.drawCentredString(
161+
center, 160,
162+
f'Date issued: {str_date}')
163+
164+
97165
page.setFillColorRGB(0.1, 0.1, 0.1)
98166
if project_representative_signature is not None:
99167
page.drawImage(
@@ -105,7 +173,7 @@ def generate_certificate_pdf(
105173
anchor='s',
106174
mask='auto')
107175

108-
page.setFont('Times-Italic', 12)
176+
page.setFont('Trueno-Light-Italic', 12)
109177
if project.project_representative:
110178
page.drawCentredString(
111179
(margin_right - 150), (margin_bottom + 60),
@@ -115,19 +183,18 @@ def generate_certificate_pdf(
115183
page.line(
116184
(margin_right - 70), (margin_bottom + 55),
117185
(margin_right - 230), (margin_bottom + 55))
118-
page.setFont('Times-Roman', 13)
186+
page.setFont('Trueno-Light', 13)
119187
page.drawCentredString(
120188
(margin_right - 150),
121189
(margin_bottom + 40),
122190
'Project Representative')
123191

124192
# Footnotes.
125-
page.setFont('Times-Roman', 14)
193+
page.setFont('Trueno-Light', 8)
126194
page.drawString(
127195
margin_left,
128196
margin_bottom - 10,
129-
'ID: {}'.format(certificate.certificateID))
130-
page.setFont('Times-Roman', 8)
197+
'This certificate is issued in accordance with the QGIS Certification Programme.')
131198
page.drawString(
132199
margin_left, (margin_bottom - 20),
133200
'You can verify this certificate by visiting '

0 commit comments

Comments
 (0)