Beispiel #1
0
 def test_notes_enabled(self):
     '''
     Tests that notes are enabled when the course tab configuration contains
     a tab with type "notes."
     '''
     with self.settings(FEATURES={'ENABLE_STUDENT_NOTES': True}):
         self.course.advanced_modules = ["notes"]
         self.assertTrue(utils.notes_enabled_for_course(self.course))
Beispiel #2
0
 def test_notes_enabled(self):
     '''
     Tests that notes are enabled when the course tab configuration contains
     a tab with type "notes."
     '''
     with self.settings(FEATURES={'ENABLE_STUDENT_NOTES': True}):
         self.course.advanced_modules = ["notes"]
         self.assertTrue(utils.notes_enabled_for_course(self.course))
Beispiel #3
0
    def test_notes_enabled(self):
        """
        Tests that notes are enabled when the course tab configuration contains
        a tab with type "notes."
        """
        self.course.tabs = [{"type": "foo"}, {"name": "My Notes", "type": "notes"}, {"type": "bar"}]

        self.assertTrue(utils.notes_enabled_for_course(self.course))
Beispiel #4
0
    def test_notes_enabled(self):
        '''
        Tests that notes are enabled when the course tab configuration contains
        a tab with type "notes."
        '''
        self.course.tabs = [{'type': 'foo'},
                            {'name': 'My Notes', 'type': 'notes'},
                            {'type': 'bar'}]

        self.assertTrue(utils.notes_enabled_for_course(self.course))
Beispiel #5
0
def notes(request, course_id):
    """ Displays the student's notes. """

    course = get_course_with_access(request.user, course_id, "load")
    if not notes_enabled_for_course(course):
        raise Http404

    notes = Note.objects.filter(course_id=course_id, user=request.user).order_by("-created", "uri")
    context = {"course": course, "notes": notes}

    return render_to_response("notes.html", context)
Beispiel #6
0
def notes(request, course_id):
    ''' Displays the student's notes. '''

    course = get_course_with_access(request.user, course_id, 'load')
    if not notes_enabled_for_course(course):
        raise Http404

    notes = Note.objects.filter(course_id=course_id,
                                user=request.user).order_by('-created', 'uri')
    context = {'course': course, 'notes': notes}

    return render_to_response('notes.html', context)
Beispiel #7
0
def notes(request, course_id):
    ''' Displays the student's notes. '''

    course = get_course_with_access(request.user, course_id, 'load')
    if not notes_enabled_for_course(course):
        raise Http404

    notes = Note.objects.filter(course_id=course_id, user=request.user).order_by('-created', 'uri')
    context = {
        'course': course,
        'notes': notes
    }

    return render_to_response('notes.html', context)
Beispiel #8
0
    def test_notes_enabled(self):
        '''
        Tests that notes are enabled when the course tab configuration contains
        a tab with type "notes."
        '''
        self.course.tabs = [{
            'type': 'foo'
        }, {
            'name': 'My Notes',
            'type': 'notes'
        }, {
            'type': 'bar'
        }]

        self.assertTrue(utils.notes_enabled_for_course(self.course))
Beispiel #9
0
def html_index(request, course_id, book_index, chapter=None):
    """
    Display an HTML textbook.

    course_id: course for which to display text.  The course should have
      "html_textbooks" property defined.

    book index:  zero-based index of which HTML textbook to display.

    chapter:  (optional) one-based index into the chapter array of textbook HTML files to display.
        Defaults to first chapter.  Specifying this assumes that there are separate HTML files for
        each chapter in a textbook.
    """
    course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
    course = get_course_with_access(request.user, 'load', course_key)
    staff_access = bool(has_access(request.user, 'staff', course))
    notes_enabled = notes_enabled_for_course(course)

    book_index = int(book_index)
    if book_index < 0 or book_index >= len(course.html_textbooks):
        raise Http404("Invalid book index value: {0}".format(book_index))
    textbook = course.html_textbooks[book_index]

    if 'url' in textbook:
        textbook['url'] = remap_static_url(textbook['url'], course)
    # then remap all the chapter URLs as well, if they are provided.
    if 'chapters' in textbook:
        for entry in textbook['chapters']:
            entry['url'] = remap_static_url(entry['url'], course)

    student = request.user
    return render_to_response(
        'static_htmlbook.html',
        {
            'book_index': book_index,
            'course': course,
            'textbook': textbook,
            'chapter': chapter,
            'student': student,
            'staff_access': staff_access,
            'notes_enabled': notes_enabled,
            'storage': course.annotation_storage_url,
            'token': retrieve_token(student.email,
                                    course.annotation_token_secret),
        },
    )
