Esempio n. 1
0
    def setUp(self):
        super().setUp()

        self.wiki = get_or_create_root()

        self.course_math101 = CourseFactory.create(org='org', number='math101', display_name='Course', metadata={'use_unique_wiki_id': 'false'})  # lint-amnesty, pylint: disable=line-too-long
        self.course_math101_staff = self.create_staff_for_course(
            self.course_math101)

        wiki_math101 = self.create_urlpath(
            self.wiki, course_wiki_slug(self.course_math101))
        wiki_math101_page = self.create_urlpath(wiki_math101, 'Child')
        wiki_math101_page_page = self.create_urlpath(wiki_math101_page,
                                                     'Grandchild')
        self.wiki_math101_pages = [
            wiki_math101, wiki_math101_page, wiki_math101_page_page
        ]

        self.course_math101b = CourseFactory.create(org='org', number='math101b', display_name='Course', metadata={'use_unique_wiki_id': 'true'})  # lint-amnesty, pylint: disable=line-too-long
        self.course_math101b_staff = self.create_staff_for_course(
            self.course_math101b)

        wiki_math101b = self.create_urlpath(
            self.wiki, course_wiki_slug(self.course_math101b))
        wiki_math101b_page = self.create_urlpath(wiki_math101b, 'Child')
        wiki_math101b_page_page = self.create_urlpath(wiki_math101b_page,
                                                      'Grandchild')
        self.wiki_math101b_pages = [
            wiki_math101b, wiki_math101b_page, wiki_math101b_page_page
        ]
Esempio n. 2
0
    def setUp(self):
        super(TestWikiAccess, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments

        self.course_310b = CourseFactory.create(org='org', number='310b', display_name='Course')
        self.course_310b_staff = self.create_staff_for_course(self.course_310b)
        self.course_310b2 = CourseFactory.create(org='org', number='310b_', display_name='Course')
        self.course_310b2_staff = self.create_staff_for_course(self.course_310b2)

        self.wiki_310b = self.create_urlpath(self.wiki, course_wiki_slug(self.course_310b))
        self.wiki_310b2 = self.create_urlpath(self.wiki, course_wiki_slug(self.course_310b2))
Esempio n. 3
0
    def setUp(self):
        super().setUp()

        self.course_310b = CourseFactory.create(org='org', number='310b', display_name='Course')
        self.course_310b_staff = self.create_staff_for_course(self.course_310b)
        self.course_310b2 = CourseFactory.create(org='org', number='310b_', display_name='Course')
        self.course_310b2_staff = self.create_staff_for_course(self.course_310b2)

        self.wiki_310b = self.create_urlpath(self.wiki, course_wiki_slug(self.course_310b))
        self.wiki_310b2 = self.create_urlpath(self.wiki, course_wiki_slug(self.course_310b2))
Esempio n. 4
0
    def setUp(self):
        super(TestWikiAccessForNumericalCourseNumber, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments

        self.course_200 = CourseFactory.create(org='org', number='200', display_name='Course')
        self.course_200_staff = self.create_staff_for_course(self.course_200)

        wiki_200 = self.create_urlpath(self.wiki, course_wiki_slug(self.course_200))
        wiki_200_page = self.create_urlpath(wiki_200, 'Child')
        wiki_200_page_page = self.create_urlpath(wiki_200_page, 'Grandchild')
        self.wiki_200_pages = [wiki_200, wiki_200_page, wiki_200_page_page]
Esempio n. 5
0
    def setUp(self):
        super().setUp()

        self.course_200 = CourseFactory.create(org='org', number='200', display_name='Course')
        self.course_200_staff = self.create_staff_for_course(self.course_200)

        wiki_200 = self.create_urlpath(self.wiki, course_wiki_slug(self.course_200))
        wiki_200_page = self.create_urlpath(wiki_200, 'Child')
        wiki_200_page_page = self.create_urlpath(wiki_200_page, 'Grandchild')
        self.wiki_200_pages = [wiki_200, wiki_200_page, wiki_200_page_page]
Esempio n. 6
0
    def setUp(self):
        super(TestWikiAccessForOldFormatCourseStaffGroups, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments

        self.course_math101c = CourseFactory.create(org='org', number='math101c', display_name='Course')
        Group.objects.get_or_create(name='instructor_math101c')
        self.course_math101c_staff = self.create_staff_for_course(self.course_math101c)

        wiki_math101c = self.create_urlpath(self.wiki, course_wiki_slug(self.course_math101c))
        wiki_math101c_page = self.create_urlpath(wiki_math101c, 'Child')
        wiki_math101c_page_page = self.create_urlpath(wiki_math101c_page, 'Grandchild')
        self.wiki_math101c_pages = [wiki_math101c, wiki_math101c_page, wiki_math101c_page_page]
Esempio n. 7
0
    def setUp(self):
        super().setUp()

        self.course_math101c = CourseFactory.create(org='org', number='math101c', display_name='Course')
        Group.objects.get_or_create(name='instructor_math101c')
        self.course_math101c_staff = self.create_staff_for_course(self.course_math101c)

        wiki_math101c = self.create_urlpath(self.wiki, course_wiki_slug(self.course_math101c))
        wiki_math101c_page = self.create_urlpath(wiki_math101c, 'Child')
        wiki_math101c_page_page = self.create_urlpath(wiki_math101c_page, 'Grandchild')
        self.wiki_math101c_pages = [wiki_math101c, wiki_math101c_page, wiki_math101c_page_page]
Esempio n. 8
0
def course_wiki_redirect(request, course_id, wiki_path=""):
    """
    This redirects to whatever page on the wiki that the course designates
    as it's home page. A course's wiki must be an article on the root (for
    example, "/6.002x") to keep things simple.
    """
    course = get_course_by_id(CourseKey.from_string(course_id))
    course_slug = course_wiki_slug(course)

    valid_slug = True
    if not course_slug:
        log.exception("This course is improperly configured. The slug cannot be empty.")
        valid_slug = False
    if re.match(r'^[-\w\.]+$', course_slug) is None:
        log.exception("This course is improperly configured. The slug can only contain letters, numbers, periods or hyphens.")  # lint-amnesty, pylint: disable=line-too-long
        valid_slug = False

    if not valid_slug:
        return redirect("wiki:get", path="")

    try:
        urlpath = URLPath.get_by_path(wiki_path or course_slug, select_related=True)

        results = list(Article.objects.filter(id=urlpath.article.id))
        if results:
            article = results[0]
        else:
            article = None

    except (NoRootURL, URLPath.DoesNotExist):
        # We will create it in the next block
        urlpath = None
        article = None

    if not article:
        # create it
        root = get_or_create_root()

        if urlpath:
            # Somehow we got a urlpath without an article. Just delete it and
            # recerate it.
            urlpath.delete()

        content = Text(
            # Translators: this string includes wiki markup.  Leave the ** and the _ alone.
            _(u"This is the wiki for **{organization}**'s _{course_name}_.")
        ).format(
            organization=course.display_org_with_default,
            course_name=course.display_name_with_default,
        )
        urlpath = URLPath.create_article(
            root,
            course_slug,
            title=course.display_name_with_default,
            content=content,
            user_message=_("Course page automatically created."),
            user=None,
            ip_address=None,
            article_kwargs={'owner': None,
                            'group': None,
                            'group_read': True,
                            'group_write': True,
                            'other_read': True,
                            'other_write': True,
                            })

    return redirect("wiki:get", path=urlpath.path)