Beispiel #1
0
def wiki(request, course_key_string, action=None):
    course = get_course(course_key_string)
    course_info = get_course_infos_or_404([course])[0]

    base_page = wiki_utils.get_base_page(course)

    if request.method == 'POST':
        value, word = {
            'open': (True, _(u"opened")),
            'close': (False, _(u"closed"))
        }[request.POST['action']]
        result = wiki_utils.set_permissions(course, value)
        if result:
            messages.success(request,
                             _(u"Wiki was successfully ") + unicode(word))
        else:
            messages.error(request, _(u"Wiki could not be ") + unicode(word))

        return redirect(
            reverse('backoffice:course-wiki', args=[course_key_string]))

    pages = wiki_utils.get_page_tree([base_page])
    html = _(u"This course has no wiki")
    if any(pages):
        pages, html = wiki_utils.render_html_tree(pages, '')

    return render(
        request, 'backoffice/courses/wiki.html', {
            'course_key_string': course_key_string,
            'course_info': course_info,
            'pages': pages,
            'html': html,
            'tab': 'courses',
            'subtab': 'wiki',
        })
Beispiel #2
0
def wiki(request, course_key_string, action=None):
    course_info = get_complete_course_info(get_course(course_key_string))

    ck = CourseKey.from_string(course_key_string)
    course = modulestore().get_course(ck)

    base_page = wiki_utils.get_base_page(course)

    if request.method == 'POST':
        value, word = {'open': (True, _(u"opened")), 'close': (False, _(u"closed"))}[request.POST['action']]
        result = wiki_utils.set_permissions(course, value)
        if result:
            messages.success(request, _(u"Wiki was successfully ") + unicode(word))
        else:
            messages.error(request, _(u"Wiki could not be ") + unicode(word))

        return redirect(reverse('backoffice:course-wiki', args=[course_key_string]))

    pages = wiki_utils.get_page_tree([base_page])
    html = _(u"This course has no wiki")
    if any(pages):
        pages, html = wiki_utils.render_html_tree(pages, '')

    return render(request, 'backoffice/wiki.html', {
            'course_key_string': course_key_string,
            'course_info': course_info,
            'pages': pages,
            'html': html,
            'tab': 'courses',
        })
Beispiel #3
0
 def test_get_page_tree(self):
     # [<URLPath: RUN/>, [<URLPath: RUN/page1/>, [<URLPath: RUN/page1/page11/>, [<URLPath: RUN/page1/page11/page111/>, <URLPath: RUN/page1/page11/page112/>]], <URLPath: RUN/page2/>]]
     from fun.utils import funwiki
     base_page = funwiki.get_base_page(self.course)
     tree = funwiki.get_page_tree([base_page])
     self.assertEqual(2, len(tree))  # root page and list of its children
     self.assertEqual(3, len(tree[1]))  # page1, page2 and list of page1's children
     self.assertEqual(2, len(tree[1][1]))  # page11, and list of it's 2 children
Beispiel #4
0
 def test_render_html_tree(self):
     from fun.utils import funwiki
     base_page = funwiki.get_base_page(self.course)
     tree = funwiki.get_page_tree([base_page])
     tree, html = funwiki.render_html_tree(tree, '')
     self.assertEqual(2, len(BeautifulSoup(html).find('ul').find('ul').find('ul').find_all('li')))  # page111 and page112