diff --git a/idhub/static/images/4_Model_Certificat_html_941e7b967953b3f3.jpg b/idhub/static/images/4_Model_Certificat_html_941e7b967953b3f3.jpg new file mode 100644 index 0000000..12e9a3e Binary files /dev/null and b/idhub/static/images/4_Model_Certificat_html_941e7b967953b3f3.jpg differ diff --git a/idhub/templates/certificates/course-credential_ca.html b/idhub/templates/certificates/course-credential_ca.html new file mode 100644 index 0000000..1d1913f --- /dev/null +++ b/idhub/templates/certificates/course-credential_ca.html @@ -0,0 +1,126 @@ +{% load i18n static %} + + + +Certificat + + + + + + + + + +
+
+
+ +
+
+
+
+ + LAFEDE.CAT – ORGANITZACIONS PER A LA JUSTÍCIA GLOBAL
CERTIFICA QUE:

+ {{ firstName }} {{ lastName }} amb DNI {{ document_id|default:"falta el dni" }}
+ Ha realitzat el curs {{ courseName }}, a {{ address|default:"falta address" }} / de manera {{ modeOfInstruction }}, els dies {{ date_course|default:"falta fecha del curso" }}
+ La durada del curs ha estat de {{ courseDuration }} hores lectives corresponents a {{ courseDays }} sessions.
+
+
+
+
+
+ I per deixar-ne constància als efectes oportuns, signo el present certificat en data de {{ issuedDate }} +
+
+ +
+
+ +
+
+ +
+
+ Pepa Martínez Peyrats
+ Directora
+ Lafede.cat - Federació d'Organitzacions per a la Justícia Global +
+
+ {% if qr %} +
+
+ +
+
+ {% endif %} +
+
+ Organitza: + Amb el suport de: + Amb la col·laboració de: +
+
+
+ +
+
+
+
+ + diff --git a/idhub/templates/certificates/course-credential_es.html b/idhub/templates/certificates/course-credential_es.html new file mode 100644 index 0000000..32056c6 --- /dev/null +++ b/idhub/templates/certificates/course-credential_es.html @@ -0,0 +1,126 @@ +{% load i18n static %} + + + +Certificado + + + + + + + + + +
+
+
+ +
+
+
+
+ + LAFEDE.CAT – ORGANIZACIONES PARA LA JUSTÍCIA GLOBAL
CERTIFICA QUE:

+ {{ firstName }} {{ lastName }} con DNI {{ document_id|default:"falta el dni" }}
+ Ha realizado el curso {{ courseName }}, en {{ address|default:"falta address" }} / de manera {{ modeOfInstruction }}, los días {{ date_course|default:"falta fecha del curso" }}
+ La duración del curso ha sido de {{ courseDuration }} horas lectivas correspondientes a {{ courseDays }} sessiones.
+
+
+
+
+
+ Y para dejar constancia a los efectos oportunos, firmo el presente certificado en fecha de {{ issuedDate }} +
+
+ +
+
+ +
+
+ +
+
+ Pepa Martínez Peyrats
+ Directora
+ Lafede.cat - Federación de Organizaciones por la Justícia Global +
+
+ {% if qr %} +
+
+ +
+
+ {% endif %} +
+
+ Organiza: + Con el soporte de: + Con la colaboración de: +
+
+
+ +
+
+
+
+ + diff --git a/idhub/templates/certificates/federation-membership_ca.html b/idhub/templates/certificates/federation-membership_ca.html new file mode 100644 index 0000000..3b83531 --- /dev/null +++ b/idhub/templates/certificates/federation-membership_ca.html @@ -0,0 +1,122 @@ +{% load i18n static %} + + + +Certificat + + + + + + + + + +
+
+
+ +
+
+
+
+

A qui correspongui,

+

+ Pepa Martínez Peyrats, com a directora de Lafede.cat - Federació d'Organitzacions per a la Justícia Global, +

+
+
+ +
+
+ CERTIFICA
+
    +
  • + Que l’entitat {{ legalName }}, amb NIF {{ registrationIdentifier }} i domicili a {{ streetAddress }} {{ postCode }} {{ city }} forma part com a entitat membre de {{ federation }} (ple dret/observadora) de Lafede.cat - Federació d'Organitzacions per a la Justícia Global, des de l’Assemblea General Ordinària celebrada el {{ membershipSince }} +
  • +
