Exemplo n.º 1
0
def course_has_been_purchased(sender, **kwargs):
    ipn_obj = sender
    ppnvp = PayPalNVP.objects.get(method='DoExpressCheckoutPayment',ack='Success',token=ipn_obj['token'])

    # Generate Order
    order = Order(user_id=ppnvp.user_id,course_id=ipn_obj['course_id'],created_at=datetime.now(),amount=ipn_obj['amt'],is_refund = False, paypal_txn_id = ipn_obj['token'])
    order.save()
    #Enrroll in the course
    enrollment = Enrollment(user_id=ppnvp.user_id,course_id=ipn_obj['course_id'], start_date = datetime.now())
    enrollment.save()

    #Send Email to Teacher
    course = Course.objects.get(pk=ipn_obj['course_id'])
    teacher = User.objects.get(pk = course.user_id)
    student = User.objects.get(pk = ppnvp.user_id)

    ctx_dict = {'course': course,'teacher': teacher, 'student': student}

    message = render_to_string('shop/buy_email.html',ctx_dict)
    subject = _('Someone has purchased your course: ')+course.title
    msg = EmailMessage(subject, message, settings.DEFAULT_FROM_EMAIL, [teacher.email])
    msg.content_subtype = "html"  # Main content is now text/html
    msg.send()

    #Send Email to the New Student
    message = render_to_string('shop/enrroled_email.html',ctx_dict)
    subject = _('You has been enrrolled in ')+course.title
    msg = EmailMessage(subject, message, settings.DEFAULT_FROM_EMAIL, [student.email])
    msg.content_subtype = "html"  # Main content is now text/html
    msg.send()
Exemplo n.º 2
0
def enrroll_tester(request,course_id):
    max_testers_number = 5
    course = get_object_or_404(Course,pk=course_id,status__name="evaluation period")
    if not request.user.get_profile().is_completed():
        messages.error(request,_('You have to fill at least: Firstname, Lastname, Professional Profile, Description, Country and State'))
    else:
        valid_enrollements = Enrollment.objects.filter(active=True,course_id = course_id).count()
        if valid_enrollements < max_testers_number:
            enrollment = Enrollment(active=True,user_id=request.user.id, course_id=course_id, start_date=datetime.now(), tester=True)
            enrollment.save()
            #Temporary Disable Auto Published Courses when 5 testers
    #        if testers_number == 4:
    #            course.status = Status.objects.get(name='published')
    #            course.save()
    #        messages.success(request,_('Now you are Tester of the Course ')+course.title)
        else:
            messages.error(request,_('You can\'t be tester on that Course. Theare are 5/5 Testers'))
    return redirect(reverse('elearning.views.view_course', args=(course.slug,)))