Beispiel #1
0
 def __init__(self,
              *,
              registration,
              filename: str,
              as_attachment: bool = False):
     self._response = PdfResponse(filename=filename,
                                  as_attachment=as_attachment)
     self.registration = registration
     self.make_pdf()
Beispiel #2
0
class CertificatePdfMaker:
    def __init__(self,
                 *,
                 registration,
                 filename: str,
                 as_attachment: bool = False):
        self._response = PdfResponse(filename=filename,
                                     as_attachment=as_attachment)
        self.registration = registration
        self.make_pdf()

    def make_pdf(self):
        reg = self.registration
        event = reg.event
        programme = get_programme(reg.event.end_date)
        main_text = f"""
On behalf of the {programme[0]} (HiPEAC), funded under the European {programme[1]} programme
under grant agreement number {programme[2]}, I would hereby like to confirm that **{reg.user.profile.name}**
— {reg.user.profile.institution.name} — attended the HiPEAC {event.year} {event.city} {event.type}
from {date_filter(event.start_date)} to {date_filter(event.end_date)} in {event.city}, {event.country.name}.
"""
        signature = f"""
Please do not hesitate to contact me for additional information.<br />
<br />
The coordinator,<br />
<strong>Koen De Bosschere</strong><br />
Ghent University<br />
Gent, Belgium<br />
<a href="mailto:[email protected]">[email protected]</a>
"""

        with Pdf() as pdf:
            pdf.add_text(str(event), "h4")
            pdf.add_spacer()
            pdf.add_text("Certificate of Attendance", "h1")
            pdf.add_spacer()
            pdf.add_text("To Whom It May Concern,")
            pdf.add_text(main_text, "p", "markdown")
            pdf.add_text(
                f"{reg.user.profile.name} attended the following sessions:")
            for session in reg.sessions.select_related("session_type"):
                if session.session_type.value != "Social Event":
                    t = f'- *{session.session_type.value}:* "{session.title}"'
                    if session.session_type.value == "Keynote":
                        t = f"{t}, by {session.main_speaker.profile.name} ({session.main_speaker.profile.institution})"
                    pdf.add_text(t, "p", "markdown")
            pdf.add_text(
                f"More information can be found on <https://www.hipeac.net{event.get_absolute_url()}>",
                "p", "markdown")
            pdf.add_text(signature, "p")
            pdf.add_page_break()

            self._response.write(pdf.get())

    @property
    def response(self) -> PdfResponse:
        return self._response
Beispiel #3
0
class TechTransferCallPdfMaker:
    def __init__(self, *, calls, filename: str, as_attachment: bool = False):
        self._response = PdfResponse(filename=filename,
                                     as_attachment=as_attachment)
        self.calls = calls
        self.make_pdf()

    def make_pdf(self):
        with Pdf() as pdf:
            for call in self.calls:
                pdf.add_spacer(4)
                pdf.add_text(f"<strong>Call: {str(call).upper()}</strong>",
                             "h1")
                pdf.add_spacer()
                pdf.add_page_break()

                for ap in call.applications.all():
                    pdf.add_text("<small>Tech Transfer application</small>",
                                 "p")
                    pdf.add_text(f"#{ap.id}: {ap.title}", "h1")
                    pdf.add_text(
                        f"<strong>Applicant</strong>: {ap.applicant.profile.name}",
                        "ul_li")
                    pdf.add_text(
                        f"<strong>Affiliation</strong>: {ap.applicant.profile.institution}",
                        "ul_li")
                    pdf.add_text(
                        f"<strong>Email</strong>: {ap.applicant.email}",
                        "ul_li")
                    pdf.add_spacer()
                    pdf.add_text(
                        "Description of the technology being transferred",
                        "h4")
                    pdf.add_text(ap.description, "p_justify", "markdown")
                    pdf.add_spacer()
                    pdf.add_text(
                        "Description of the academic partners and the company involved",
                        "h4")
                    pdf.add_text(ap.partners_description, "p_justify",
                                 "markdown")
                    pdf.add_spacer()
                    pdf.add_text("Estimate of the value of the agreement",
                                 "h4")
                    pdf.add_text(ap.value, "p_justify", "markdown")
                    pdf.add_page_break()

            self._response.write(pdf.get())

    @property
    def response(self) -> PdfResponse:
        return self._response