+
+
+
+ I per deixar-ne constància als efectes oportuns, signo el present certificat en data de {{ issue_date_now }} +
+
+ +
+
+ +
+
+ +
+
+ Pepa Martínez Peyrats
+ Directora
+ Lafede.cat - Federació d'Organitzacions per a la Justícia Global +
+
+ {% if qr %} +
+
+ +
+
+ {% endif %} +
+ + diff --git a/idhub/templates/certificates/federation-membership_es.html b/idhub/templates/certificates/federation-membership_es.html new file mode 100644 index 0000000..ef4a06f --- /dev/null +++ b/idhub/templates/certificates/federation-membership_es.html @@ -0,0 +1,122 @@ +{% load i18n static %} + + + +Certificado + + + + + + + + + +
+
+
+ +
+
+
+
+

A quién corresponda,

+

+ Pepa Martínez Peyrats, como directora de Lafede.cat - Federación de Organizaciones para la Justícia Global, +

+
+
+ +
+
+ CERTIFICA
+
    +
  • + Que la entidad {{ legalName }}, con NIF {{ registrationIdentifier }} y domicilio {{ streetAddress }} {{ postCode }} {{ city }} forma parte como entidad miembro de {{ federation }} (por el derecho/observadora) de Lafede.cat - Federación de Organizaciones para la Justícia Global, desde la Asamblea General Ordinaria celebrada el {{ membershipSince }} +
  • +