Beispiel #10
0
def html_index(request, course_id, book_index, chapter=None):
    """
    Display an HTML textbook.

    course_id: course for which to display text.  The course should have
      "html_textbooks" property defined.

    book index:  zero-based index of which HTML textbook to display.

    chapter:  (optional) one-based index into the chapter array of textbook HTML files to display.
        Defaults to first chapter.  Specifying this assumes that there are separate HTML files for
        each chapter in a textbook.
    """
    course = get_course_with_access(request.user, course_id, 'load')
    staff_access = has_access(request.user, course, 'staff')
    notes_enabled = notes_enabled_for_course(course)

    book_index = int(book_index)
    if book_index < 0 or book_index >= len(course.html_textbooks):
        raise Http404("Invalid book index value: {0}".format(book_index))
    textbook = course.html_textbooks[book_index]

    def remap_static_url(original_url, course):
        input_url = "'" + original_url + "'"
        output_url = replace_static_urls(
            input_url,
            getattr(course, 'data_dir', None),
            course_namespace=course.location
        )
        # strip off the quotes again...
        return output_url[1:-1]

    if 'url' in textbook:
        textbook['url'] = remap_static_url(textbook['url'], course)
    # then remap all the chapter URLs as well, if they are provided.
    if 'chapters' in textbook:
        for entry in textbook['chapters']:
            entry['url'] = remap_static_url(entry['url'], course)

    return render_to_response('static_htmlbook.html',
                              {'book_index': book_index,
                               'course': course,
                               'textbook': textbook,
                               'chapter': chapter,
                               'staff_access': staff_access,
                               'notes_enabled': notes_enabled})
Beispiel #11
0
def html_index(request, course_id, book_index, chapter=None):
    """
    Display an HTML textbook.

    course_id: course for which to display text.  The course should have
      "html_textbooks" property defined.

    book index:  zero-based index of which HTML textbook to display.

    chapter:  (optional) one-based index into the chapter array of textbook HTML files to display.
        Defaults to first chapter.  Specifying this assumes that there are separate HTML files for
        each chapter in a textbook.
    """
    course = get_course_with_access(request.user, course_id, 'load')
    staff_access = has_access(request.user, course, 'staff')
    notes_enabled = notes_enabled_for_course(course)

    book_index = int(book_index)
    if book_index < 0 or book_index >= len(course.html_textbooks):
        raise Http404("Invalid book index value: {0}".format(book_index))
    textbook = course.html_textbooks[book_index]

    def remap_static_url(original_url, course):
        input_url = "'" + original_url + "'"
        output_url = replace_static_urls(input_url,
                                         getattr(course, 'data_dir', None),
                                         course_namespace=course.location)
        # strip off the quotes again...
        return output_url[1:-1]

    if 'url' in textbook:
        textbook['url'] = remap_static_url(textbook['url'], course)
    # then remap all the chapter URLs as well, if they are provided.
    if 'chapters' in textbook:
        for entry in textbook['chapters']:
            entry['url'] = remap_static_url(entry['url'], course)

    return render_to_response(
        'static_htmlbook.html', {
            'book_index': book_index,
            'course': course,
            'textbook': textbook,
            'chapter': chapter,
            'staff_access': staff_access,
            'notes_enabled': notes_enabled
        })
Beispiel #12
0
def html_index(request, course_id, book_index, chapter=None):
    """
    Display an HTML textbook.

    course_id: course for which to display text.  The course should have
      "html_textbooks" property defined.

    book index:  zero-based index of which HTML textbook to display.

    chapter:  (optional) one-based index into the chapter array of textbook HTML files to display.
        Defaults to first chapter.  Specifying this assumes that there are separate HTML files for
        each chapter in a textbook.
    """
    course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
    course = get_course_with_access(request.user, 'load', course_key)
    staff_access = bool(has_access(request.user, 'staff', course))
    notes_enabled = notes_enabled_for_course(course)

    book_index = int(book_index)
    if book_index < 0 or book_index >= len(course.html_textbooks):
        raise Http404("Invalid book index value: {0}".format(book_index))
    textbook = course.html_textbooks[book_index]

    if 'url' in textbook:
        textbook['url'] = remap_static_url(textbook['url'], course)
    # then remap all the chapter URLs as well, if they are provided.
    if 'chapters' in textbook:
        for entry in textbook['chapters']:
            entry['url'] = remap_static_url(entry['url'], course)

    student = request.user
    return render_to_response(
        'static_htmlbook.html',
        {
            'book_index': book_index,
            'course': course,
            'textbook': textbook,
            'chapter': chapter,
            'student': student,
            'staff_access': staff_access,
            'notes_enabled': notes_enabled,
            'storage': course.annotation_storage_url,
            'token': retrieve_token(student.email, course.annotation_token_secret),
        },
    )
