Пример #1
0
def course_page(pctx):
    from course.content import get_processed_page_chunks, get_course_desc
    page_desc = get_course_desc(pctx.repo, pctx.course, pctx.course_commit_sha)

    chunks = get_processed_page_chunks(
            pctx.course, pctx.repo, pctx.course_commit_sha, page_desc,
            pctx.role, get_now_or_fake_time(pctx.request),
            facilities=pctx.request.relate_facilities)

    show_enroll_button = (
            pctx.course.accepts_enrollment
            and pctx.role == participation_role.unenrolled)

    if pctx.request.user.is_authenticated() and Participation.objects.filter(
            user=pctx.request.user,
            course=pctx.course,
            status=participation_status.requested).count():
        show_enroll_button = False

        messages.add_message(pctx.request, messages.INFO,
                _("Your enrollment request is pending. You will be "
                "notified once it has been acted upon."))

    return render_course_page(pctx, "course/course-page.html", {
        "chunks": chunks,
        "show_enroll_button": show_enroll_button,
        })
Пример #2
0
def course_page(pctx):
    # type: (CoursePageContext) -> http.HttpResponse
    from course.content import get_processed_page_chunks, get_course_desc
    page_desc = get_course_desc(pctx.repo, pctx.course, pctx.course_commit_sha)

    chunks = get_processed_page_chunks(
        pctx.course,
        pctx.repo,
        pctx.course_commit_sha,
        page_desc,
        pctx.role_identifiers(),
        get_now_or_fake_time(pctx.request),
        facilities=pctx.request.relate_facilities)

    show_enroll_button = (pctx.course.accepts_enrollment
                          and pctx.participation is None)

    if pctx.request.user.is_authenticated and Participation.objects.filter(
            user=pctx.request.user,
            course=pctx.course,
            status=participation_status.requested).count():
        show_enroll_button = False

        messages.add_message(
            pctx.request, messages.INFO,
            _("Your enrollment request is pending. You will be "
              "notified once it has been acted upon."))

        from course.models import ParticipationPreapproval

        if ParticipationPreapproval.objects.filter(course=pctx.course).exclude(
                institutional_id=None).count():
            if not pctx.request.user.institutional_id:
                from django.urls import reverse
                messages.add_message(
                    pctx.request, messages.WARNING,
                    _("This course uses institutional ID for "
                      "enrollment preapproval, please <a href='%s' "
                      "role='button' class='btn btn-md btn-primary'>"
                      "fill in your institutional ID &nbsp;&raquo;"
                      "</a> in your profile.") %
                    (reverse("relate-user_profile") + "?referer=" +
                     pctx.request.path + "&set_inst_id=1"))
            else:
                if pctx.course.preapproval_require_verified_inst_id:
                    messages.add_message(
                        pctx.request, messages.WARNING,
                        _("Your institutional ID is not verified or "
                          "preapproved. Please contact your course "
                          "staff."))

    return render_course_page(pctx, "course/course-page.html", {
        "chunks": chunks,
        "show_enroll_button": show_enroll_button,
    })
Пример #3
0
def course_page(pctx):
    # type: (CoursePageContext) -> http.HttpResponse
    from course.content import get_processed_page_chunks, get_course_desc
    page_desc = get_course_desc(pctx.repo, pctx.course, pctx.course_commit_sha)

    chunks = get_processed_page_chunks(
            pctx.course, pctx.repo, pctx.course_commit_sha, page_desc,
            pctx.role_identifiers(), get_now_or_fake_time(pctx.request),
            facilities=pctx.request.relate_facilities)

    show_enroll_button = (
            pctx.course.accepts_enrollment
            and pctx.participation is None)

    if pctx.request.user.is_authenticated and Participation.objects.filter(
            user=pctx.request.user,
            course=pctx.course,
            status=participation_status.requested).count():
        show_enroll_button = False

        messages.add_message(pctx.request, messages.INFO,
                _("Your enrollment request is pending. You will be "
                "notified once it has been acted upon."))

        from course.models import ParticipationPreapproval

        if ParticipationPreapproval.objects.filter(
                course=pctx.course).exclude(institutional_id=None).count():
            if not pctx.request.user.institutional_id:
                from django.urls import reverse
                messages.add_message(pctx.request, messages.WARNING,
                        _("This course uses institutional ID for "
                        "enrollment preapproval, please <a href='%s' "
                        "role='button' class='btn btn-md btn-primary'>"
                        "fill in your institutional ID &nbsp;&raquo;"
                        "</a> in your profile.")
                        % (
                            reverse("relate-user_profile")
                            + "?referer="
                            + pctx.request.path
                            + "&set_inst_id=1"
                            )
                        )
            else:
                if pctx.course.preapproval_require_verified_inst_id:
                    messages.add_message(pctx.request, messages.WARNING,
                            _("Your institutional ID is not verified or "
                            "preapproved. Please contact your course "
                            "staff.")
                            )

    return render_course_page(pctx, "course/course-page.html", {
        "chunks": chunks,
        "show_enroll_button": show_enroll_button,
        })