Beispiel #4
0
class JobsPdfMaker:
    def __init__(self,
                 *,
                 registration,
                 filename: str,
                 as_attachment: bool = False):
        self._response = PdfResponse(filename=filename,
                                     as_attachment=as_attachment)
        self.registration = registration
        self.make_pdf()

    def make_pdf(self):
        with Pdf() as pdf:
            reg = self.registration
            attended = "attended" if reg.event.is_finished() else "will attend"
            institution = f" —{reg.user.profile.institution.name}—" if reg.user.profile.institution else ""

            pdf.add_text(str(reg.event), "h4")
            pdf.add_text(f"Receipt (#{reg.id})", "h1")
            pdf.add_text("To Whom It May Concern,", "p")
            pdf.add_text(
                f"""On behalf of the European Network on High-performance Embedded Architecture and
Compilation (HiPEAC), funded under the {H2020}, I would hereby like to confirm that <strong>{reg.user.profile.name}
{institution}</strong> {attended} the <strong>{reg.event}</strong> event in {reg.event.country.name}, between
{date_filter(reg.event.start_date)} and {date_filter(reg.event.end_date)}.""",
                "p",
            )
            pdf.add_text(
                f"""{reg.user.profile.name} registered for this event on {date_filter(reg.created_at)} and
paid the registration fee of <strong>EUR {reg.total_fee}</strong>.""",
                "p",
            )
            pdf.add_text(
                f"""More information about {reg.event} can be found on
<strong>hipeac.net{reg.event.get_absolute_url()}</strong>.""",
                "p",
            )
            pdf.add_text(
                "Please do not hesitate to contact me for additional information.",
                "p")
            pdf.add_text("The coordinator,<br/>Koen De Bosschere", "p")
            pdf.add_page_break()

            self._response.write(pdf.get())

    @property
    def response(self) -> PdfResponse:
        return self._response
Beispiel #5
0
class JobsPdfMaker:
    def __init__(self, *, jobs, filename: str, as_attachment: bool = False):
        self._response = PdfResponse(filename=filename, as_attachment=as_attachment)
        self.jobs = jobs
        self.make_pdf()

    def make_pdf(self):
        with Pdf() as pdf:
            for job in self.jobs:
                try:
                    location = []
                    if job.location:
                        location.append(job.location)
                    if job.country:
                        location.append(job.country.name)

                    pdf.add_note(f"Find more on our web: hipeac.net/jobs/{job.id}")
                    if job.institution:
                        if job.institution.image:
                            pdf.add_image(job.institution.images["th"], "th")
                        pdf.add_text(f"<strong>{job.institution.name}</strong>", "h4")
                    pdf.add_text(", ".join(location), "h4")
                    pdf.add_spacer()
                    pdf.add_text(job.title, "h1")
                    pdf.add_text(f"<strong>Deadline</strong>: {date_filter(job.deadline)}", "ul_li")
                    pdf.add_text(
                        f'<strong>Career levels</strong>: {job.get_metadata_display("career_levels")}', "ul_li"
                    )
                    pdf.add_text(f'<strong>Keywords</strong>: {job.get_metadata_display("topics")}', "ul_li")
                    pdf.add_spacer()
                    pdf.add_text(job.description, "p_justify", "markdown")
                    pdf.add_page_break()

                except Exception:
                    pdf.add_text(f"<strong>ERROR FOUND: #{job.id} {job.title}</strong>", "h4")
                    pdf.add_page_break()

            self._response.write(pdf.get())

    @property
    def response(self) -> PdfResponse:
        return self._response
Beispiel #6
0
 def __init__(self, *, jobs, filename: str, as_attachment: bool = False):
     self._response = PdfResponse(filename=filename, as_attachment=as_attachment)
     self.jobs = jobs
     self.make_pdf()