コード例 #1
0
    def _draw_audit_trail(self, story):
        s = self.styles["line_data_small"]
        t = Table(
            [[
                Paragraph("Document", s),
                Paragraph("Changed by", s),
                Paragraph("Date", s),
                Paragraph("Action", s),
            ]],
            (3 * cm, 3 * cm, 3 * cm, 9 * cm),
        )
        self.set_table_style(t,
                             bg_cmd=("BACKGROUND", (0, 0), (3, -1),
                                     colors.lightgrey))
        story.append(t)

        qs = (get_ae_model("deathreport").history.filter(
            id=self.death_report.id).order_by("-history_date"))
        for obj in qs:
            username = obj.user_created if obj.history_type == "+" else obj.user_modified
            t = Table(
                [[
                    Paragraph(
                        get_ae_model("deathreport")._meta.verbose_name, s),
                    Paragraph(username, s),
                    Paragraph(obj.modified.strftime("%Y-%m-%d %H:%M"), s),
                    Paragraph(fill(self.history_change_message(obj), width=60),
                              s),
                ]],
                (3 * cm, 3 * cm, 3 * cm, 9 * cm),
            )
            self.set_table_style(t)
            story.append(t)
コード例 #2
0
    def _draw_audit_trail(self, story):
        s = self.styles["line_data_small"]
        t = Table(
            [[
                Paragraph("Document", s),
                Paragraph("Changed by", s),
                Paragraph("Date", s),
                Paragraph("Action", s),
            ]],
            (3 * cm, 3 * cm, 3 * cm, 9 * cm),
        )
        self.set_table_style(t,
                             bg_cmd=("BACKGROUND", (0, 0), (3, -1),
                                     colors.lightgrey))
        story.append(t)

        followups = self.ae_initial.ae_follow_ups.order_by("-created")
        index = followups.count()
        for followup in followups:
            qs = followup.history.filter(
                id=followup.id).order_by("-history_date")
            for obj in qs:
                username = obj.user_created if obj.history_type == "+" else obj.user_modified
                t = Table(
                    [[
                        Paragraph(
                            f"{get_ae_model('aefollowup')._meta.verbose_name}: {index}",
                            s,
                        ),
                        Paragraph(username, s),
                        Paragraph(obj.modified.strftime("%Y-%m-%d %H:%M"), s),
                        Paragraph(
                            fill(self.history_change_message(obj), width=60),
                            s),
                    ]],
                    (3 * cm, 3 * cm, 3 * cm, 9 * cm),
                )
                self.set_table_style(t)
                story.append(t)
            index -= 1
        qs = (get_ae_model("aeinitial").history.filter(
            id=self.ae_initial.id).order_by("-history_date"))
        for obj in qs:
            username = obj.user_created if obj.history_type == "+" else obj.user_modified
            t = Table(
                [[
                    Paragraph(get_ae_model("aeinitial")._meta.verbose_name, s),
                    Paragraph(username, s),
                    Paragraph(obj.modified.strftime("%Y-%m-%d %H:%M"), s),
                    Paragraph(fill(self.history_change_message(obj), width=60),
                              s),
                ]],
                (3 * cm, 3 * cm, 3 * cm, 9 * cm),
            )
            self.set_table_style(t)
            story.append(t)
コード例 #3
0
 def changelist_url(self):
     AeFollowup = get_ae_model("aefollowup")
     app_label = AeFollowup._meta.app_label
     model_name = AeFollowup._meta.object_name.lower()
     return reverse(
         f"{settings.ADVERSE_EVENT_ADMIN_SITE}:{app_label}_{model_name}_changelist"
     )
コード例 #4
0
 def death_report(self):
     """Returns a model instance or None"""
     try:
         return get_ae_model("deathreport").objects.get(
             subject_identifier=self.subject_identifier)
     except ObjectDoesNotExist:
         return None
コード例 #5
0
 def raise_if_followup_exists(self):
     """Raise an exception if the AE followup exists
     and the user is attempting to change this form.
     """
     AeFollowup = get_ae_model("aefollowup")
     if AeFollowup.objects.filter(ae_initial=self.instance.pk).exists():
         url = f"{self.changelist_url}?q={self.instance.action_identifier}"
         raise forms.ValidationError(
             mark_safe(
                 f"Unable to save. Follow-up reports exist. Provide updates "
                 f"to this report using the "
                 f"{AeFollowup._meta.verbose_name} instead. "
                 f'See <A href="{url}">AE Follow-ups for {self.instance}</A>.'
             ))
コード例 #6
0
 def print_pdf_report(self, action_identifier=None, request=None):
     try:
         ae_initial = get_ae_model("aeinitial").objects.get(
             action_identifier=action_identifier)
     except ObjectDoesNotExist:
         pass
     else:
         report = self.pdf_report_cls(
             ae_initial=ae_initial,
             subject_identifier=ae_initial.subject_identifier,
             user=self.request.user,
             request=request,
         )
         return report.render()
     return None
コード例 #7
0
    def if_sae_reason(self, obj):
        """Returns the SAE reason.

        If DEATH, adds link to the death report.
        """
        if obj.sae_reason.name == DEAD:
            DeathReport = get_ae_model("deathreport")
            try:
                death_report = DeathReport.objects.get(
                    subject_identifier=obj.subject_identifier
                )
            except ObjectDoesNotExist:
                link = '<font color="red">Death report pending</font>'
            else:
                url_name = f"{settings.ADVERSE_EVENT_APP_LABEL}_deathreport"
                namespace = self.admin_site.name
                url = reverse(f"{namespace}:{url_name}_changelist")
                link = (
                    f'See report <a title="go to Death report"'
                    f'href="{url}?q={death_report.subject_identifier}">'
                    f"<span nowrap>{death_report.identifier}</span></a>"
                )
            return mark_safe(f"{obj.sae_reason.name}.<BR>{link}.")
        return obj.get_sae_reason_display()