+
+
+
+ Y para dejar constancia a los efectos oportunos, firmo el presente certificado en fecha de {{ issue_date_now }} +
+
+ +
+
+ +
+
+ +
+
+ Pepa Martínez Peyrats
+ Directora
+ Lafede.cat - Federació d'Organitzacions per a la Justícia Global +
+
+ {% if qr %} +
+
+ +
+
+ {% endif %} +
+ + diff --git a/idhub/templates/idhub/user/credential.html b/idhub/templates/idhub/user/credential.html index 9e1e0f4..6362a5e 100644 --- a/idhub/templates/idhub/user/credential.html +++ b/idhub/templates/idhub/user/credential.html @@ -9,19 +9,24 @@ {{ subtitle }} -
- {% if object.get_status == 'Issued' %} -
- {% if object.eidas1_did and admin_validated %} - {% trans 'Download as PDF' %} - {% endif %} - {% trans 'Download as JSON' %} + {% if object.get_status == 'Issued' %} + {% if object.eidas1_did and admin_validated %} + + {% endif %} + {% endif %} +
+ {% if object.get_status == 'Issued' %} + {% if object.eidas1_did and admin_validated %} + {% endif %} + {% trans 'Download as JSON' %} + {% endif %} {% if object.get_status == 'Enabled' %} - {% endif %}
diff --git a/idhub/urls.py b/idhub/urls.py index d0230c9..9ecc8d0 100644 --- a/idhub/urls.py +++ b/idhub/urls.py @@ -73,7 +73,7 @@ urlpatterns = [ name='user_credentials'), path('user/credentials/', views_user.CredentialView.as_view(), name='user_credential'), - path('user/credentials//pdf', views_user.CredentialPdfView.as_view(), + path('user/credentials//pdf/', views_user.CredentialPdfView.as_view(), name='user_credential_pdf'), path('credentials//', views_user.CredentialJsonView.as_view(), name='user_credential_json'), diff --git a/idhub/user/views.py b/idhub/user/views.py index 6db3500..50e0dd3 100644 --- a/idhub/user/views.py +++ b/idhub/user/views.py @@ -209,14 +209,19 @@ class CredentialView(MyWallet, TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) + url_ca = reverse_lazy('idhub:user_credential_pdf', args=[self.object.id, 'ca']) + url_es = reverse_lazy('idhub:user_credential_pdf', args=[self.object.id, 'es']) context.update({ 'object': self.object, + 'url_ca': url_ca, + 'url_es': url_es, }) return context class CredentialPdfView(MyWallet, TemplateView): - template_name = "certificates/4_Model_Certificat.html" + template_name = "certificates/{}_{}.html" + template_name = "certificates/{}_{}.html" subtitle = _('Credential management') icon = 'bi bi-patch-check-fill' file_name = "certificate.pdf" @@ -225,6 +230,7 @@ class CredentialPdfView(MyWallet, TemplateView): if not cache.get("KEY_DIDS"): return redirect(reverse_lazy('idhub:user_dashboard')) pk = kwargs['pk'] + lang = kwargs.get('lang', 'ca') self.user = self.request.user self.object = get_object_or_404( VerificableCredential, @@ -232,6 +238,11 @@ class CredentialPdfView(MyWallet, TemplateView): eidas1_did__isnull=False, user=self.request.user ) + self.credential_type = self.object.schema.file_schema.split(".json")[0] + self.template_name = self.template_name.format( + self.credential_type, + lang + ) self.url_id = "{}://{}/public/credentials/{}".format( self.request.scheme, self.request.get_host(), @@ -247,49 +258,52 @@ class CredentialPdfView(MyWallet, TemplateView): response['Content-Disposition'] = 'attachment; filename={}'.format(self.file_name) return response - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - # this_folder = str(Path.cwd()) + def get_img_sign(self): path_img_sig = "idhub/static/images/4_Model_Certificat_html_58d7f7eeb828cf29.jpg" img_signature = next(Path.cwd().glob(path_img_sig)) with open(img_signature, 'rb') as _f: img_sig = base64.b64encode(_f.read()).decode('utf-8') + return img_sig - path_img_head = "idhub/static/images/4_Model_Certificat_html_7a0214c6fc8f2309.jpg" + def get_img_header(self): + path_img_head = "idhub/static/images/4_Model_Certificat_html_7a0214c6fc8f2309.jpg" img_header= next(Path.cwd().glob(path_img_head)) with open(img_header, 'rb') as _f: img_head = base64.b64encode(_f.read()).decode('utf-8') + return img_head + def get_img_footer(self): + path_img_foot = "idhub/static/images/4_Model_Certificat_html_941e7b967953b3f3.jpg" + img_foot= next(Path.cwd().glob(path_img_foot)) + with open(img_foot, 'rb') as _f: + img_foot = base64.b64encode(_f.read()).decode('utf-8') + return img_foot + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + img_sig = self.get_img_sign() + img_head = self.get_img_header() + img_foot = self.get_img_footer() qr = self.generate_qr_code(self.url_id) + issue_date_now = datetime.datetime.now() - first_name = self.user.first_name and self.user.first_name.upper() or "" - last_name = self.user.first_name and self.user.last_name.upper() or "" - document_id = "0000000-L" - course = "COURSE 1" - address = "ADDRESS" - date_course = datetime.datetime.now() - n_hours = 40 - n_lections = 5 - issue_date = datetime.datetime.now() + context.update(dict(self.object.get_datas())) context.update({ 'object': self.object, "image_signature": img_sig, "image_header": img_head, - "first_name": first_name, - "last_name": last_name, - "document_id": document_id, - "course": course, - "address": address, - "date_course": date_course, - "n_hours": n_hours, - "n_lections": n_lections, - "issue_date": issue_date, - "qr": qr + "image_footer": img_foot, + "issue_date_now": issue_date_now.strftime("%d/%m/%Y"), + "qr": qr, }) return context def build_certificate(self): - doc = self.render_to_response(context=self.get_context_data()) + try: + doc = self.render_to_response(context=self.get_context_data()) + except Exception: + self.template_name = "certificates/4_Model_Certificat_ca.html" + doc = self.render_to_response(context=self.get_context_data()) doc.render() pdf = weasyprint.HTML(string=doc.content) return pdf.write_pdf() @@ -340,7 +354,7 @@ class CredentialPdfView(MyWallet, TemplateView): w = IncrementalPdfFileWriter(_buffer) fields.append_signature_field( w, sig_field_spec=fields.SigFieldSpec( - 'Signature', box=(150, 100, 450, 150) + 'Signature', box=(150, 75, 450, 100) ) )