def __init__(self, request, course_identifier): # type: (http.HttpRequest, Text) -> None self.request = request self.course_identifier = course_identifier self._permissions_cache = None # type: Optional[FrozenSet[Tuple[Text, Optional[Text]]]] # noqa self._role_identifiers_cache = None # type: Optional[List[Text]] self.old_language = None # using this to prevent nested using as context manager self._is_in_context_manager = False from course.models import Course # noqa self.course = get_object_or_404(Course, identifier=course_identifier) from course.enrollment import get_participation_for_request self.participation = get_participation_for_request( request, self.course) from course.views import check_course_state check_course_state(self.course, self.participation) self.course_commit_sha = get_course_commit_sha(self.course, self.participation) self.repo = get_course_repo(self.course) # logic duplicated in course.content.get_course_commit_sha sha = self.course.active_git_commit_sha.encode() if self.participation is not None: if self.participation.preview_git_commit_sha: preview_sha = self.participation.preview_git_commit_sha.encode( ) with get_course_repo(self.course) as repo: from relate.utils import SubdirRepoWrapper if isinstance(repo, SubdirRepoWrapper): true_repo = repo.repo else: true_repo = cast(dulwich.repo.Repo, repo) try: true_repo[preview_sha] except KeyError: from django.contrib import messages messages.add_message( request, messages.ERROR, _("Preview revision '%s' does not exist--" "showing active course content instead.") % preview_sha.decode()) preview_sha = None finally: true_repo.close() if preview_sha is not None: sha = preview_sha self.course_commit_sha = sha
def __init__(self, request, course_identifier): # type: (http.HttpRequest, Text) -> None self.request = request self.course_identifier = course_identifier self._permissions_cache = None # type: Optional[FrozenSet[Tuple[Text, Optional[Text]]]] # noqa self._role_identifiers_cache = None # type: Optional[List[Text]] self.old_language = None # using this to prevent nested using as context manager self._is_in_context_manager = False from course.models import Course # noqa self.course = get_object_or_404(Course, identifier=course_identifier) from course.enrollment import get_participation_for_request self.participation = get_participation_for_request( request, self.course) from course.views import check_course_state check_course_state(self.course, self.participation) self.course_commit_sha = get_course_commit_sha( self.course, self.participation) self.repo = get_course_repo(self.course) # logic duplicated in course.content.get_course_commit_sha sha = self.course.active_git_commit_sha.encode() if self.participation is not None: if self.participation.preview_git_commit_sha: preview_sha = self.participation.preview_git_commit_sha.encode() with get_course_repo(self.course) as repo: from relate.utils import SubdirRepoWrapper if isinstance(repo, SubdirRepoWrapper): true_repo = repo.repo else: true_repo = cast(dulwich.repo.Repo, repo) try: true_repo[preview_sha] except KeyError: from django.contrib import messages messages.add_message(request, messages.ERROR, _("Preview revision '%s' does not exist--" "showing active course content instead.") % preview_sha.decode()) preview_sha = None finally: true_repo.close() if preview_sha is not None: sha = preview_sha self.course_commit_sha = sha
def get_repo_file(request, course_identifier, commit_sha, path): commit_sha = commit_sha.encode() course = get_object_or_404(Course, identifier=course_identifier) participation = get_participation_for_request(request, course) return get_repo_file_backend(request, course, participation, commit_sha, path)
def get_repo_file(request, course_identifier, commit_sha, path): commit_sha = commit_sha.encode() course = get_object_or_404(Course, identifier=course_identifier) participation = get_participation_for_request(request, course) return get_repo_file_backend( request, course, participation, commit_sha, path)
def get_current_repo_file(request, course_identifier, path): # type: (http.HttpRequest, str, str) -> http.HttpResponse course = get_object_or_404(Course, identifier=course_identifier) participation = get_participation_for_request(request, course) from course.content import get_course_commit_sha commit_sha = get_course_commit_sha(course, participation) return get_repo_file_backend(request, course, participation, commit_sha, path)
def current_repo_file_etag_func(request, course_identifier, path): # type: (http.HttpRequest, str, str) -> str course = get_object_or_404(Course, identifier=course_identifier) participation = get_participation_for_request(request, course) check_course_state(course, participation) from course.content import get_course_commit_sha commit_sha = get_course_commit_sha(course, participation) return ":".join([course_identifier, commit_sha.decode(), path])
def get_current_repo_file(request, course_identifier, path): # type: (http.HttpRequest, str, str) -> http.HttpResponse course = get_object_or_404(Course, identifier=course_identifier) participation = get_participation_for_request(request, course) from course.content import get_course_commit_sha commit_sha = get_course_commit_sha(course, participation) return get_repo_file_backend( request, course, participation, commit_sha, path)
def current_repo_file_etag_func(request, course_identifier, path): # type: (http.HttpRequest, str, str) -> str course = get_object_or_404(Course, identifier=course_identifier) participation = get_participation_for_request(request, course) check_course_state(course, participation) from course.content import get_course_commit_sha commit_sha = get_course_commit_sha(course, participation) return ":".join([course_identifier, commit_sha.decode(), path])
def home(request): # type: (http.HttpRequest) -> http.HttpResponse now_datetime = get_now_or_fake_time(request) current_courses = [] past_courses = [] for course in Course.objects.filter(listed=True): participation = get_participation_for_request(request, course) show = True if course.hidden: perms = get_participation_permissions(course, participation) if (pperm.view_hidden_course_page, None) not in perms: show = False if not course.listed: show = False if show: if (course.end_date is None or now_datetime.date() <= course.end_date): current_courses.append(course) else: past_courses.append(course) def course_sort_key_minor(course): return course.number if course.number is not None else "" def course_sort_key_major(course): return (course.start_date if course.start_date is not None else now_datetime.date()) current_courses.sort(key=course_sort_key_minor) past_courses.sort(key=course_sort_key_minor) current_courses.sort(key=course_sort_key_major, reverse=True) past_courses.sort(key=course_sort_key_major, reverse=True) return render(request, "course/home.html", { "current_courses": current_courses, "past_courses": past_courses, })
def home(request): # type: (http.HttpRequest) -> http.HttpResponse now_datetime = get_now_or_fake_time(request) current_courses = [] past_courses = [] for course in Course.objects.filter(listed=True): participation = get_participation_for_request(request, course) show = True if course.hidden: perms = get_participation_permissions(course, participation) if (pperm.view_hidden_course_page, None) not in perms: show = False if not course.listed: show = False if show: if (course.end_date is None or now_datetime.date() <= course.end_date): current_courses.append(course) else: past_courses.append(course) def course_sort_key_minor(course): return course.number if course.number is not None else "" def course_sort_key_major(course): return (course.start_date if course.start_date is not None else now_datetime.date()) current_courses.sort(key=course_sort_key_minor) past_courses.sort(key=course_sort_key_minor) current_courses.sort(key=course_sort_key_major, reverse=True) past_courses.sort(key=course_sort_key_major, reverse=True) return render(request, "course/home.html", { "current_courses": current_courses, "past_courses": past_courses, })
def __init__(self, request, course_identifier): # type: (http.HttpRequest, Text) -> None self.request = request self.course_identifier = course_identifier self._permissions_cache = None # type: Optional[FrozenSet[Tuple[Text, Optional[Text]]]] # noqa self._role_identifiers_cache = None # type: Optional[List[Text]] self.old_language = None # using this to prevent nested using as context manager self._is_in_context_manager = False from course.models import Course # noqa self.course = get_object_or_404(Course, identifier=course_identifier) from course.enrollment import get_participation_for_request self.participation = get_participation_for_request( request, self.course) from course.views import check_course_state check_course_state(self.course, self.participation) self.repo = get_course_repo(self.course) try: sha = get_course_commit_sha( self.course, self.participation, repo=self.repo, raise_on_nonexistent_preview_commit=True) except CourseCommitSHADoesNotExist as e: from django.contrib import messages messages.add_message(request, messages.ERROR, str(e)) sha = self.course.active_git_commit_sha.encode() self.course_commit_sha = sha
def __init__(self, request, course_identifier): # type: (http.HttpRequest, Text) -> None self.request = request self.course_identifier = course_identifier self._permissions_cache = None # type: Optional[FrozenSet[Tuple[Text, Optional[Text]]]] # noqa self._role_identifiers_cache = None # type: Optional[List[Text]] self.old_language = None # using this to prevent nested using as context manager self._is_in_context_manager = False from course.models import Course # noqa self.course = get_object_or_404(Course, identifier=course_identifier) from course.enrollment import get_participation_for_request self.participation = get_participation_for_request( request, self.course) from course.views import check_course_state check_course_state(self.course, self.participation) self.repo = get_course_repo(self.course) try: sha = get_course_commit_sha( self.course, self.participation, repo=self.repo, raise_on_nonexistent_preview_commit=True) except CourseCommitSHADoesNotExist as e: from django.contrib import messages messages.add_message(request, messages.ERROR, str(e)) sha = self.course.active_git_commit_sha.encode() self.course_commit_sha = sha