Ejemplo n.º 1
0
def donate_direct(request):
    make_donation = None
    teacher_donation = None
    c = Context(dict(
        page_title='Donator',
        donate=True,
        reply_to=settings.EMAIL_HOST_USER,
    ))
    if request.POST:
        make_donation = request.POST.get('make_donation')
        teacher_donation = request.POST.get('teacher_donation')
        form = DonationForm(request.POST)
        if form.is_valid():
            teacher = Teacher.objects.get(pk=request.POST.get('student_teacher_id'))
            first_name = request.POST.get('student_first_name').strip()
            last_name = request.POST.get('student_last_name').strip()
            per_lap = request.POST.get('per_lap')
            identifier = '{0}-{1}-{2}'.format(replace_space(first_name), replace_space(last_name), teacher.room_number)
            try:
                student = Student.objects.get(identifier=identifier)
            except Exception, e:
                student = Student(
                    first_name=first_name,
                    last_name=last_name,
                    date_added=date.datetime.now(pytz.utc),
                    identifier=identifier,
                    teacher=teacher,
                )
                student.save()
            try:
                donation = Donation.objects.create(
                    first_name=request.POST.get('first_name'),
                    last_name=request.POST.get('last_name'),
                    email_address=request.POST.get('email_address'),
                    phone_number=request.POST.get('phone_number'),
                    per_lap=per_lap and int(per_lap) or 0,
                    donation=request.POST.get('donation'),
                    date_added=date.datetime.now(pytz.utc),
                    student=student,
                )
                messages.success(request, 'Thank you for making a pledge to {0}'.format(teacher_donation and donation.first_name or student.full_name()))
                # add to cart
                add_to_cart(request, 'donation', donation.id, 1)
                # update totals
                donation.calculate_totals(donation.id)
#                 calculate_totals_signal.send(sender=None, donation=donation)
                c['success'] = True
                c['donate_url'] = student.donate_url()
                c['student_full_name'] = student.full_name()
                c['student_identifier'] = student.identifier
                c['amount'] = donation.donation
                c['full_name'] = donation.full_name()
                c['is_per_lap'] = donation.per_lap
                c['payment_url'] = donation.payment_url()
                c['email_address'] = donation.email_address
                c['subject'] = 'Hicks Canyon Jog-A-Thon: Thank you for making a Pledge'
                c['domain'] = Site.objects.get_current().domain
                if not teacher_donation:
                    _send_email_teamplate('donate', c)
            except Exception, e:
                messages.error(request, str(e))
Ejemplo n.º 2
0
def donate_direct(request):
    make_donation = None
    teacher_donation = None
    c = Context(dict(page_title="Donator", donate=True, reply_to=settings.EMAIL_HOST_USER))
    if request.POST:
        make_donation = request.POST.get("make_donation")
        teacher_donation = request.POST.get("teacher_donation")
        form = DonationForm(request.POST)
        if form.is_valid():
            teacher = Teacher.objects.get(pk=request.POST.get("student_teacher_id"))
            first_name = request.POST.get("student_first_name").strip()
            last_name = request.POST.get("student_last_name").strip()
            per_lap = request.POST.get("per_lap")
            identifier = "{0}-{1}-{2}".format(replace_space(first_name), replace_space(last_name), teacher.room_number)
            try:
                student = Student.objects.get(identifier=identifier)
            except Exception, e:
                student = Student(
                    first_name=first_name,
                    last_name=last_name,
                    date_added=date.datetime.now(pytz.utc),
                    identifier=identifier,
                    teacher=teacher,
                )
                student.save()
            try:
                donation = Donation.objects.create(
                    first_name=request.POST.get("first_name"),
                    last_name=request.POST.get("last_name"),
                    email_address=request.POST.get("email_address"),
                    phone_number=request.POST.get("phone_number"),
                    per_lap=per_lap and int(per_lap) or 0,
                    donation=request.POST.get("donation"),
                    date_added=date.datetime.now(pytz.utc),
                    student=student,
                )
                messages.success(
                    request,
                    "Thank you for making a pledge to {0}".format(
                        teacher_donation and donation.first_name or student.full_name()
                    ),
                )
                # add to cart
                add_to_cart(request, "donation", donation.id, 1)
                # update totals
                donation.calculate_totals(donation.id)
                #                 calculate_totals_signal.send(sender=None, donation=donation)
                c["success"] = True
                c["donate_url"] = student.donate_url()
                c["student_full_name"] = student.full_name()
                c["student_identifier"] = student.identifier
                c["amount"] = donation.donation
                c["full_name"] = donation.full_name()
                c["is_per_lap"] = donation.per_lap
                c["payment_url"] = donation.payment_url()
                c["email_address"] = donation.email_address
                c["subject"] = "Hicks Canyon Jog-A-Thon: Thank you for making a Pledge"
                c["domain"] = Site.objects.get_current().domain
                if not teacher_donation:
                    _send_email_teamplate("donate", c)
            except Exception, e:
                messages.error(request, str(e))