def get(self, request, course_id): """ Renders the teams dashboard, which is shown on the "Teams" tab. Raises a 404 if the course specified by course_id does not exist, the user is not registered for the course, or the teams feature is not enabled. """ course_key = CourseKey.from_string(course_id) course = get_course_with_access(request.user, "load", course_key) if not is_feature_enabled(course): raise Http404 if not CourseEnrollment.is_enrolled(request.user, course.id) and \ not has_access(request.user, 'staff', course, course.id): raise Http404 sort_order = 'name' topics = get_ordered_topics(course, sort_order) topics_page = Paginator(topics, TOPICS_PER_PAGE).page(1) topics_serializer = PaginatedTopicSerializer( instance=topics_page, context={'course_id': course.id, 'sort_order': sort_order} ) user = request.user team_memberships = CourseTeamMembership.get_memberships(request.user.username, [course.id]) team_memberships_page = Paginator(team_memberships, TEAM_MEMBERSHIPS_PER_PAGE).page(1) team_memberships_serializer = PaginatedMembershipSerializer( instance=team_memberships_page, context={'expand': ('team',)}, ) context = { "course": course, "topics": topics_serializer.data, # It is necessary to pass both privileged and staff because only privileged users can # administer discussion threads, but both privileged and staff users are allowed to create # multiple teams (since they are not automatically added to teams upon creation). "user_info": { "username": user.username, "privileged": has_discussion_privileges(user, course_key), "staff": bool(has_access(user, 'staff', course_key)), "team_memberships_data": team_memberships_serializer.data, }, "topic_url": reverse( 'topics_detail', kwargs={'topic_id': 'topic_id', 'course_id': str(course_id)}, request=request ), "topics_url": reverse('topics_list', request=request), "teams_url": reverse('teams_list', request=request), "team_memberships_url": reverse('team_membership_list', request=request), "team_membership_detail_url": reverse('team_membership_detail', args=['team_id', user.username]), "languages": settings.ALL_LANGUAGES, "countries": list(countries), "disable_courseware_js": True, "teams_base_url": reverse('teams_dashboard', request=request, kwargs={'course_id': course_id}), } return render_to_response("teams/teams.html", context)
def is_enabled(cls, course, user=None): """Returns true if the teams feature is enabled in the course. Args: course (CourseDescriptor): the course using the feature user (User): the user interacting with the course """ if not super(TeamsTab, cls).is_enabled(course, user=user): return False return is_feature_enabled(course)
def get(self, request, course_id): """ Renders the teams dashboard, which is shown on the "Teams" tab. Raises a 404 if the course specified by course_id does not exist, the user is not registered for the course, or the teams feature is not enabled. """ course_key = CourseKey.from_string(course_id) course = get_course_with_access(request.user, "load", course_key) if not is_feature_enabled(course): raise Http404 if not CourseEnrollment.is_enrolled(request.user, course.id) and \ not has_access(request.user, 'staff', course, course.id): raise Http404 # Even though sorting is done outside of the serializer, sort_order needs to be passed # to the serializer so that the paginated results indicate how they were sorted. sort_order = 'name' topics = get_alphabetical_topics(course) topics_page = Paginator(topics, TOPICS_PER_PAGE).page(1) # BulkTeamCountPaginatedTopicSerializer will add team counts to the topics in a single # bulk operation per page. topics_serializer = BulkTeamCountPaginatedTopicSerializer( instance=topics_page, context={ 'course_id': course.id, 'sort_order': sort_order }) user = request.user team_memberships = CourseTeamMembership.get_memberships( request.user.username, [course.id]) team_memberships_page = Paginator(team_memberships, TEAM_MEMBERSHIPS_PER_PAGE).page(1) team_memberships_serializer = PaginatedMembershipSerializer( instance=team_memberships_page, context={'expand': ('team', )}, ) context = { "course": course, "topics": topics_serializer.data, # It is necessary to pass both privileged and staff because only privileged users can # administer discussion threads, but both privileged and staff users are allowed to create # multiple teams (since they are not automatically added to teams upon creation). "user_info": { "username": user.username, "privileged": has_discussion_privileges(user, course_key), "staff": bool(has_access(user, 'staff', course_key)), "team_memberships_data": team_memberships_serializer.data, }, "topic_url": reverse('topics_detail', kwargs={ 'topic_id': 'topic_id', 'course_id': str(course_id) }, request=request), "topics_url": reverse('topics_list', request=request), "teams_url": reverse('teams_list', request=request), "team_memberships_url": reverse('team_membership_list', request=request), "team_membership_detail_url": reverse('team_membership_detail', args=['team_id', user.username]), "languages": settings.ALL_LANGUAGES, "countries": list(countries), "disable_courseware_js": True, "teams_base_url": reverse('teams_dashboard', request=request, kwargs={'course_id': course_id}), } return render_to_response("teams/teams.html", context)
def get(self, request, course_id): """ Renders the teams dashboard, which is shown on the "Teams" tab. Raises a 404 if the course specified by course_id does not exist, the user is not registered for the course, or the teams feature is not enabled. """ course_key = CourseKey.from_string(course_id) course = get_course_with_access(request.user, "load", course_key) if not is_feature_enabled(course): raise Http404 if not CourseEnrollment.is_enrolled(request.user, course.id) and \ not has_access(request.user, 'staff', course, course.id): raise Http404 sort_order = 'name' topics = get_ordered_topics(course, sort_order) topics_page = Paginator(topics, TOPICS_PER_PAGE).page(1) topics_serializer = PaginatedTopicSerializer(instance=topics_page, context={ 'course_id': course.id, 'sort_order': sort_order }) user = request.user team_memberships = CourseTeamMembership.get_memberships( request.user.username, [course.id]) team_memberships_page = Paginator(team_memberships, TEAM_MEMBERSHIPS_PER_PAGE).page(1) team_memberships_serializer = PaginatedMembershipSerializer( instance=team_memberships_page, context={'expand': ('team', )}, ) context = { "course": course, "topics": topics_serializer.data, "user_info": { "username": user.username, "privileged": has_discussion_privileges(user, course_key), "team_memberships_data": team_memberships_serializer.data, }, "topic_url": reverse('topics_detail', kwargs={ 'topic_id': 'topic_id', 'course_id': str(course_id) }, request=request), "topics_url": reverse('topics_list', request=request), "teams_url": reverse('teams_list', request=request), "team_memberships_url": reverse('team_membership_list', request=request), "team_membership_detail_url": reverse('team_membership_detail', args=['team_id', user.username]), "languages": settings.ALL_LANGUAGES, "countries": list(countries), "disable_courseware_js": True, "teams_base_url": reverse('teams_dashboard', request=request, kwargs={'course_id': course_id}), } return render_to_response("teams/teams.html", context)
def get(self, request, course_id): """ Renders the teams dashboard, which is shown on the "Teams" tab. Raises a 404 if the course specified by course_id does not exist, the user is not registered for the course, or the teams feature is not enabled. """ course_key = CourseKey.from_string(course_id) course = get_course_with_access(request.user, "load", course_key) if not is_feature_enabled(course): raise Http404 if not CourseEnrollment.is_enrolled(request.user, course.id) and not has_access( request.user, "staff", course, course.id ): raise Http404 # Even though sorting is done outside of the serializer, sort_order needs to be passed # to the serializer so that the paginated results indicate how they were sorted. sort_order = "name" topics = get_alphabetical_topics(course) topics_page = Paginator(topics, TOPICS_PER_PAGE).page(1) # BulkTeamCountPaginatedTopicSerializer will add team counts to the topics in a single # bulk operation per page. topics_serializer = BulkTeamCountPaginatedTopicSerializer( instance=topics_page, context={"course_id": course.id, "sort_order": sort_order} ) user = request.user team_memberships = CourseTeamMembership.get_memberships(request.user.username, [course.id]) team_memberships_page = Paginator(team_memberships, TEAM_MEMBERSHIPS_PER_PAGE).page(1) team_memberships_serializer = PaginatedMembershipSerializer( instance=team_memberships_page, context={"expand": ("team", "user"), "request": request} ) context = { "course": course, "topics": topics_serializer.data, # It is necessary to pass both privileged and staff because only privileged users can # administer discussion threads, but both privileged and staff users are allowed to create # multiple teams (since they are not automatically added to teams upon creation). "user_info": { "username": user.username, "privileged": has_discussion_privileges(user, course_key), "staff": bool(has_access(user, "staff", course_key)), "team_memberships_data": team_memberships_serializer.data, }, "topic_url": reverse( "topics_detail", kwargs={"topic_id": "topic_id", "course_id": str(course_id)}, request=request ), "topics_url": reverse("topics_list", request=request), "teams_url": reverse("teams_list", request=request), "teams_detail_url": reverse("teams_detail", args=["team_id"]), "team_memberships_url": reverse("team_membership_list", request=request), "team_membership_detail_url": reverse("team_membership_detail", args=["team_id", user.username]), "languages": [ [lang[0], _(lang[1])] for lang in settings.ALL_LANGUAGES ], # pylint: disable=translation-of-non-string "countries": list(countries), "disable_courseware_js": True, "teams_base_url": reverse("teams_dashboard", request=request, kwargs={"course_id": course_id}), } return render_to_response("teams/teams.html", context)