Printing

A tested document

This is a tested document. The following instructions are used for initialization:

>>> import lino
>>> lino.startup('lino_prima.projects.prima1.settings')
>>> from lino.api.doctest import *

We take an object, clear the cache, ask Lino to print it and check whether we get the expected response.

>>> ses = rt.login("robin")
>>> def printit(obj):
...     print("Going to print", repr(obj))
...     obj.clear_cache()
...     d = ses.run(obj.do_print)
...     assert d['success']
...     print(d['message'])
...
>>> printit(projects.Project.objects.last())
... 
Going to print Project #81 ('Aasiya Crispeel (6B (2023/24)) doing Leb')
weasy2pdf render ['projects/Project/default.weasy.html'] ->
.../media/cache/weasy2pdf/Project-2023_24-6B-Aasiya_Crispeel-Leb-81.pdf ('en', {})
Your printable document (<a href="/media/cache/weasy2pdf/Project-2023_24-6B-Aasiya_Crispeel-Leb-81.pdf">Project-2023_24-6B-Aasiya_Crispeel-Leb-81.pdf</a>) should now open in
a new browser window. If it doesn't, please ask your system administrator.
>>> qs = cert.Certificate.objects.all()
>>> printit(qs.last())  
Going to print Certificate #672 ('Aatifa Crispel 2')
weasy2pdf render ['cert/Certificate/default.weasy.html'] ->
.../media/cache/weasy2pdf/Certificate-2024_25-2-7B-Aatifa_Crispel.pdf ('en', {}) Your printable document (<a
href="/media/cache/weasy2pdf/Certificate-2024_25-2-7B-Aatifa_Crispel.pdf">Certificate-2024_25-2-7B-Aatifa_Crispel.pdf</a>) should now open in
a new browser window. If it doesn't, please ask your system administrator.

The following failed on 20250728 with jinja2.exceptions.UndefinedError: ‘None’ has no attribute ‘rating_type’:

>>> qs = cert.Certificate.objects.filter(enrolment__group__designation="2A")
>>> qs = qs.filter(period__ref="2024/25-2")
>>> printit(qs.last()) 
Going to print Certificate #94 ('Alma André 2')
weasy2pdf render ['cert/Certificate/default.weasy.html'] ->
.../media/cache/weasy2pdf/Certificate-2024_25-2-2A-Alma_Andr_.pdf ('en', {}) Your printable
document (<a
href="/media/cache/weasy2pdf/Certificate-2024_25-2-2A-Alma_Andr_.pdf">Certificate-2024_25-2-2A-Alma_Andr_.pdf</a>)
should now open in a new browser window. If it doesn't, please ask your system
administrator.
>>> qs = school.Group.objects.filter(designation="2A")
>>> printit(qs.last()) 
Going to print Group #2 ('2A (2023/24)')...
Your printable document (<a href="/media/cache/weasy2pdf/Group-2023_24-2-2A.pdf">Group-2023_24-2-2A.pdf</a>) should now open in a new browser window.
If it doesn't, please ask your system administrator.