Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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.')
Ejemplo n.º 4
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)
        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)
    )
Ejemplo n.º 5
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))