示例#1
0
 def test_saving_participant_with_same_email_and_feedback_email(self):
     email = Email.objects.create(address='*****@*****.**')
     participant = Participant()
     participant.first_name = 'Jake'
     participant.last_name = 'Howard'
     participant.email = email
     participant.feedback_email = email
     participant.full_clean()
     participant.save()
示例#2
0
 def test_saving_without_name_fails(self):
     email = Email.objects.create(address='*****@*****.**')
     feedback_email = Email.objects.create(address='*****@*****.**')
     participant = Participant()
     participant.first_name = ''
     participant.last_name = ''
     participant.email = email
     participant.feedback_email = feedback_email
     with self.assertRaises(ValidationError):
         participant.full_clean()
         participant.save()
示例#3
0
    def test_saving_participant_without_email_fails(self):
        participant = Participant()
        participant.first_name = 'Jake'
        participant.last_name = 'Howard'

        with self.assertRaises(ValidationError):
            participant.full_clean()
            participant.save()
示例#4
0
    def test_saving_and_retrieving_participant(self):
        email = Email.objects.create(address='*****@*****.**')
        feedback_email = Email.objects.create(address='*****@*****.**')
        participant = Participant()
        participant.first_name = 'Jake'
        participant.last_name = 'Howard'
        participant.email = email
        participant.feedback_email = feedback_email
        participant.full_clean()
        participant.save()

        participant = Participant.objects.first()
        self.assertEqual(participant.first_name, 'Jake')
        self.assertEqual(participant.last_name, 'Howard')
        self.assertEqual(participant.email, email)
        self.assertEqual(participant.feedback_email, feedback_email)
示例#5
0
def opt_in(request):
    # Get the data
    first_name = request.POST.get('first-name', '')
    last_name = request.POST.get('last-name', '')
    main_email_string = request.POST.get('email', '')
    feedback_email_string = request.POST.get('feedback-email', '')

    # Check the main email is one of our trusted domains
    if main_email_string and not is_allowed_email(main_email_string):
        error_message = "Please use a recognised email address as your main email."
        return render(request, 'opt_in_page.html', {'error_message':error_message})


    # Create and validate the emails to attribute to the participant
    error_message = "The email address you supplied is not a valid email address."
    main_email = create_email_or_None(main_email_string)
    if not main_email:
        return render(request, 'opt_in_page.html', {'error_message':error_message})

    if not feedback_email_string:
        feedback_email = main_email
    else:
        feedback_email = create_email_or_None(feedback_email_string)
        if not feedback_email:
            return render(request, 'opt_in_page.html', {'error_message':error_message})

    # Make the participant
    participant = Participant()
    participant.first_name = first_name
    participant.last_name = last_name
    participant.email = main_email
    participant.feedback_email = feedback_email
    try:
        participant.full_clean()
        participant.save()
    except ValidationError:
        error_message = "You have to provide: First Name, Last Name, Email."
        return render(request, 'opt_in_page.html', {'error_message':error_message})

    try:
        send_validation_email(participant.email.address)
    except:
        participant.delete()
        error_message = 'Something has gone wrong on our end...you could try again to see if it works next time.'
        return render(request, 'opt_in_page.html', {'error_message':error_message})

    return redirect('/')