Пример #4
0
def static_page(pctx, page_path):
    from course.content import get_staticpage_desc, get_processed_page_chunks
    try:
        page_desc = get_staticpage_desc(pctx.repo, pctx.course,
                pctx.course_commit_sha, "staticpages/"+page_path+".yml")
    except ObjectDoesNotExist:
        raise http.Http404()

    chunks = get_processed_page_chunks(
            pctx.course, pctx.repo, pctx.course_commit_sha, page_desc,
            pctx.role, get_now_or_fake_time(pctx.request),
            facilities=pctx.request.relate_facilities)

    return render_course_page(pctx, "course/static-page.html", {
        "chunks": chunks,
        "show_enroll_button": False,
        })
Пример #5
0
def static_page(pctx, page_path):
    # type: (CoursePageContext, Text) -> http.HttpResponse
    from course.content import get_staticpage_desc, get_processed_page_chunks
    try:
        page_desc = get_staticpage_desc(pctx.repo, pctx.course,
                pctx.course_commit_sha, "staticpages/"+page_path+".yml")
    except ObjectDoesNotExist:
        raise http.Http404()

    chunks = get_processed_page_chunks(
            pctx.course, pctx.repo, pctx.course_commit_sha, page_desc,
            pctx.role_identifiers(), get_now_or_fake_time(pctx.request),
            facilities=pctx.request.relate_facilities)

    return render_course_page(pctx, "course/static-page.html", {
        "chunks": chunks,
        "show_enroll_button": False,
        })
Пример #6
0
def course_page(pctx):
    # type: (CoursePageContext) -> http.HttpResponse
    from course.content import get_processed_page_chunks, get_course_desc
    page_desc = get_course_desc(pctx.repo, pctx.course, pctx.course_commit_sha)

    show_enroll_button = (pctx.course.accepts_enrollment
                          and pctx.participation is None)

    if show_enroll_button:
        chunks = None
    else:
        chunks = get_processed_page_chunks(
            pctx.course,
            pctx.repo,
            pctx.course_commit_sha,
            page_desc,
            pctx.role_identifiers(),
            get_now_or_fake_time(pctx.request),
            facilities=pctx.request.relate_facilities)

    if pctx.request.method == 'POST':
        form = StripeForm(pctx.request.POST, pctx=pctx)
        if form.is_valid():
            charge_successful, message = form.charge_card()
            if charge_successful:
                messages.add_message(pctx.request, messages.SUCCESS,
                                     _("Payment was successful."))
                preapproval = ParticipationPreapproval.objects.get_or_create(
                    email=pctx.request.user.email, course=pctx.course)[0]
                preapproval.roles.add(
                    preapproval.roles.model.objects.get(
                        course=preapproval.course,
                        is_default_for_new_participants=True))
                return redirect("relate-enroll", pctx.course.identifier)
            else:
                messages.add_message(pctx.request, messages.ERROR, message)

    if pctx.request.user.is_authenticated and Participation.objects.filter(
            user=pctx.request.user,
            course=pctx.course,
            status=participation_status.requested).count():
        show_enroll_button = False

        messages.add_message(
            pctx.request, messages.INFO,
            _("Your enrollment request is pending. You will be "
              "notified once it has been acted upon."))

        if ParticipationPreapproval.objects.filter(course=pctx.course).exclude(
                institutional_id=None).count():
            if not pctx.request.user.institutional_id:
                from django.urls import reverse
                messages.add_message(
                    pctx.request, messages.WARNING,
                    _("This course uses institutional ID for "
                      "enrollment preapproval, please <a href='%s' "
                      "role='button' class='btn btn-md btn-primary'>"
                      "fill in your institutional ID &nbsp;&raquo;"
                      "</a> in your profile.") %
                    (reverse("relate-user_profile") + "?referer=" +
                     pctx.request.path + "&set_inst_id=1"))
            else:
                if pctx.course.preapproval_require_verified_inst_id:
                    messages.add_message(
                        pctx.request, messages.WARNING,
                        _("Your institutional ID is not verified or "
                          "preapproved. Please contact your course "
                          "staff."))
    elif pctx.request.user.is_authenticated and ParticipationPreapproval.objects.filter(
            course=pctx.course, email__iexact=pctx.request.user.email).exists() and \
            pctx.participation is None:
        return redirect("relate-enroll", pctx.course.identifier)

    return render_course_page(
        pctx, "course/course-page.html", {
            "chunks": chunks,
            "show_enroll_button": show_enroll_button,
            "stripe_form": StripeForm(pctx=pctx),
            "pctx": pctx
        })