def get_current_repo_file(request, course_identifier, path): course = get_object_or_404(Course, identifier=course_identifier) role, participation = get_role_and_participation( request, course) from course.views import check_course_state check_course_state(course, role) from course.content import get_course_commit_sha commit_sha = get_course_commit_sha(course, participation) role, participation = get_role_and_participation(request, course) repo = get_course_repo(course) from course.content import is_repo_file_public if not is_repo_file_public(repo, commit_sha, path): raise PermissionDenied() from course.content import get_repo_blob_data_cached try: data = get_repo_blob_data_cached( repo, path, commit_sha.encode()) except ObjectDoesNotExist: raise http.Http404() from mimetypes import guess_type content_type, _ = guess_type(path) return http.HttpResponse(data, content_type=content_type)
def get_current_repo_file(request, course_identifier, path): course = get_object_or_404(Course, identifier=course_identifier) role, participation = get_role_and_participation(request, course) from course.views import check_course_state check_course_state(course, role) from course.content import get_course_commit_sha commit_sha = get_course_commit_sha(course, participation) role, participation = get_role_and_participation(request, course) repo = get_course_repo(course) from course.content import is_repo_file_public if not is_repo_file_public(repo, commit_sha, path): raise PermissionDenied() from course.content import get_repo_blob_data_cached try: data = get_repo_blob_data_cached(repo, path, commit_sha.encode()) except ObjectDoesNotExist: raise http.Http404() from mimetypes import guess_type content_type, _ = guess_type(path) return http.HttpResponse(data, content_type=content_type)
def get_repo_file_response(repo, path, commit_sha): from course.content import get_repo_blob_data_cached try: data = get_repo_blob_data_cached(repo, path, commit_sha.encode()) except ObjectDoesNotExist: raise http.Http404() from mimetypes import guess_type content_type, _ = guess_type(path) if content_type is None: content_type = "application/octet-stream" return http.HttpResponse(data, content_type=content_type)
def get_repo_file_response(repo, path, commit_sha): from course.content import get_repo_blob_data_cached try: data = get_repo_blob_data_cached(repo, path, commit_sha) except ObjectDoesNotExist: raise http.Http404() from mimetypes import guess_type content_type, _ = guess_type(path) if content_type is None: content_type = "application/octet-stream" return http.HttpResponse(data, content_type=content_type)
def _render_notebook_cells(self, ipynb_path, indices=None, clear_output=False, clear_markdown=False, **kwargs): # type: (Text, Optional[Any], Optional[bool], Optional[bool], **Any) -> Text from course.content import get_repo_blob_data_cached try: ipynb_source = get_repo_blob_data_cached(self.repo, ipynb_path, self.commit_sha).decode() return self._render_notebook_from_source( ipynb_source, indices=indices, clear_output=clear_output, clear_markdown=clear_markdown, **kwargs ) except ObjectDoesNotExist: raise
def get_media(request, course_identifier, commit_sha, media_path): course = get_object_or_404(Course, identifier=course_identifier) role, participation = get_role_and_participation(request, course) repo = get_course_repo(course) from course.content import get_repo_blob_data_cached try: data = get_repo_blob_data_cached(repo, "media/" + media_path, commit_sha.encode()) except ObjectDoesNotExist: raise http.Http404() from mimetypes import guess_type content_type, _ = guess_type(media_path) return http.HttpResponse(data, content_type=content_type)
def get_media(request, course_identifier, commit_sha, media_path): course = get_object_or_404(Course, identifier=course_identifier) role, participation = get_role_and_participation(request, course) repo = get_course_repo(course) from course.content import get_repo_blob_data_cached try: data = get_repo_blob_data_cached( repo, "media/"+media_path, commit_sha.encode()) except ObjectDoesNotExist: raise http.Http404() from mimetypes import guess_type content_type = guess_type(media_path) return http.HttpResponse(data, content_type=content_type)