コード例 #1
0
    def dispatch(self, request, *args, **kwargs):
        """Handle forms"""
        foia = self.get_object()
        self.admin_fix_form = FOIAAdminFixForm(prefix='admin_fix',
                                               request=self.request,
                                               foia=self.get_object(),
                                               initial={
                                                   'subject':
                                                   foia.default_subject(),
                                                   'other_emails':
                                                   foia.get_other_emails(),
                                               })
        self.resend_forms = {
            c.pk: ResendForm(communication=c)
            for c in foia.communications.all()
        }
        if request.POST:
            try:
                return self.post(request)
            except FoiaFormError:
                # if their is a form error, continue onto the GET path
                # and show the invalid form with errors displayed
                return self.get(request, *args, **kwargs)

        return super(Detail, self).dispatch(request, *args, **kwargs)
コード例 #2
0
    def dispatch(self, request, *args, **kwargs):
        """Handle forms"""
        self.foia = self.get_object()
        self.admin_fix_form = FOIAAdminFixForm(
            prefix="admin_fix",
            request=self.request,
            foia=self.get_object(),
            initial={
                "subject": self.foia.default_subject(),
                "other_emails": self.foia.cc_emails.all(),
            },
        )
        self.resend_forms = {
            c.pk: ResendForm(prefix=str(c.pk)) for c in self.foia.communications.all()
        }
        self.fee_form = RequestFeeForm(
            user=self.request.user, initial={"amount": self.foia.get_stripe_amount()}
        )
        self.agency_passcode_form = AgencyPasscodeForm(foia=self.foia)
        if request.POST:
            try:
                return self.post(request)
            except FoiaFormError as exc:
                # if their is a form error, update the form, continue onto
                # the GET path and show the invalid form with errors displayed
                if exc.form_name == "resend_form":
                    if exc.comm_id:
                        self.resend_forms[exc.comm_id] = exc.form
                else:
                    setattr(self, exc.form_name, exc.form)
                return self.get(request, *args, **kwargs)

        return super(Detail, self).dispatch(request, *args, **kwargs)
コード例 #3
0
    def dispatch(self, request, *args, **kwargs):
        """Handle forms"""
        foia = self.get_object()
        self.admin_fix_form = FOIAAdminFixForm(prefix='admin_fix',
                                               request=self.request,
                                               foia=self.get_object(),
                                               initial={
                                                   'subject':
                                                   foia.default_subject(),
                                                   'other_emails':
                                                   foia.get_other_emails(),
                                               })
        self.resend_form = ResendForm()
        self.fee_form = RequestFeeForm(
            user=self.request.user,
            initial={'amount': foia.get_stripe_amount()},
        )
        if request.POST:
            try:
                return self.post(request)
            except FoiaFormError:
                # if their is a form error, continue onto the GET path
                # and show the invalid form with errors displayed
                return self.get(request, *args, **kwargs)

        return super(Detail, self).dispatch(request, *args, **kwargs)
コード例 #4
0
ファイル: detail_actions.py プロジェクト: WPMedia/muckrock
def resend_comm(request, foia):
    """Resend a communication"""
    if request.user.is_staff:
        form = ResendForm(request.POST, prefix=request.POST.get("communication", ""))
        if form.is_valid():
            foia.update_address(
                form.cleaned_data["via"],
                email=form.cleaned_data["email"],
                fax=form.cleaned_data["fax"],
            )
            snail = form.cleaned_data["via"] == "snail"
            foia.submit(snail=snail, comm=form.cleaned_data["communication"])
            messages.success(request, "The communication was resent")
        else:
            comm = form.cleaned_data.get("communication")
            raise FoiaFormError("resend_form", form, comm_id=comm.id if comm else None)
    return _get_redirect(request, foia)
コード例 #5
0
 def _resend_comm(self, request, foia):
     """Resend a communication"""
     if request.user.is_staff:
         form = ResendForm(request.POST)
         if form.is_valid():
             foia.update_address(
                 form.cleaned_data['via'],
                 email=form.cleaned_data['email'],
                 fax=form.cleaned_data['fax'],
             )
             snail = form.cleaned_data['via'] == 'snail'
             foia.submit(
                 snail=snail,
                 comm=form.cleaned_data['communication'],
             )
             messages.success(request, 'The communication was resent')
         else:
             comm = form.cleaned_data['communication']
             if comm:
                 self.resend_forms[comm.pk] = form
             raise FoiaFormError
     return redirect(foia.get_absolute_url() + '#')