def home(request): courses_and_descs_and_invalid_flags = [] for course in Course.objects.all(): repo = get_course_repo(course) desc = get_course_desc(repo, course, course.active_git_commit_sha.encode()) role, participation = get_role_and_participation(request, course) show = True if course.hidden: if role not in [participation_role.teaching_assistant, participation_role.instructor]: show = False if not course.valid: if role != participation_role.instructor: show = False if show: courses_and_descs_and_invalid_flags.append( (course, desc, not course.valid)) def course_sort_key(entry): course, desc, invalid_flag = entry return course.identifier courses_and_descs_and_invalid_flags.sort(key=course_sort_key) return render(request, "course/home.html", { "courses_and_descs_and_invalid_flags": courses_and_descs_and_invalid_flags })
def home(request): courses_and_descs_and_invalid_flags = [] for course in Course.objects.filter(listed=True): repo = get_course_repo(course) desc = get_course_desc(repo, course, course.active_git_commit_sha.encode()) role, participation = get_role_and_participation(request, course) show = True if course.hidden: if role not in [ participation_role.teaching_assistant, participation_role.instructor ]: show = False if not course.valid: if role != participation_role.instructor: show = False if show: courses_and_descs_and_invalid_flags.append( (course, desc, not course.valid)) def course_sort_key(entry): course, desc, invalid_flag = entry return course.identifier courses_and_descs_and_invalid_flags.sort(key=course_sort_key) return render(request, "course/home.html", { "courses_and_descs_and_invalid_flags": courses_and_descs_and_invalid_flags })
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, })
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 »" "</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, })
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 »" "</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, })
def set_course_metadata(apps, schema_editor): Course = apps.get_model("course", "Course") # noqa for course in Course.objects.all(): from course.content import get_course_repo, get_course_desc, get_course_commit_sha repo = get_course_repo(course) course_desc = get_course_desc(repo, course, get_course_commit_sha(course, participation=None)) course.name = course_desc.name course.number = course_desc.number course.time_period = course_desc.run repo.close() course.save()
def __init__(self, request, course_identifier): self.request = request self.course_identifier = course_identifier self.course = get_object_or_404(Course, identifier=course_identifier) self.role, self.participation = get_role_and_participation( request, self.course) from course.views import check_course_state check_course_state(self.course, self.role) self.course_commit_sha = get_active_commit_sha( self.course, self.participation) self.repo = get_course_repo(self.course) self.course_desc = get_course_desc(self.repo, self.course, self.course_commit_sha)
def __init__(self, request, course_identifier): self.request = request self.course_identifier = course_identifier self.course = get_object_or_404(Course, identifier=course_identifier) self.role, self.participation = get_role_and_participation( request, self.course) from course.views import check_course_state check_course_state(self.course, self.role) self.course_commit_sha = get_course_commit_sha(self.course, self.participation) self.repo = get_course_repo(self.course) self.course_desc = get_course_desc(self.repo, self.course, self.course_commit_sha)
def set_course_metadata(apps, schema_editor): Course = apps.get_model("course", "Course") # noqa for course in Course.objects.all(): from course.content import ( get_course_repo, get_course_desc, get_course_commit_sha) repo = get_course_repo(course) course_desc = get_course_desc( repo, course, get_course_commit_sha(course, participation=None)) course.name = course_desc.name course.number = course_desc.number course.time_period = course_desc.run repo.close() course.save()
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 »" "</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 })