示例#1
0
def index(request):
    landing = HomeLandingText.objects.all()
    about = HomeAboutText.objects.all()
    staff = Staff.objects.all()
    sponsers = Sponser.objects.all()
    images = HomeImages.objects.all()

    donations = Donation.objects.all()
    ach = 0

    for donation in donations:
        ach += donation.donation

    if request.method == 'POST':

        contact_form = ContactRequestForm(request.POST)

        if contact_form.is_valid():
            ''' Begin reCAPTCHA validation '''
            recaptcha_response = request.POST.get('g-recaptcha-response')
            data = {
                'secret': settings.GOOGLE_RECAPTCHA_SECRET_KEY,
                'response': recaptcha_response
            }
            r = requests.post('https://www.google.com/recaptcha/api/siteverify', data=data)
            result = r.json()
            ''' End reCAPTCHA validation '''

            if result['success']:
                contact = contact_form.save()
                contact.save()
                try:
                    my_send_mail(request, contact.name, contact.email, contact.number, contact.message)
                except SMTPAuthenticationError as e:
                    authError(request)

            else:
                messages.error(request, 'Invalid reCAPTCHA. Please try again.')
                return redirect('/')

        return redirect('/')

    else:

        contact_form = ContactRequestForm()

    args = {
        'landing': landing,
        'about': about,
        'staff': staff,
        'sponsers':sponsers,
        'ach': ach,
        'contact_form': contact_form,
        'images': images
    }
    return render(request, 'pages/home.html', args)
示例#2
0
def get_staff(request):
    roles = StaffRole.objects.all().order_by('rank')
    staff = Staff.objects.all().order_by('rank')
    trusteeroles = TrusteeSection.objects.all().order_by('rank')
    trustees = Trustee.objects.all().order_by('rank')
    sponsers = Sponser.objects.all()

    if request.method == 'POST':

        contact_form = ContactRequestForm(request.POST)

        if contact_form.is_valid():
            ''' Begin reCAPTCHA validation '''
            recaptcha_response = request.POST.get('g-recaptcha-response')
            data = {
                'secret': settings.GOOGLE_RECAPTCHA_SECRET_KEY,
                'response': recaptcha_response
            }
            r = requests.post(
                'https://www.google.com/recaptcha/api/siteverify', data=data)
            result = r.json()
            ''' End reCAPTCHA validation '''

            if result['success']:
                contact = contact_form.save()
                contact.save()
                try:
                    my_send_mail(request, contact.name, contact.email,
                                 contact.number, contact.message)
                except SMTPAuthenticationError as e:
                    authError(request)

            else:
                messages.error(request, 'Invalid reCAPTCHA. Please try again.')
                return redirect('/staff')

        return redirect('staff')

    else:

        contact_form = ContactRequestForm()

    args = {
        'roles': roles,
        'sponsers': sponsers,
        'staff': staff,
        'trustees': trustees,
        'trustee_roles': trusteeroles,
        'contact_form': contact_form
    }

    return render(request, 'pages/staff.html', args)
示例#3
0
def get_info(request):
    sponsers = Sponser.objects.all()
    info = InformationText.objects.all()
    stickys = StickyNote.objects.all()

    if request.method == 'POST':

        contact_form = ContactRequestForm(request.POST)

        if contact_form.is_valid():
            ''' Begin reCAPTCHA validation '''
            recaptcha_response = request.POST.get('g-recaptcha-response')
            data = {
                'secret': settings.GOOGLE_RECAPTCHA_SECRET_KEY,
                'response': recaptcha_response
            }
            r = requests.post(
                'https://www.google.com/recaptcha/api/siteverify', data=data)
            result = r.json()
            ''' End reCAPTCHA validation '''

            if result['success']:
                contact = contact_form.save()
                contact.save()
                try:
                    my_send_mail(request, contact.name, contact.email,
                                 contact.number, contact.message)
                except SMTPAuthenticationError as e:
                    authError(request)

            else:
                messages.error(request, 'Invalid reCAPTCHA. Please try again.')
                return redirect('/information')

        return redirect('/information')

    else:

        contact_form = ContactRequestForm()

    args = {
        'info': info,
        'sponsers': sponsers,
        'stickys': stickys,
        'contact_form': contact_form
    }

    return render(request, 'pages/info.html', args)
示例#4
0
def get_donations(request):

    text = DonationText.objects.all()

    sponsers = Sponser.objects.all()

    donations = Donation.objects.all()
    ach = 0

    for donation in donations:
        ach += donation.donation

    if request.method == 'POST':
        contact_form = ContactRequestForm(request.POST)
        form = DonationForm(request.POST)
        if contact_form.is_valid():
            ''' Begin reCAPTCHA validation '''
            recaptcha_response = request.POST.get('g-recaptcha-response')
            data = {
                'secret': settings.GOOGLE_RECAPTCHA_SECRET_KEY,
                'response': recaptcha_response
            }
            r = requests.post(
                'https://www.google.com/recaptcha/api/siteverify', data=data)
            result = r.json()
            ''' End reCAPTCHA validation '''

            if result['success']:
                contact = contact_form.save()
                contact.save()
                try:
                    my_send_mail(request, contact.name, contact.email,
                                 contact.number, contact.message)
                except SMTPAuthenticationError as e:
                    authError(request)

            else:
                messages.error(request, 'Invalid reCAPTCHA. Please try again.')
                return redirect('/fundraising')

        if form.is_valid():
            try:
                customer = stripe.Charge.create(
                    amount=int(form.cleaned_data['donation'] * 100),
                    currency="GBP",
                    description='Share',
                    card=form.cleaned_data['stripe_id'],
                )
                if customer.paid:
                    new_form = form.save(False)
                    new_form.save()
                    messages.success(
                        request, 'Thank you, your donation of £' +
                        str(form.cleaned_data['donation']) +
                        ' is greatly appreciated!')
                else:
                    messages.error(
                        request,
                        "Sorry, we were unable to take a payment with that card!"
                    )
            except stripe.error.CardError:
                messages.error(request,
                               "Unfortunately, your card was declined!")

            return redirect('/fundraising')
    else:
        contact_form = ContactRequestForm()
        form = DonationForm()

    args = {
        'sponsers': sponsers,
        'ach': ach,
        'form': form,
        'contact_form': contact_form,
        'text': text,
        'STRIPE_PUBLISHABLE_KEY': settings.STRIPE_PUBLISHABLE_KEY
    }

    return render(request, 'pages/donations.html', args)