cert (Certificates)

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 *

Plain-text representation

The plain-text representation methods of the Certificate model are defined as follows:

def __str__(self):
    return f"{self.enrolment.pupil} {self.period.nickname}"

def get_str_words(self, ar):
    if not ar.is_obvious_field("enrolment"):
        yield str(self.enrolment)
    if not ar.is_obvious_field("period"):
        yield str(self.period)

The following snippets test whether they work as expected.

>>> current_year = periods.StoredYear.get_or_create_from_date(dd.today())
>>> qs = cert.Certificate.objects.filter(enrolment__group__designation="4A")
>>> qs = qs.exclude(enrolment__group__year=current_year)
>>> print(qs.first())
Faustin Blondeel 2023/24-1
>>> qs = cert.Certificate.objects.filter(enrolment__group__designation="5A")
>>> obj = qs.filter(enrolment__group__year=current_year).first()
>>> print(obj.enrolment)
Faustin Blondeel (5A)
>>> print(obj)
Faustin Blondeel 1
>>> print(repr(obj))
Certificate #243 ('Faustin Blondeel 1')
>>> res = AttrDict(get_json_dict("robin", f"cert/Certificates/{obj.pk}"))
>>> print(res['title'])
<a ...>5A</a> &raquo; Faustin Blondeel (5A) 1

When the enrolment is an obvious field, Lino does not show it:

>>> mt = contenttypes.ContentType.objects.get_for_model(school.Enrolment).id
>>> res = get_json_dict("robin", f"cert/CertificatesByEnrolment/{obj.pk}", mk=obj.enrolment.id, mt=mt)
>>> print(res['title'])
<a ...>5A</a> &raquo; 1

The Certificate.enrolment field in the detail view

>>> print(res['data']['enrolment'])
Faustin Blondeel in 5A

Filtering ExamResponsesBySection

The following snippets verify #6484 (Filter nach Kompetenzen). The user has opened the detail view of the “Science” section of the first certificate for pupil Guillaume Borsu in group 6A. This view shows a table of exam responses for this pupil and for the skills covered by this certificate section.

>>> sr = cert.SectionResponse.objects.get(pk=674)
>>> sr.section
CertSection #5 ('Science')
>>> sr.certificate
Certificate #291 ('Guillaume Borsu 1')
>>> rt.show(cert.ExamResponsesBySection, sr)
========================== ====================== ===============================================
 Exam response              Remark                 Ratings
-------------------------- ---------------------- -----------------------------------------------
 `Exam 96 (11.08.) <…>`__   It's never too late.   `0 / 5 <…>`__, `0 / 10 <…>`__
 `Exam 97 (14.08.) <…>`__   It's never too late.   `0 / 20 <…>`__, `0 / 12 <…>`__, `0 / 6 <…>`__
 `Exam 98 (17.08.) <…>`__   It's never too late.   `0 / 8 <…>`__, `0 / 15 <…>`__, `0 / 20 <…>`__
 `Exam 99 (20.08.) <…>`__   It's never too late.   `0 / 30 <…>`__
========================== ====================== ===============================================

This table has three parameter fields:

>>> pprint(cert.ExamResponsesBySection.parameters)
{'enrolment': <django.db.models.fields.related.ForeignKey: enrolment>,
 'exam': <django.db.models.fields.related.ForeignKey: exam>,
 'exam__challenge__skill': <lino.core.vfields.RemoteField: exam__challenge__skill>}
>>> skill = school.Skill.objects.get(designation="History")
>>> pv = dict(exam__challenge__skill=skill)
>>> rt.show(cert.ExamResponsesBySection, sr, param_values=pv)
========================== ====================== ===============================================
 Exam response              Remark                 Ratings
-------------------------- ---------------------- -----------------------------------------------
 `Exam 97 (14.08.) <…>`__   It's never too late.   `0 / 20 <…>`__, `0 / 12 <…>`__, `0 / 6 <…>`__
 `Exam 98 (17.08.) <…>`__   It's never too late.   `0 / 8 <…>`__, `0 / 15 <…>`__, `0 / 20 <…>`__
========================== ====================== ===============================================
>>> skill = school.Skill.objects.get(designation="Geography")
>>> pv = dict(exam__challenge__skill=skill)
>>> rt.show(cert.ExamResponsesBySection, sr, param_values=pv)
========================== ====================== ===============================
 Exam response              Remark                 Ratings
-------------------------- ---------------------- -------------------------------
 `Exam 96 (11.08.) <…>`__   It's never too late.   `0 / 5 <…>`__, `0 / 10 <…>`__
========================== ====================== ===============================
>>> skill = school.Skill.objects.get(designation="Natural science")
>>> pv = dict(exam__challenge__skill=skill)
>>> rt.show(cert.ExamResponsesBySection, sr, param_values=pv)
========================== ====================== ================
 Exam response              Remark                 Ratings
-------------------------- ---------------------- ----------------
 `Exam 99 (20.08.) <…>`__   It's never too late.   `0 / 30 <…>`__
