Exemplo n.º 1
0
 def test_contact_form(self):
     """
     Cruedely test that we're requiring a message in our
     contact form.
     """
     form_data = {'email': '*****@*****.**', 'message': 'some message'}
     form = ContactForm(data=form_data)
     self.assertEqual(form.is_valid(), True)
Exemplo n.º 2
0
 def test_contact_form(self):
     """
     Crudely test that we're requiring a message in our
     contact form.
     """
     form_data = {'email': '*****@*****.**', 'message': 'some message'}
     form = ContactForm(data=form_data)
     self.assertEqual(form.is_valid(), True)
Exemplo n.º 3
0
def contact(request):
    """
    Our contact form page
    """

    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            # If our form is valid, let's generate and email to our contact folks

            from_address = form.cleaned_data['email']

            content = '''
This is a message from the Perma.cc contact form, http://perma.cc/contact



Message from user
--------
%s
''' % (form.cleaned_data['message'])

            send_contact_email(
                "New message from Perma contact form",
                content,
                from_address,
                request
            )

            # redirect to a new URL:
            return HttpResponseRedirect(reverse('contact_thanks'))
        else:
            context = RequestContext(request, {'form': form})
            return render_to_response('contact.html', context)

    else:

        # Our contact form serves a couple of purposes
        # If we get a message parameter, we're getting a message from the create form
        # about a failed archive
        #
        # If we get a flagged parameter, we're getting the guid of an archive from the
        # Flag as inappropriate button on an archive page
        #
        # We likely want to clean up this contact for logic if we tack much else on
        
        message = request.GET.get('message', '')
        flagged_archive_guid = request.GET.get('flag', '')

        if flagged_archive_guid:
            message = 'http://perma.cc/%s contains material that is inappropriate.' % flagged_archive_guid


        form = ContactForm(initial={'message': message})

        context = RequestContext(request, {'form': form})
        return render_to_response('contact.html', context)
Exemplo n.º 4
0
def contact(request):
    """
    Our contact form page
    """

    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            # If our form is valid, let's generate and email to our contact folks

            from_address = form.cleaned_data['email']

            content = '''
This is a message from the Perma.cc contact form, http://perma.cc/contact



Message from user
--------
%s
''' % (form.cleaned_data['message'])

            send_admin_email("New message from Perma contact form", content,
                             from_address, request)

            # redirect to a new URL:
            return HttpResponseRedirect(reverse('contact_thanks'))
        else:
            context = RequestContext(request, {'form': form})
            return render_to_response('contact.html', context)

    else:

        # Our contact form serves a couple of purposes
        # If we get a message parameter, we're getting a message from the create form
        # about a failed archive
        #
        # If we get a flagged parameter, we're getting the guid of an archive from the
        # Flag as inappropriate button on an archive page
        #
        # We likely want to clean up this contact for logic if we tack much else on

        message = request.GET.get('message', '')
        flagged_archive_guid = request.GET.get('flag', '')

        if flagged_archive_guid:
            message = 'http://perma.cc/%s contains material that is inappropriate.' % flagged_archive_guid

        form = ContactForm(initial={'message': message})

        context = RequestContext(request, {'form': form})
        return render_to_response('contact.html', context)
Exemplo n.º 5
0
def contact(request):
    """
    Our contact form page
    """

    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            # If our form is valid, let's generate and email to our contact folks

            user_agent = 'Unknown'
            if 'HTTP_USER_AGENT' in request.META:
                user_agent = request.META.get('HTTP_USER_AGENT')

            from_address = form.cleaned_data['email']

            content = '''
            This is a message from the Perma.cc contact form, http://perma.cc/contact



            Message from user
            --------
            %s


            User email: %s
            User agent: %s

            ''' % (form.cleaned_data['message'], from_address, user_agent)

            send_mail(
                "New message from Perma contact form",
                content,
                from_address,
                [settings.DEFAULT_FROM_EMAIL], fail_silently=False
            )

            # redirect to a new URL:
            return HttpResponseRedirect(reverse('contact_thanks'))
        else:
            context = RequestContext(request, {'form': form})
            return render_to_response('contact.html', context)

    else:
        form = ContactForm()

        context = RequestContext(request, {'form': form})
        return render_to_response('contact.html', context)
Exemplo n.º 6
0
def contact(request):
    """
    Our contact form page
    """

    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            # If our form is valid, let's generate and email to our contact folks

            user_agent = 'Unknown'
            if 'HTTP_USER_AGENT' in request.META:
                user_agent = request.META.get('HTTP_USER_AGENT')

            from_address = form.cleaned_data['email']

            content = '''
            This is a message from the Perma.cc contact form, http://perma.cc/contact



            Message from user
            --------
            %s


            User email: %s
            User agent: %s

            ''' % (form.cleaned_data['message'], from_address, user_agent)

            send_mail(
                "New message from Perma contact form",
                content,
                from_address,
                [settings.DEFAULT_FROM_EMAIL], fail_silently=False
            )

            # redirect to a new URL:
            return HttpResponseRedirect(reverse('contact_thanks'))
        else:
            context = RequestContext(request, {'form': form})
            return render_to_response('contact.html', context)

    else:
        form = ContactForm(initial={'message': request.GET.get('message', '')})

        context = RequestContext(request, {'form': form})
        return render_to_response('contact.html', context)
Exemplo n.º 7
0
def contact(request):
    """
    Our contact form page
    """

    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            # If our form is valid, let's generate and email to our contact folks

            from_address = form.cleaned_data['email']

            content = '''
This is a message from the Perma.cc contact form, http://perma.cc/contact



Message from user
--------
%s
''' % (form.cleaned_data['message'])

            send_contact_email(
                "New message from Perma contact form",
                content,
                from_address,
                request
            )

            # redirect to a new URL:
            return HttpResponseRedirect(reverse('contact_thanks'))
        else:
            context = RequestContext(request, {'form': form})
            return render_to_response('contact.html', context)

    else:
        form = ContactForm(initial={'message': request.GET.get('message', '')})

        context = RequestContext(request, {'form': form})
        return render_to_response('contact.html', context)