Beispiel #13
0
def notes(request, course_id):
    ''' Displays the student's notes. '''

    course = get_course_with_access(request.user, course_id, 'load')
    if not notes_enabled_for_course(course):
        raise Http404

    notes = Note.objects.filter(course_id=course_id, user=request.user).order_by('-created', 'uri')

    student = request.user
    storage = course.annotation_storage_url
    context = {
        'course': course,
        'notes': notes,
        'student': student,
        'storage': storage,
        'token': retrieve_token(student.email, course.annotation_token_secret),
    }
    return render_to_response('notes.html', context)
Beispiel #14
0
def html_index(request, course_id, book_index, chapter=None):
    """
    Display an HTML textbook.

    course_id: course for which to display text.  The course should have
      "html_textbooks" property defined.

    book index:  zero-based index of which HTML textbook to display.

    chapter:  (optional) one-based index into the chapter array of textbook HTML files to display.
        Defaults to first chapter.  Specifying this assumes that there are separate HTML files for
        each chapter in a textbook.
    """
    course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
    course = get_course_with_access(request.user, "load", course_key)
    staff_access = has_access(request.user, "staff", course)
    notes_enabled = notes_enabled_for_course(course)

    book_index = int(book_index)
    if book_index < 0 or book_index >= len(course.html_textbooks):
        raise Http404("Invalid book index value: {0}".format(book_index))
    textbook = course.html_textbooks[book_index]

    if "url" in textbook:
        textbook["url"] = remap_static_url(textbook["url"], course)
    # then remap all the chapter URLs as well, if they are provided.
    if "chapters" in textbook:
        for entry in textbook["chapters"]:
            entry["url"] = remap_static_url(entry["url"], course)

    student = request.user
    return render_to_response(
        "static_htmlbook.html",
        {
            "book_index": book_index,
            "course": course,
            "textbook": textbook,
            "chapter": chapter,
            "student": student,
            "staff_access": staff_access,
            "notes_enabled": notes_enabled,
        },
    )
Beispiel #15
0
def notes(request, course_id):
    ''' Displays the student's notes. '''

    course = get_course_with_access(request.user, 'load', course_id)
    if not notes_enabled_for_course(course):
        raise Http404

    notes = Note.objects.filter(course_id=course_id, user=request.user).order_by('-created', 'uri')

    student = request.user
    storage = course.annotation_storage_url
    context = {
        'course': course,
        'notes': notes,
        'student': student,
        'storage': storage,
        'token': retrieve_token(student.email, course.annotation_token_secret),
    }

    return render_to_response('notes.html', context)
Beispiel #16
0
def notes(request, course_id):
    """ Displays the student's notes. """
    course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
    course = get_course_with_access(request.user, "load", course_key)
    if not notes_enabled_for_course(course):
        raise Http404

    notes = Note.objects.filter(course_id=course_key, user=request.user).order_by("-created", "uri")

    student = request.user
    storage = course.annotation_storage_url
    context = {
        "course": course,
        "notes": notes,
        "student": student,
        "storage": storage,
        "token": retrieve_token(student.email, course.annotation_token_secret),
        "default_tab": "myNotes",
    }

    return render_to_response("notes.html", context)
Beispiel #17
0
def notes(request, course_id):
    ''' Displays the student's notes. '''
    course_key = CourseKey.from_string(course_id)
    course = get_course_with_access(request.user, 'load', course_key)
    if not notes_enabled_for_course(course):
        raise Http404

    notes = Note.objects.filter(course_id=course_key,
                                user=request.user).order_by('-created', 'uri')

    student = request.user
    storage = course.annotation_storage_url
    context = {
        'course': course,
        'notes': notes,
        'student': student,
        'storage': storage,
        'token': None,
        'default_tab': 'myNotes',
    }

    return render_to_response('notes.html', context)
Beispiel #18
0
def api_enabled(request, course_key):
    '''
    Returns True if the api is enabled for the course, otherwise False.
    '''
    course = _get_course(request, course_key)
    return notes_enabled_for_course(course)
Beispiel #19
0
 def test_notes_not_enabled(self):
     '''
     Tests that notes are disabled when the course tab configuration does NOT
     contain a tab with type "notes."
     '''
     self.assertFalse(utils.notes_enabled_for_course(self.course))
Beispiel #20
0
 def test_notes_not_enabled(self):
     '''
     Tests that notes are disabled when the course tab configuration does NOT
     contain a tab with type "notes."
     '''
     self.assertFalse(utils.notes_enabled_for_course(self.course))
Beispiel #21
0
def api_enabled(request, course_key):
    '''
    Returns True if the api is enabled for the course, otherwise False.
    '''
    course = _get_course(request, course_key)
    return notes_enabled_for_course(course)