Ejemplo n.º 1
0
def view(request, course_prefix, course_suffix, slug):

    common_page_data = request.common_page_data

    try:
        #getByCourse takes care of checking for draft vs live, is_deleted and live times
        video = Video.objects.getByCourse(
            course=common_page_data['course']).get(slug=slug)
    except Video.DoesNotExist:
        raise Http404

    if not common_page_data['is_course_admin']:
        visit_log = PageVisitLog(
            course=common_page_data['ready_course'],
            user=request.user,
            page_type='video',
            object_id=str(video.id),
        )
        visit_log.save()

    videos = Video.objects.getByCourse(course=common_page_data['course'])
    #Get index of current video
    cur_index = None  #just code safety
    for index, item in enumerate(videos):
        if item == video:
            cur_index = index
            break

    #code safety
    next_slug = None
    prev_slug = None

    if cur_index is not None:
        if cur_index > 0:
            prev_slug = videos[cur_index - 1].slug
        else:
            prev_slug = None
        if cur_index < videos.count() - 1:
            next_slug = videos[cur_index + 1].slug
        else:
            next_slug = None

    video_rec = request.user.videoactivity_set.filter(video=video)
    if video_rec:
        video_rec = video_rec[0]
    else:
        #note student field to be renamed to user, VideoActivity for all users now
        video_rec = VideoActivity(student=request.user,
                                  course=common_page_data['course'],
                                  video=video)
        video_rec.save()

    return render_to_response('videos/view.html', {
        'common_page_data': common_page_data,
        'video': video,
        'video_rec': video_rec,
        'prev_slug': prev_slug,
        'next_slug': next_slug
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def view(request, course_prefix, course_suffix, slug):
    try:
        common_page_data = get_common_page_data(request, course_prefix, course_suffix)
    except:
        raise Http404

    try:
        video = Video.objects.get(course=common_page_data['course'], slug=slug)
    except Video.DoesNotExist:
        raise Http404
    
    if not common_page_data['is_course_admin']:
        visit_log = PageVisitLog(
            course = common_page_data['ready_course'],
            user = request.user,
            page_type= 'video',
            object_id = str(video.id),
        )
        visit_log.save()

    video_rec = request.user.videoactivity_set.filter(video=video)
    if video_rec:
        video_rec = video_rec[0]
    else:
        #note student field to be renamed to user, VideoActivity for all users now
        video_rec = VideoActivity(student=request.user, course=common_page_data['course'], video=video)
        video_rec.save()

    if video.mode == 'ready':
        draft_version = video.image
        video = draft_version

    return render_to_response('videos/view.html', {'common_page_data': common_page_data, 'video': video, 'video_rec':video_rec}, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def view(request, course_prefix, course_suffix, slug):
    try:
        common_page_data = get_common_page_data(request, course_prefix, course_suffix)
    except:
        raise Http404

    video = None
    video_rec = None
    if request.user.is_authenticated():
        #video = Video.objects.get(course=common_page_data['production_course'], slug=slug)
        video = Video.objects.get(course=common_page_data['course'], slug=slug)
        #video_rec = request.user.videoactivity_set.filter(video=video)
        video_rec = request.user.videoactivity_set.filter(video=video)
        if video_rec:
            video_rec = video_rec[0]
        else:
            #if student, needs to be an easy way to check if member of group
            user_groups = request.user.groups.all()
            for group in user_groups:
                if group == common_page_data['course'].student_group:
                    video_rec = VideoActivity(student=request.user, course=common_page_data['course'], video=video)
                    video_rec.save()
                    break

    return render_to_response('videos/view.html', {'common_page_data': common_page_data, 'video': video, 'video_rec':video_rec}, context_instance=RequestContext(request))
Ejemplo n.º 4
0
def view(request, course_prefix, course_suffix, slug):
    try:
        common_page_data = get_common_page_data(request, course_prefix, course_suffix)
    except:
        raise Http404

    try:
        video = Video.objects.get(course=common_page_data["course"], slug=slug)
    except Video.DoesNotExist:
        raise Http404

    if not common_page_data["is_course_admin"]:
        visit_log = PageVisitLog(
            course=common_page_data["ready_course"], user=request.user, page_type="video", object_id=str(video.id)
        )
        visit_log.save()

    video_rec = request.user.videoactivity_set.filter(video=video)
    if video_rec:
        video_rec = video_rec[0]
    else:
        # note student field to be renamed to user, VideoActivity for all users now
        video_rec = VideoActivity(student=request.user, course=common_page_data["course"], video=video)
        video_rec.save()

    return render(
        request, "videos/view.html", {"common_page_data": common_page_data, "video": video, "video_rec": video_rec}
    )
Ejemplo n.º 5
0
def view(request, course_prefix, course_suffix, slug):

    common_page_data = request.common_page_data
    
    try:
        #getByCourse takes care of checking for draft vs live, is_deleted and live times
        video = Video.objects.getByCourse(course=common_page_data['course']).get(slug=slug)
    except Video.DoesNotExist:
        raise Http404
    
    if not common_page_data['is_course_admin']:
        visit_log = PageVisitLog(
            course = common_page_data['ready_course'],
            user = request.user,
            page_type= 'video',
            object_id = str(video.id),
        )
        visit_log.save()

    if not 'video_quiz_mode' in request.session:
        #Default to include quizzes in viewing videos
        request.session['video_quiz_mode'] = "quizzes included"

    videos = Video.objects.getByCourse(course=common_page_data['course'])
    #Get index of current video
    cur_index = None #just code safety
    for index, item in enumerate(videos):
        if item == video:
            cur_index = index
            break

    #code safety
    next_slug = None
    prev_slug = None

    if cur_index is not None:
        if cur_index > 0:
            prev_slug = videos[cur_index-1].slug
        else:
            prev_slug = None
        if cur_index < videos.count() - 1:
            next_slug = videos[cur_index+1].slug
        else:
            next_slug = None

    video_rec = request.user.videoactivity_set.filter(video=video)
    if video_rec:
        video_rec = video_rec[0]
    else:
        #note student field to be renamed to user, VideoActivity for all users now
        video_rec = VideoActivity(student=request.user, course=common_page_data['course'], video=video)
        video_rec.save()
        
    has_ex = VideoToExercise.objects.filter(is_deleted=False, video=video).exists()

    no_ex = 1 if (not has_ex) or request.session['video_quiz_mode'] != "quizzes included" else 0
    return render_to_response('videos/view.html', {'common_page_data': common_page_data, 'video': video, 'video_rec':video_rec, 'prev_slug': prev_slug, 'next_slug': next_slug, 'no_ex':no_ex}, context_instance=RequestContext(request))
Ejemplo n.º 6
0
def view(request, course_prefix, course_suffix, slug):
    try:
        common_page_data = get_common_page_data(request, course_prefix, course_suffix)
    except:
        raise Http404

    try:
        video = Video.objects.get(course=common_page_data["course"], slug=slug)
    except Video.DoesNotExist:
        raise Http404

    if not common_page_data["is_course_admin"]:
        visit_log = PageVisitLog(
            course=common_page_data["ready_course"], user=request.user, page_type="video", object_id=str(video.id)
        )
        visit_log.save()

    videos = Video.objects.getByCourse(course=common_page_data["course"])
    # Get index of current video
    for index, item in enumerate(videos):
        if item == video:
            cur_index = index
            break

    if cur_index > 0:
        prev_slug = videos[cur_index - 1].slug
    else:
        prev_slug = None
    if cur_index < videos.count() - 1:
        next_slug = videos[cur_index + 1].slug
    else:
        next_slug = None

    video_rec = request.user.videoactivity_set.filter(video=video)
    if video_rec:
        video_rec = video_rec[0]
    else:
        # note student field to be renamed to user, VideoActivity for all users now
        video_rec = VideoActivity(student=request.user, course=common_page_data["course"], video=video)
        video_rec.save()

    return render_to_response(
        "videos/view.html",
        {
            "common_page_data": common_page_data,
            "video": video,
            "video_rec": video_rec,
            "prev_slug": prev_slug,
            "next_slug": next_slug,
        },
        context_instance=RequestContext(request),
    )
Ejemplo n.º 7
0
def view(request, course_prefix, course_suffix, slug):
    try:
        common_page_data = get_common_page_data(request, course_prefix, course_suffix)
    except:
        raise Http404

    video = Video.objects.get(course=common_page_data['course'], slug=slug)            
    video_rec = request.user.videoactivity_set.filter(video=video)
    if video_rec:
        video_rec = video_rec[0]
    else:
        #note student field to be renamed to user, VideoActivity for all users now
        video_rec = VideoActivity(student=request.user, course=common_page_data['course'], video=video)
        video_rec.save()

    if video.mode == 'ready':
        draft_version = video.image
        video = draft_version

    return render_to_response('videos/view.html', {'common_page_data': common_page_data, 'video': video, 'video_rec':video_rec}, context_instance=RequestContext(request))
Ejemplo n.º 8
0
def view(request, course_prefix, course_suffix, slug):
    try:
        common_page_data = get_common_page_data(request, course_prefix,
                                                course_suffix)
    except:
        raise Http404

    try:
        video = Video.objects.get(course=common_page_data['course'], slug=slug)
    except Video.DoesNotExist:
        raise Http404

    if not common_page_data['is_course_admin']:
        visit_log = PageVisitLog(
            course=common_page_data['ready_course'],
            user=request.user,
            page_type='video',
            object_id=str(video.id),
        )
        visit_log.save()

    video_rec = request.user.videoactivity_set.filter(video=video)
    if video_rec:
        video_rec = video_rec[0]
    else:
        #note student field to be renamed to user, VideoActivity for all users now
        video_rec = VideoActivity(student=request.user,
                                  course=common_page_data['course'],
                                  video=video)
        video_rec.save()

    if video.mode == 'ready':
        draft_version = video.image
        video = draft_version

    return render_to_response('videos/view.html', {
        'common_page_data': common_page_data,
        'video': video,
        'video_rec': video_rec
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 9
0
def view(request, course_prefix, course_suffix, slug):

    common_page_data = request.common_page_data
    
    try:
        #getByCourse takes care of checking for draft vs live, is_deleted and live times
        video = Video.objects.getByCourse(course=common_page_data['course']).get(slug=slug)
    except Video.DoesNotExist:
        raise Http404
    
    if not common_page_data['is_course_admin']:
        visit_log = PageVisitLog(
            course = common_page_data['ready_course'],
            user = request.user,
            page_type= 'video',
            object_id = str(video.id),
        )
        visit_log.save()

    if not 'video_quiz_mode' in request.session:
        #Default to include quizzes in viewing videos
        request.session['video_quiz_mode'] = "quizzes included"

    videos = Video.objects.getByCourse(course=common_page_data['course'])
    #Get index of current video
    cur_index = None #just code safety
    for index, item in enumerate(videos):
        if item == video:
            cur_index = index
            break

    ready_section = video.section
    if ready_section and ready_section.mode == "draft":
        ready_section = ready_section.image

    #code safety
    next_slug = None
    prev_slug = None

    if cur_index is not None:
        if cur_index > 0:
            prev_slug = videos[cur_index-1].slug
        else:
            prev_slug = None
        if cur_index < videos.count() - 1:
            next_slug = videos[cur_index+1].slug
        else:
            next_slug = None

    video_rec = request.user.videoactivity_set.filter(video=video)
    if video_rec:
        video_rec = video_rec[0]
    else:
        #note student field to be renamed to user, VideoActivity for all users now
        video_rec = VideoActivity(student=request.user, course=common_page_data['course'], video=video)
        video_rec.save()
        
    course = common_page_data['course']

    key = ('video', video.id)
    l1items, l2items = get_contentgroup_data(course=course)
    downloadable_content = get_children(key, l1items, l2items)

    if video.exam:
        try:
            exam = video.exam
            video_obj = videos_in_exam_metadata(exam.xml_metadata, times_for_video_slug=video.slug)
            question_times = video_obj['question_times']

        except Exam.DoesNotExist:
            raise Http404
    else:
        sections = ContentSection.objects.getByCourse(course) 
        section = sections[0]
        # create fake exam as exam template (which is what displays all videos) needs exam data to function
        # correctly (TODO: Refactor this)
        exam = Exam(course=course, slug=slug, title=video.title, description="Empty Exam", html_content="", xml_metadata="", due_date='', assessment_type="survey", mode="draft", total_score=0, grade_single=0, grace_period='', partial_credit_deadline='', late_penalty=0, submissions_permitted=0, resubmission_penalty=0, exam_type="survey", autograde=0, display_single=0, invideo=1, section=section,)
        exam.live_datetime = video.live_datetime    # needed so video shows up
        question_times = ""

    return render_to_response('exams/view_exam.html', 
                              {
                               'common_page_data':    common_page_data, 
                               'video':               video,
                               'ready_section':       ready_section,
                               'video_rec':           video_rec, 
                               'prev_slug':           prev_slug, 
                               'next_slug':           next_slug, 
                               'downloadable_content':downloadable_content,
                               'json_pre_pop':"{}",
                               'scores':"{}",
                               'editable':True,
                               'single_question':exam.display_single,
                               'videotest':exam.invideo,
                               'question_times':json.dumps(question_times),
                               'allow_submit':True,
                               'children': downloadable_content,
                               'exam':exam
                              },
                              context_instance=RequestContext(request))
Ejemplo n.º 10
0
def view(request, course_prefix, course_suffix, slug):

    common_page_data = request.common_page_data
    
    try:
        #getByCourse takes care of checking for draft vs live, is_deleted and live times
        video = Video.objects.getByCourse(course=common_page_data['course']).get(slug=slug)
    except Video.DoesNotExist:
        raise Http404
    
    if not common_page_data['is_course_admin']:
        visit_log = PageVisitLog(
            course = common_page_data['ready_course'],
            user = request.user,
            page_type= 'video',
            object_id = str(video.id),
        )
        visit_log.save()

    if not 'video_quiz_mode' in request.session:
        #Default to include quizzes in viewing videos
        request.session['video_quiz_mode'] = "quizzes included"

    videos = Video.objects.getByCourse(course=common_page_data['course'])
    #Get index of current video
    cur_index = None #just code safety
    for index, item in enumerate(videos):
        if item == video:
            cur_index = index
            break

    #code safety
    next_slug = None
    prev_slug = None

    if cur_index is not None:
        if cur_index > 0:
            prev_slug = videos[cur_index-1].slug
        else:
            prev_slug = None
        if cur_index < videos.count() - 1:
            next_slug = videos[cur_index+1].slug
        else:
            next_slug = None

    video_rec = request.user.videoactivity_set.filter(video=video)
    if video_rec:
        video_rec = video_rec[0]
    else:
        #note student field to be renamed to user, VideoActivity for all users now
        video_rec = VideoActivity(student=request.user, course=common_page_data['course'], video=video)
        video_rec.save()
        
    course = common_page_data['course']
    full_contentsection_list, full_index_list = get_full_contentsection_list(course, filter_children=True)

    if request.user.is_authenticated():
        is_logged_in = 1
    else:
        is_logged_in = 0    

    key = ('video', video.id)
    l1items, l2items = get_contentgroup_data(course=course)
    downloadable_content = get_children(key, l1items, l2items)

    if video.exam:
        try:
            #exam = Exam.objects.get(course=course, is_deleted=0, slug=exam_slug)
            exam = video.exam
            display_single = exam.display_single
            invideo = exam.invideo
            metadata_dom = parseString(exam.xml_metadata) #The DOM corresponding to the XML metadata
            video_questions = metadata_dom.getElementsByTagName('video')
           
            question_times = {}
            for video_node in video_questions:
                video_slug = video_node.getAttribute("url-identifier")
                if video_slug == "":
                    video_slug = video_node.getAttribute("url_identifier")
                if video_slug == video.slug:
                    question_children = video_node.getElementsByTagName("question")
                    times = []
                    for question in question_children:
                        time = "sec_%s" % question.getAttribute("time")
                        if time not in question_times:
                            question_times[time] = [] 
                        question_times[time].append(question.getAttribute("id"))

            print json.dumps(question_times)

        except Exam.DoesNotExist:
            raise Http404
    else:
        sections = ContentSection.objects.getByCourse(course) 
        section = sections[0]
        # create fake exam as exam template (which is what displays all videos) needs exam data to function
        # correctly (TODO: Refactor this)
        exam = Exam(course=course, slug=slug, title=video.title, description="Empty Exam", html_content="", xml_metadata="", due_date='', assessment_type="survey", mode="draft", total_score=0, grade_single=0, grace_period='', partial_credit_deadline='', late_penalty=0, submissions_permitted=0, resubmission_penalty=0, exam_type="survey", autograde=0, display_single=0, invideo=1, section=section,)
        exam.live_datetime = video.live_datetime    # needed so video shows up
        question_times = ""

    videoURL = None
    thumbnailPath = None
    
    if is_storage_local():
        videoURL = local_file_server_root() + "/" + str(video.file)
        thumbnailPath = local_file_server_root() + "/" + course.prefix + "/" + course.suffix + "/videos/" + str(video.id if video.mode == 'draft' else video.image.id) + "/jpegs/"
    elif video.url:
        videoURL = "http://www.youtube.com/embed/" + (video.url if video.mode == 'draft' else video.image.url) + "?autoplay=0&wmode=transparent&fs=0&rel=0&modestbranding=1&showinfo=0&start=0&enablejsapi=1&disablekb=1&amp;"
        thumbnailPath = "http://" + settings.AWS_STORAGE_BUCKET_NAME + ".s3-website-us-west-2.amazonaws.com/" + course.prefix + "/" + course.suffix + "/videos/" + str(video.id if video.mode == 'draft' else video.image.id) + "/jpegs/"


    # change from 'videos/view.html' to 'exams/view_exam.html'
    return render_to_response('exams/view_exam.html', 
                              {
                               'common_page_data':    common_page_data, 
                               'video':               video, 
                               'video_rec':           video_rec,
                               'videoURL':            videoURL,
                               'thumbnailPath':       thumbnailPath,
                               'prev_slug':           prev_slug, 
                               'next_slug':           next_slug, 
                               'contentsection_list': full_contentsection_list, 
                               'full_index_list':     full_index_list,
                               'is_logged_in':        is_logged_in,
                               'downloadable_content':downloadable_content,
                               'json_pre_pop':"{}",
                               'scores':"{}",
                               'editable':True,
                               'single_question':exam.display_single,
                               'videotest':exam.invideo,
                               'question_times':json.dumps(question_times),
                               'allow_submit':True,
                               'children': downloadable_content,
                               'exam':exam
                              },
                              context_instance=RequestContext(request))
Ejemplo n.º 11
0
def view(request, course_prefix, course_suffix, slug):

    common_page_data = request.common_page_data

    try:
        # getByCourse takes care of checking for draft vs live, is_deleted and live times
        video = Video.objects.getByCourse(course=common_page_data["course"]).get(slug=slug)
    except Video.DoesNotExist:
        raise Http404

    if not common_page_data["is_course_admin"]:
        visit_log = PageVisitLog(
            course=common_page_data["ready_course"], user=request.user, page_type="video", object_id=str(video.id)
        )
        visit_log.save()

    if not "video_quiz_mode" in request.session:
        # Default to include quizzes in viewing videos
        request.session["video_quiz_mode"] = "quizzes included"

    videos = Video.objects.getByCourse(course=common_page_data["course"])
    # Get index of current video
    cur_index = None  # just code safety
    for index, item in enumerate(videos):
        if item == video:
            cur_index = index
            break

    # code safety
    next_slug = None
    prev_slug = None

    if cur_index is not None:
        if cur_index > 0:
            prev_slug = videos[cur_index - 1].slug
        else:
            prev_slug = None
        if cur_index < videos.count() - 1:
            next_slug = videos[cur_index + 1].slug
        else:
            next_slug = None

    video_rec = request.user.videoactivity_set.filter(video=video)
    if video_rec:
        video_rec = video_rec[0]
    else:
        # note student field to be renamed to user, VideoActivity for all users now
        video_rec = VideoActivity(student=request.user, course=common_page_data["course"], video=video)
        video_rec.save()

    course = common_page_data["course"]
    full_contentsection_list, full_index_list = get_full_contentsection_list(course, filter_children=True)

    if request.user.is_authenticated():
        is_logged_in = 1
    else:
        is_logged_in = 0

    key = ("video", video.id)
    l1items, l2items = get_contentgroup_data(course=course)
    downloadable_content = get_children(key, l1items, l2items)

    if video.exam:
        try:
            # exam = Exam.objects.get(course=course, is_deleted=0, slug=exam_slug)
            exam = video.exam
            display_single = exam.display_single
            invideo = exam.invideo
            metadata_dom = parseString(exam.xml_metadata)  # The DOM corresponding to the XML metadata
            video_questions = metadata_dom.getElementsByTagName("video")

            question_times = {}
            for video_node in video_questions:
                video_slug = video_node.getAttribute("url-identifier")
                if video_slug == "":
                    video_slug = video_node.getAttribute("url_identifier")
                if video_slug == video.slug:
                    question_children = video_node.getElementsByTagName("question")
                    times = []
                    for question in question_children:
                        time = "sec_%s" % question.getAttribute("time")
                        if time not in question_times:
                            question_times[time] = []
                        question_times[time].append(question.getAttribute("id"))

            print json.dumps(question_times)

        except Exam.DoesNotExist:
            raise Http404
    else:
        sections = ContentSection.objects.getByCourse(course)
        section = sections[0]
        # create fake exam as exam template (which is what displays all videos) needs exam data to function
        # correctly (TODO: Refactor this)
        exam = Exam(
            course=course,
            slug=slug,
            title=video.title,
            description="Empty Exam",
            html_content="",
            xml_metadata="",
            due_date="",
            assessment_type="survey",
            mode="draft",
            total_score=0,
            grade_single=0,
            grace_period="",
            partial_credit_deadline="",
            late_penalty=0,
            submissions_permitted=0,
            resubmission_penalty=0,
            exam_type="survey",
            autograde=0,
            display_single=0,
            invideo=1,
            section=section,
        )
        exam.live_datetime = video.live_datetime  # needed so video shows up
        question_times = ""

    # change from 'videos/view.html' to 'exams/view_exam.html'
    return render_to_response(
        "exams/view_exam.html",
        {
            "common_page_data": common_page_data,
            "video": video,
            "video_rec": video_rec,
            "prev_slug": prev_slug,
            "next_slug": next_slug,
            "contentsection_list": full_contentsection_list,
            "full_index_list": full_index_list,
            "is_logged_in": is_logged_in,
            "downloadable_content": downloadable_content,
            "json_pre_pop": "{}",
            "scores": "{}",
            "editable": True,
            "single_question": exam.display_single,
            "videotest": exam.invideo,
            "question_times": json.dumps(question_times),
            "allow_submit": True,
            "children": downloadable_content,
            "exam": exam,
        },
        context_instance=RequestContext(request),
    )
Ejemplo n.º 12
0
def view(request, course_prefix, course_suffix, slug):

    common_page_data = request.common_page_data
    
    try:
        #getByCourse takes care of checking for draft vs live, is_deleted and live times
        video = Video.objects.getByCourse(course=common_page_data['course']).get(slug=slug)
    except Video.DoesNotExist:
        raise Http404
    
    if not common_page_data['is_course_admin']:
        visit_log = PageVisitLog(
            course = common_page_data['ready_course'],
            user = request.user,
            page_type= 'video',
            object_id = str(video.id),
        )
        visit_log.save()

    if not 'video_quiz_mode' in request.session:
        #Default to include quizzes in viewing videos
        request.session['video_quiz_mode'] = "quizzes included"

    videos = Video.objects.getByCourse(course=common_page_data['course'])
    #Get index of current video
    cur_index = None #just code safety
    for index, item in enumerate(videos):
        if item == video:
            cur_index = index
            break

    #code safety
    next_slug = None
    prev_slug = None

    if cur_index is not None:
        if cur_index > 0:
            prev_slug = videos[cur_index-1].slug
        else:
            prev_slug = None
        if cur_index < videos.count() - 1:
            next_slug = videos[cur_index+1].slug
        else:
            next_slug = None

    video_rec = request.user.videoactivity_set.filter(video=video)
    if video_rec:
        video_rec = video_rec[0]
    else:
        #note student field to be renamed to user, VideoActivity for all users now
        video_rec = VideoActivity(student=request.user, course=common_page_data['course'], video=video)
        video_rec.save()
        
    has_ex = VideoToExercise.objects.filter(is_deleted=False, video=video).exists()

    no_ex = 1 if (not has_ex) or request.session['video_quiz_mode'] != "quizzes included" else 0
    
    course = common_page_data['course']
    contentsection_list = ContentSection.objects.getByCourse(course=course)
    video_list = videos #Video.objects.getByCourse(course=course)
    pset_list =  ProblemSet.objects.getByCourse(course=course)
    additional_pages =  AdditionalPage.objects.getSectionPagesByCourse(course=course)
    file_list = File.objects.getByCourse(course=course)
    groups = ContentGroup.objects.getByCourse(course=course)
    level1_items, level2_items = group_data(groups)

    full_contentsection_list, full_index_list = get_full_contentsection_list(course, contentsection_list, video_list, pset_list, additional_pages, file_list, level2_items)

    if request.user.is_authenticated():
        is_logged_in = 1
    else:
        is_logged_in = 0    
    
    return render_to_response('videos/view.html', 
                              {'common_page_data': common_page_data, 
                               'video': video, 
                               'video_rec':video_rec, 
                               'prev_slug': prev_slug, 
                               'next_slug': next_slug, 
                               'no_ex': no_ex,
                               'contentsection_list': full_contentsection_list, 
                               'full_index_list': full_index_list,
                               'is_logged_in': is_logged_in}, 
                              context_instance=RequestContext(request))
Ejemplo n.º 13
0
def view(request, course_prefix, course_suffix, slug):

    common_page_data = request.common_page_data

    try:
        #getByCourse takes care of checking for draft vs live, is_deleted and live times
        video = Video.objects.getByCourse(
            course=common_page_data['course']).get(slug=slug)
    except Video.DoesNotExist:
        raise Http404

    if not common_page_data['is_course_admin']:
        visit_log = PageVisitLog(
            course=common_page_data['ready_course'],
            user=request.user,
            page_type='video',
            object_id=str(video.id),
        )
        visit_log.save()

    if not 'video_quiz_mode' in request.session:
        #Default to include quizzes in viewing videos
        request.session['video_quiz_mode'] = "quizzes included"

    videos = Video.objects.getByCourse(course=common_page_data['course'])
    #Get index of current video
    cur_index = None  #just code safety
    for index, item in enumerate(videos):
        if item == video:
            cur_index = index
            break

    #code safety
    next_slug = None
    prev_slug = None

    if cur_index is not None:
        if cur_index > 0:
            prev_slug = videos[cur_index - 1].slug
        else:
            prev_slug = None
        if cur_index < videos.count() - 1:
            next_slug = videos[cur_index + 1].slug
        else:
            next_slug = None

    video_rec = request.user.videoactivity_set.filter(video=video)
    if video_rec:
        video_rec = video_rec[0]
    else:
        #note student field to be renamed to user, VideoActivity for all users now
        video_rec = VideoActivity(student=request.user,
                                  course=common_page_data['course'],
                                  video=video)
        video_rec.save()

    has_ex = VideoToExercise.objects.filter(is_deleted=False,
                                            video=video).exists()

    no_ex = 1 if (
        not has_ex
    ) or request.session['video_quiz_mode'] != "quizzes included" else 0

    course = common_page_data['course']
    contentsection_list = ContentSection.objects.getByCourse(course=course)
    video_list = videos  #Video.objects.getByCourse(course=course)
    pset_list = ProblemSet.objects.getByCourse(course=course)
    additional_pages = AdditionalPage.objects.getSectionPagesByCourse(
        course=course)
    file_list = File.objects.getByCourse(course=course)

    full_contentsection_list, full_index_list = get_full_contentsection_list(
        course, contentsection_list, video_list, pset_list, additional_pages,
        file_list)

    if request.user.is_authenticated():
        is_logged_in = 1
    else:
        is_logged_in = 0

    return render_to_response('videos/view.html', {
        'common_page_data': common_page_data,
        'video': video,
        'video_rec': video_rec,
        'prev_slug': prev_slug,
        'next_slug': next_slug,
        'no_ex': no_ex,
        'contentsection_list': full_contentsection_list,
        'full_index_list': full_index_list,
        'is_logged_in': is_logged_in
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 14
0
def view(request, course_prefix, course_suffix, slug):

    common_page_data = request.common_page_data

    try:
        #getByCourse takes care of checking for draft vs live, is_deleted and live times
        video = Video.objects.getByCourse(
            course=common_page_data['course']).get(slug=slug)
    except Video.DoesNotExist:
        raise Http404

    if not common_page_data['is_course_admin']:
        visit_log = PageVisitLog(
            course=common_page_data['ready_course'],
            user=request.user,
            page_type='video',
            object_id=str(video.id),
        )
        visit_log.save()

    if not 'video_quiz_mode' in request.session:
        #Default to include quizzes in viewing videos
        request.session['video_quiz_mode'] = "quizzes included"

    videos = Video.objects.getByCourse(course=common_page_data['course'])
    #Get index of current video
    cur_index = None  #just code safety
    for index, item in enumerate(videos):
        if item == video:
            cur_index = index
            break

    #code safety
    next_slug = None
    prev_slug = None

    if cur_index is not None:
        if cur_index > 0:
            prev_slug = videos[cur_index - 1].slug
        else:
            prev_slug = None
        if cur_index < videos.count() - 1:
            next_slug = videos[cur_index + 1].slug
        else:
            next_slug = None

    video_rec = request.user.videoactivity_set.filter(video=video)
    if video_rec:
        video_rec = video_rec[0]
    else:
        #note student field to be renamed to user, VideoActivity for all users now
        video_rec = VideoActivity(student=request.user,
                                  course=common_page_data['course'],
                                  video=video)
        video_rec.save()

    course = common_page_data['course']
    full_contentsection_list, full_index_list = get_full_contentsection_list(
        course, filter_children=True)

    if request.user.is_authenticated():
        is_logged_in = 1
    else:
        is_logged_in = 0

    key = ('video', video.id)
    l1items, l2items = get_contentgroup_data(course=course)
    downloadable_content = get_children(key, l1items, l2items)

    if video.exam:
        try:
            #exam = Exam.objects.get(course=course, is_deleted=0, slug=exam_slug)
            exam = video.exam
            display_single = exam.display_single
            invideo = exam.invideo
            metadata_dom = parseString(
                exam.xml_metadata)  #The DOM corresponding to the XML metadata
            video_questions = metadata_dom.getElementsByTagName('video')

            question_times = {}
            for video_node in video_questions:
                video_slug = video_node.getAttribute("url-identifier")
                if video_slug == "":
                    video_slug = video_node.getAttribute("url_identifier")
                if video_slug == video.slug:
                    question_children = video_node.getElementsByTagName(
                        "question")
                    times = []
                    for question in question_children:
                        time = "sec_%s" % question.getAttribute("time")
                        if time not in question_times:
                            question_times[time] = []
                        question_times[time].append(
                            question.getAttribute("id"))

            print json.dumps(question_times)

        except Exam.DoesNotExist:
            raise Http404
    else:
        sections = ContentSection.objects.getByCourse(course)
        section = sections[0]
        # create fake exam as exam template (which is what displays all videos) needs exam data to function
        # correctly (TODO: Refactor this)
        exam = Exam(
            course=course,
            slug=slug,
            title=video.title,
            description="Empty Exam",
            html_content="",
            xml_metadata="",
            due_date='',
            assessment_type="survey",
            mode="draft",
            total_score=0,
            grade_single=0,
            grace_period='',
            partial_credit_deadline='',
            late_penalty=0,
            submissions_permitted=0,
            resubmission_penalty=0,
            exam_type="survey",
            autograde=0,
            display_single=0,
            invideo=1,
            section=section,
        )
        exam.live_datetime = video.live_datetime  # needed so video shows up
        question_times = ""

    videoURL = None
    thumbnailPath = None

    if is_storage_local():
        videoURL = local_file_server_root() + "/" + str(video.file)
        thumbnailPath = local_file_server_root(
        ) + "/" + course.prefix + "/" + course.suffix + "/videos/" + str(
            video.id if video.mode == 'draft' else video.image.id) + "/jpegs/"
    elif video.url:
        videoURL = "http://www.youtube.com/embed/" + (
            video.url if video.mode == 'draft' else video.image.url
        ) + "?autoplay=0&wmode=transparent&fs=0&rel=0&modestbranding=1&showinfo=0&start=0&enablejsapi=1&disablekb=1&amp;"
        thumbnailPath = "http://" + settings.AWS_STORAGE_BUCKET_NAME + ".s3-website-us-west-2.amazonaws.com/" + course.prefix + "/" + course.suffix + "/videos/" + str(
            video.id if video.mode == 'draft' else video.image.id) + "/jpegs/"

    # change from 'videos/view.html' to 'exams/view_exam.html'
    return render_to_response('exams/view_exam.html', {
        'common_page_data': common_page_data,
        'video': video,
        'video_rec': video_rec,
        'videoURL': videoURL,
        'thumbnailPath': thumbnailPath,
        'prev_slug': prev_slug,
        'next_slug': next_slug,
        'contentsection_list': full_contentsection_list,
        'full_index_list': full_index_list,
        'is_logged_in': is_logged_in,
        'downloadable_content': downloadable_content,
        'json_pre_pop': "{}",
        'scores': "{}",
        'editable': True,
        'single_question': exam.display_single,
        'videotest': exam.invideo,
        'question_times': json.dumps(question_times),
        'allow_submit': True,
        'children': downloadable_content,
        'exam': exam
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 15
0
def view(request, course_prefix, course_suffix, slug):

    common_page_data = request.common_page_data

    try:
        #getByCourse takes care of checking for draft vs live, is_deleted and live times
        video = Video.objects.getByCourse(
            course=common_page_data['course']).get(slug=slug)
    except Video.DoesNotExist:
        raise Http404

    if not common_page_data['is_course_admin']:
        visit_log = PageVisitLog(
            course=common_page_data['ready_course'],
            user=request.user,
            page_type='video',
            object_id=str(video.id),
        )
        visit_log.save()

    if not 'video_quiz_mode' in request.session:
        #Default to include quizzes in viewing videos
        request.session['video_quiz_mode'] = "quizzes included"

    videos = Video.objects.getByCourse(course=common_page_data['course'])
    #Get index of current video
    cur_index = None  #just code safety
    for index, item in enumerate(videos):
        if item == video:
            cur_index = index
            break

    ready_section = video.section
    if ready_section and ready_section.mode == "draft":
        ready_section = ready_section.image

    #code safety
    next_slug = None
    prev_slug = None

    if cur_index is not None:
        if cur_index > 0:
            prev_slug = videos[cur_index - 1].slug
        else:
            prev_slug = None
        if cur_index < videos.count() - 1:
            next_slug = videos[cur_index + 1].slug
        else:
            next_slug = None

    video_rec = request.user.videoactivity_set.filter(video=video)
    if video_rec:
        video_rec = video_rec[0]
    else:
        #note student field to be renamed to user, VideoActivity for all users now
        video_rec = VideoActivity(student=request.user,
                                  course=common_page_data['course'],
                                  video=video)
        video_rec.save()

    course = common_page_data['course']

    key = ('video', video.id)
    l1items, l2items = get_contentgroup_data(course=course)
    downloadable_content = get_children(key, l1items, l2items)

    if video.exam:
        try:
            exam = video.exam
            video_obj = videos_in_exam_metadata(
                exam.xml_metadata, times_for_video_slug=video.slug)
            question_times = video_obj['question_times']

        except Exam.DoesNotExist:
            raise Http404
    else:
        sections = ContentSection.objects.getByCourse(course)
        section = sections[0]
        # create fake exam as exam template (which is what displays all videos) needs exam data to function
        # correctly (TODO: Refactor this)
        exam = Exam(
            course=course,
            slug=slug,
            title=video.title,
            description="Empty Exam",
            html_content="",
            xml_metadata="",
            due_date='',
            assessment_type="survey",
            mode="draft",
            total_score=0,
            grade_single=0,
            grace_period='',
            partial_credit_deadline='',
            late_penalty=0,
            submissions_permitted=0,
            resubmission_penalty=0,
            exam_type="survey",
            autograde=0,
            display_single=0,
            invideo=1,
            section=section,
        )
        exam.live_datetime = video.live_datetime  # needed so video shows up
        question_times = ""

    return render_to_response('exams/view_exam.html', {
        'common_page_data': common_page_data,
        'video': video,
        'ready_section': ready_section,
        'video_rec': video_rec,
        'prev_slug': prev_slug,
        'next_slug': next_slug,
        'downloadable_content': downloadable_content,
        'json_pre_pop': "{}",
        'scores': "{}",
        'editable': True,
        'single_question': exam.display_single,
        'videotest': exam.invideo,
        'question_times': json.dumps(question_times),
        'allow_submit': True,
        'children': downloadable_content,
        'exam': exam,
    },
                              context_instance=RequestContext(request))