コード例 #1
0
    def init(self, request, **kwargs):
        self.back_url = reverse_lazy("cases:case",
                                     kwargs={
                                         "queue_pk": kwargs["queue_pk"],
                                         "pk": kwargs["pk"],
                                         "tab": "documents"
                                     })
        self.contacts = get_case_additional_contacts(request, kwargs["pk"])
        self.applicant = get_case_applicant(request, kwargs["pk"])
        self.template = request.POST.get(TEMPLATE)

        params = {
            "case": self.kwargs["pk"],
            "page": self.request.GET.get("page", 1)
        }
        if self.kwargs.get("decision_key"):
            params["decision"] = self.kwargs["decision_key"]
        self.templates, _ = get_letter_templates(
            self.request, convert_dict_to_query_params(params))
        self.data = {"total_pages": self.templates["total_pages"]}

        if self.template and not request.POST.get(TEXT):
            template, _ = get_letter_template(
                request,
                self.template,
                params=convert_dict_to_query_params({TEXT: True}))
            self.data[TEXT] = template[TEXT]

        self.object_pk = kwargs["pk"]
        self.action = self._validate
        self.additional_context = {
            "case": get_case(request, self.object_pk),
            "applicant": self.applicant,
            "contacts": self.contacts,
        }
コード例 #2
0
    def get(self, request, **kwargs):
        letter_template = get_letter_template(request,
                                              str(kwargs["pk"]))[0]["template"]
        letter_template_case_types = letter_template.pop("case_types") or []
        letter_template_decisions = letter_template.pop("decisions") or []

        letter_template_case_types = [
            case_type["reference"]["key"]
            for case_type in letter_template_case_types
        ]
        letter_template.update(case_types=letter_template_case_types)

        letter_template_decisions = [
            decision["name"]["key"] for decision in letter_template_decisions
        ]
        letter_template.update(decisions=letter_template_decisions)

        case_type_options = [
            Option(option["key"], option["value"])
            for option in get_case_types(request)
        ]
        decision_options = [
            Option(decision["key"], decision["value"])
            for decision in get_decisions(request)[0]
        ]

        return form_page(
            request,
            edit_letter_template(request, letter_template, case_type_options,
                                 decision_options),
            data=letter_template,
        )
コード例 #3
0
    def get(self, request, **kwargs):
        letter_template = get_letter_template(request,
                                              str(kwargs["pk"]))[0]["template"]
        letter_paragraphs = get_letter_paragraphs(
            request, letter_template["letter_paragraphs"])
        letter_paragraphs = self.sort_letter_paragraphs(
            letter_paragraphs, letter_template["letter_paragraphs"])

        context = {
            "letter_template": letter_template,
            "letter_paragraphs": letter_paragraphs
        }
        return render(request, "letter-templates/edit-letter-paragraphs.html",
                      context)
コード例 #4
0
 def get(self, request, **kwargs):
     letter_template_id = str(kwargs["pk"])
     params = convert_dict_to_query_params({
         "generate_preview": True,
         "activity": True
     })
     response, _ = get_letter_template(request,
                                       letter_template_id,
                                       params=params)
     context = {
         "letter_template": response["template"],
         "preview": response["preview"],
         "activity": response.get("activity", []),
     }
     return render(request, "letter-templates/letter-template.html",
                   context)
コード例 #5
0
    def post(request, **kwargs):
        letter_template_id = str(kwargs["pk"])
        letter_template = get_letter_template(
            request, letter_template_id)[0]["template"]

        # Override case restrictions to use getlist
        edited_letter_template_data = request.POST.copy()
        edited_letter_template_data[
            "case_types"] = edited_letter_template_data.getlist("case_types[]")
        edited_letter_template_data[
            "decisions"] = edited_letter_template_data.getlist("decisions[]")

        case_type_options = [
            Option(option["key"], option["value"])
            for option in get_case_types(request)
        ]
        decision_options = [
            Option(decision["key"], decision["value"])
            for decision in get_decisions(request)[0]
        ]

        next_form, _ = submit_single_form(
            request,
            edit_letter_template(request, letter_template, case_type_options,
                                 decision_options),
            put_letter_template,
            object_pk=letter_template_id,
            override_data=edited_letter_template_data,
        )

        if next_form:
            return next_form

        return redirect(
            reverse("letter_templates:letter_template",
                    kwargs={"pk": letter_template_id}))