Example #1
0
    def get(self, request, notice_of_application_to_vary_order_id=None):

        uid = request.user.id

        pdf_type = request.query_params.get("pdf_type")
        if pdf_type is None:
            return HttpResponseBadRequest("Missing pdf_type parameters.")

        notice_of_application_to_vary_order_ids = request.query_params.getlist(
            "id")

        if not notice_of_application_to_vary_order_ids:
            notice_of_application_to_vary_order = self.get_notice_of_application_to_vary_order_for_user(
                notice_of_application_to_vary_order_id, uid)
            if not notice_of_application_to_vary_order:
                return HttpResponseNotFound(no_record_found)

            prepared_pdf = self.get_pdf_by_notice_of_application_to_vary_order_id_and_type(
                notice_of_application_to_vary_order_id, pdf_type)
            if prepared_pdf is None:
                return HttpResponseNotFound(no_record_found)

            pdf_content = settings.ENCRYPTOR.decrypt(prepared_pdf.key_id,
                                                     prepared_pdf.data)
            return create_download_response(pdf_content)
        else:
            pdf_contents = list()
            for notice_of_application_to_vary_orderId in notice_of_application_to_vary_order_ids:
                notice_of_application_to_vary_order = self.get_notice_of_application_to_vary_order_for_user(
                    notice_of_application_to_vary_orderId, uid)
                if not notice_of_application_to_vary_order:
                    continue

                prepared_pdf = self.get_pdf_by_notice_of_application_to_vary_order_id_and_type(
                    notice_of_application_to_vary_orderId, pdf_type)
                if prepared_pdf is None:
                    continue

                pdf_contents.append({
                    "id":
                    notice_of_application_to_vary_orderId,
                    "type":
                    pdf_type,
                    "pdf":
                    settings.ENCRYPTOR.decrypt(prepared_pdf.key_id,
                                               prepared_pdf.data)
                })
            if not pdf_contents:
                return HttpResponseNotFound(no_record_found)
            return create_zip_download_response(pdf_contents)
    def get(self, request, objection_withdraw_id=None):

        uid = request.user.id

        pdf_type = request.query_params.get("pdf_type")
        if pdf_type is None:
            return HttpResponseBadRequest("Missing pdf_type parameters.")

        objection_withdraw_ids = request.query_params.getlist("id")

        if not objection_withdraw_ids:
            objection_withdraw = self.get_objection_withdraw_for_user(
                objection_withdraw_id, uid)
            if not objection_withdraw:
                return HttpResponseNotFound(no_record_found)

            prepared_pdf = self.get_pdf_by_objection_withdraw_id_and_type(
                objection_withdraw_id, pdf_type)
            if prepared_pdf is None:
                return HttpResponseNotFound(no_record_found)

            pdf_content = settings.ENCRYPTOR.decrypt(prepared_pdf.key_id,
                                                     prepared_pdf.data)
            return create_download_response(pdf_content)
        else:
            pdf_contents = list()
            for objection_withdrawId in objection_withdraw_ids:
                objection_withdraw = self.get_objection_withdraw_for_user(
                    objection_withdrawId, uid)
                if not objection_withdraw:
                    continue

                prepared_pdf = self.get_pdf_by_objection_withdraw_id_and_type(
                    objection_withdrawId, pdf_type)
                if prepared_pdf is None:
                    continue

                pdf_contents.append({
                    "id":
                    objection_withdrawId,
                    "type":
                    pdf_type,
                    "pdf":
                    settings.ENCRYPTOR.decrypt(prepared_pdf.key_id,
                                               prepared_pdf.data)
                })
            if not pdf_contents:
                return HttpResponseNotFound(no_record_found)
            return create_zip_download_response(pdf_contents)
    def get(self, request, change_of_address_id = None):

        uid = request.user.id

        pdf_type = request.query_params.get("pdf_type")
        if pdf_type is None:
            return HttpResponseBadRequest("Missing pdf_type parameters.")

        change_of_address_ids = request.query_params.getlist("id")                            

        if not change_of_address_ids:        
            change_of_address = self.get_change_of_address_for_user(change_of_address_id, uid)
            if not change_of_address:
                return HttpResponseNotFound(no_record_found)

            prepared_pdf = self.get_pdf_by_change_of_address_id_and_type(change_of_address_id, pdf_type)
            if prepared_pdf is None:
                return HttpResponseNotFound(no_record_found)
                
            pdf_content = settings.ENCRYPTOR.decrypt(prepared_pdf.key_id, prepared_pdf.data)
            return create_download_response(pdf_content)
        else :
            pdf_contents = list()
            for change_of_addressId in change_of_address_ids:
                change_of_address = self.get_change_of_address_for_user(change_of_addressId, uid)
                if not change_of_address:
                    continue

                prepared_pdf = self.get_pdf_by_change_of_address_id_and_type(change_of_addressId, pdf_type)
                if prepared_pdf is None:
                    continue

                pdf_contents.append({"id":change_of_addressId, "type":pdf_type, "pdf": settings.ENCRYPTOR.decrypt(prepared_pdf.key_id, prepared_pdf.data)})
            if not pdf_contents:
                return HttpResponseNotFound(no_record_found)
            return create_zip_download_response(pdf_contents)