示例#1
0
 def _admin_follow_up(self, request, foia):
     """Handle follow ups for admins"""
     form = FOIAAdminFixForm(
         request.POST,
         prefix='admin_fix',
         request=request,
         foia=foia,
     )
     if form.is_valid():
         foia.update_address(
             form.cleaned_data['via'],
             email=form.cleaned_data['email'],
             other_emails=form.cleaned_data['other_emails'],
             fax=form.cleaned_data['fax'],
         )
         snail = form.cleaned_data['via'] == 'snail'
         foia.create_out_communication(
             from_user=form.cleaned_data['from_user'],
             text=form.cleaned_data['comm'],
             user=request.user,
             snail=snail,
             subject=form.cleaned_data['subject'],
         )
         messages.success(request, 'Your follow up has been sent.')
         new_action(request.user, 'followed up on', target=foia)
         return redirect(foia.get_absolute_url() + '#')
     else:
         self.admin_fix_form = form
         raise FoiaFormError
示例#2
0
def _admin_follow_up(request, foia):
    """Handle follow ups for admins"""
    form = FOIAAdminFixForm(
        request.POST, prefix="admin_fix", request=request, foia=foia
    )
    if form.is_valid():
        foia.update_address(
            form.cleaned_data["via"],
            email=form.cleaned_data["email"],
            other_emails=form.cleaned_data["other_emails"],
            fax=form.cleaned_data["fax"],
        )
        snail = form.cleaned_data["via"] == "snail"
        foia.create_out_communication(
            from_user=form.cleaned_data["from_user"],
            text=form.cleaned_data["comm"],
            user=request.user,
            snail=snail,
            subject=form.cleaned_data["subject"],
        )
        messages.success(request, "Your follow up has been sent.")
        new_action(request.user, "followed up on", target=foia)
        return _get_redirect(request, foia)
    else:
        raise FoiaFormError("admin_fix_form", form)
示例#3
0
 def test_email_cleaning(self):
     """The email addresses should be stripped of extra white space."""
     # pylint: disable=no-self-use
     data = {
         'from_email': '*****@*****.**',
         'email': '*****@*****.**',
         'other_emails': '[email protected], [email protected] ',
         'comm': 'Test'
     }
     form = FOIAAdminFixForm(data)
     ok_(form.is_valid(), 'The form should validate. %s' % form.errors)
     eq_(form.cleaned_data['email'], '*****@*****.**',
         'Extra space should be stripped from the email address.')
     eq_(form.cleaned_data['other_emails'], '[email protected], [email protected]',
         'Extra space should be stripped from the CC address list.')
示例#4
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)
示例#5
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)
示例#6
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)
示例#7
0
文件: actions.py 项目: benlk/muckrock
def admin_fix(request, jurisdiction, jidx, slug, idx):
    """Send an email from the requests auto email address"""
    foia = _get_foia(jurisdiction, jidx, slug, idx)

    if request.method == 'POST':
        form = FOIAAdminFixForm(request.POST)
        if form.is_valid():
            if form.cleaned_data['email']:
                foia.email = form.cleaned_data['email']
            if form.cleaned_data['other_emails']:
                foia.other_emails = form.cleaned_data['other_emails']
            if form.cleaned_data['from_email']:
                from_who = form.cleaned_data['from_email']
            else:
                from_who = foia.user.get_full_name()
            save_foia_comm(
                foia,
                from_who,
                form.cleaned_data['comm'],
                request.user,
                snail=form.cleaned_data['snail_mail'],
                subject=form.cleaned_data['subject'],
            )
            messages.success(request, 'Admin Fix submitted')
            return redirect(foia)
    else:
        form = FOIAAdminFixForm(
                instance=foia,
                initial={'subject': foia.default_subject()},
                )
    context = {
        'form': form,
        'foia': foia,
        'heading': 'Email from Request Address',
        'action': 'Submit',
        'MAX_ATTACHMENT_NUM': settings.MAX_ATTACHMENT_NUM,
        'MAX_ATTACHMENT_SIZE': settings.MAX_ATTACHMENT_SIZE,
        'AWS_STORAGE_BUCKET_NAME': settings.AWS_STORAGE_BUCKET_NAME,
        'AWS_ACCESS_KEY_ID': settings.AWS_ACCESS_KEY_ID,
    }
    return render_to_response(
        'forms/foia/admin_fix.html',
        context,
        context_instance=RequestContext(request)
    )
示例#8
0
def admin_fix(request, jurisdiction, jidx, slug, idx):
    """Send an email from the requests auto email address"""
    foia = _get_foia(jurisdiction, jidx, slug, idx)

    if request.method == 'POST':
        form = FOIAAdminFixForm(request.POST)
        formset = FOIAFileFormSet(request.POST, request.FILES)
        if form.is_valid() and formset.is_valid():
            if form.cleaned_data['email']:
                foia.email = form.cleaned_data['email']
            if form.cleaned_data['other_emails']:
                foia.other_emails = form.cleaned_data['other_emails']
            if form.cleaned_data['from_email']:
                from_who = form.cleaned_data['from_email']
            else:
                from_who = foia.user.get_full_name()
            save_foia_comm(
                foia,
                from_who,
                form.cleaned_data['comm'],
                formset,
                snail=form.cleaned_data['snail_mail'],
                subject=form.cleaned_data['subject'],
            )
            messages.success(request, 'Admin Fix submitted')
            return redirect(foia)
    else:
        form = FOIAAdminFixForm(
            instance=foia,
            initial={'subject': foia.default_subject()},
        )
        formset = FOIAFileFormSet(queryset=FOIAFile.objects.none())
    context = {
        'form': form,
        'foia': foia,
        'heading': 'Email from Request Address',
        'formset': formset,
        'action': 'Submit'
    }
    return render_to_response('forms/foia/admin_fix.html',
                              context,
                              context_instance=RequestContext(request))