========================== ====================== ================

The Ratings detail

>>> ar = rt.login('robin')
>>> obj = cert.Certificate.objects.get(id=291)
>>> print(obj)
Guillaume Borsu 1
>>> print(obj.enrolment)
Guillaume Borsu (6A)
>>> er = cert.ElementResponse.objects.get(
...     section_response__certificate=obj,
...     cert_element__skill__designation="Geography")
>>> fld = er._meta.get_field('ratings_detail')
>>> res = fld.value_from_object(er, ar)
>>> print(html2text(res))
| Source      | 2024/25-1  | 2024/25-2
| Challenges  | [0.0/5.0](…) \+ [0.0/10.0](…) = 0 / | | 15 (0,0 %)  | no ratings |
|-------------|------------|------------|
| Projects    | no ratings | no ratings |
| Final exams | no ratings | no ratings |
| Certificate | no ratings | no ratings |


The printable certificate

>>> ar = rt.login('robin')
>>> obj = cert.Certificate.objects.get(id=291)
>>> print(obj)
Guillaume Borsu 1
>>> res = "".join(obj.as_page(ar))
>>> print(html2text(res))
# Certificate

Name: BORSU Guillaume

Group: 6A — Schuljahr 2024/25 - 1. Periode

Class teacher: Aimée AELTER; Protestant religion: Abel ADAM; Music: Adèle
ADAMI

###  🖩 Mathematics

| Kompetenz   | Punkte | Prozentsatz |
|-------------|--------|-------------|
| Arithmetics | — / —  |             |
| Stochastics | — / —  |             |
| Gesamt      |  — / — |  —          |


###  Science

| Kompetenz       | Punkte  | Prozentsatz |
|-----------------|---------|-------------|
| Geography       | 0 / 6   | 0,0 %       |
| History         | 0 / 8   | 0,0 %       |
| Natural science | 0 / 15  | 0,0 %       |
| Gesamt          |  0 / 29 |  0,0 %      |


###  🕊 Religion

This Course is _really_ great.

| Kompetenz | Punkte  | Prozentsatz |
|-----------|---------|-------------|
| Knowledge | 0 / 20  | 0,0 %       |
| Behaviour | 0 / 30  | 0,0 %       |
| Attitude  | 0 / 5   | 0,0 %       |
| Gesamt    |  0 / 55 |  0,0 %      |


###  🎜 Music

This Course is _really_ cool.

| Note | Kommentar | | |
|------|-----------|


###  Soft skills

| Skill                                                | ![](file:///.../Smilies/4.png) | ![](file:///.../Smilies/3.png) | ![](file:///.../Smilies/2.png) | ![](file:///.../Smilies/1.png) |
|------------------------------------------------------|-...----------------------------|-...----------------------------|-...----------------------------|-...----------------------------|
| You obey rules                                       |                                |                                |                                |                                |
| You respect your classmates                          |                                |                                |                                |                                |
| You respect your teachers                            |                                |                                |                                |                                |
| You are helpful                                      |                                |                                |                                |                                |
| You are able to cope in situations of conflict       |                                |                                |                                |                                |
| You say your opinion respectfully and can explain it |                                |                                |                                |                                |
| You do your homework carefully                       |                                |                                |                                |                                |
| You focus on your work                               |                                |                                |                                |                                |
| You can work independently                           |                                |                                |                                |                                |
| You have a readable handwriting                      |                                |                                |                                |                                |


### Übersicht

| Fach            | 1      | 2     | Durchschnitt | Mathematics | — | — | — |
|-----------------|--------|-------|--------------|
| Arithmetics     | — / —  | — / — | — / —        |
| Stochastics     | — / —  | — / — | — / —        |
| Science         | 0,0 %  | —     | 0,0 %        |
| Geography       | 0 / 6  | — / — | 0 / 6        |
| History         | 0 / 8  | — / — | 0 / 8        |
| Natural science | 0 / 15 | — / — | 0 / 15       |
| Religion        | 0,0 %  | —     | 0,0 %        |
| Knowledge       | 0 / 20 | — / — | 0 / 20       |
| Behaviour       | 0 / 30 | — / — | 0 / 30       |
| Attitude        | 0 / 5  | — / — | 0 / 5        |
| Music           |        |       | —            |

|  |


##### Abwesenheiten

(in halben Schultagen)

| mit einer **schriftlichen Entschuldigung** |  **ohne** schriftliche Entschuldigung |  mit einem **ärztlichen Attest** |  0 |  0 |  0 |
|--------------------------------------------|---------------------------------------|----------------------------------|


API reference

class lino_prima.plugins.cert.Certificate
enrolment

The pupil for whom this certificate has been issued.

Note that this labelled “Pupil” but actually points to an enrolment, not to a pupil.

absences_m

The number of absences for medical reasons.

absences_p

The number of excused absences with parental proof.

absences_u

The number of unexcused absences.