views.py 1.7 KB
Newer Older
1 2 3 4 5
"""
Views to support the edX Notes feature.
"""

from django.conf import settings
6
from django.contrib.auth.decorators import login_required
7
from django.http import Http404
8

David Baumgold committed
9
from edxmako.shortcuts import render_to_response
10
from opaque_keys.edx.locations import SlashSeparatedCourseKey
11
from courseware.courses import get_course_with_access
12
from courseware.tabs import EnrolledTab
13
from notes.models import Note
14
from notes.utils import notes_enabled_for_course
15
from xmodule.annotator_token import retrieve_token
16
from django.utils.translation import ugettext_noop
17

Arthur Barrett committed
18

19
@login_required
20
def notes(request, course_id):
21
    ''' Displays the student's notes. '''
22 23
    course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
    course = get_course_with_access(request.user, 'load', course_key)
24 25
    if not notes_enabled_for_course(course):
        raise Http404
Arthur Barrett committed
26

27
    notes = Note.objects.filter(course_id=course_key, user=request.user).order_by('-created', 'uri')
daniel cebrian committed
28 29 30

    student = request.user
    storage = course.annotation_storage_url
31 32
    context = {
        'course': course,
daniel cebrian committed
33 34
        'notes': notes,
        'student': student,
35 36
        'storage': storage,
        'token': retrieve_token(student.email, course.annotation_token_secret),
37
        'default_tab': 'myNotes',
38 39 40
    }

    return render_to_response('notes.html', context)
41 42


43
class NotesTab(EnrolledTab):
44 45 46
    """
    A tab for the course notes.
    """
47
    type = 'notes'
48
    title = ugettext_noop("My Notes")
49 50 51 52
    view_name = "notes"

    @classmethod
    def is_enabled(cls, course, user=None):
53
        if not super(NotesTab, cls).is_enabled(course, user):
54 55
            return False
        return settings.FEATURES.get('ENABLE_STUDENT_NOTES') and "notes" in course.advanced_modules