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

    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.º 4
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.º 5
0
def show(request, course_prefix, course_suffix, pset_slug):

    common_page_data = request.common_page_data
    try:
        ps = ProblemSet.objects.getByCourse(
            course=common_page_data['course']).get(slug=pset_slug)
    except ProblemSet.DoesNotExist:
        messages.add_message(
            request, messages.ERROR,
            'This Problemset is not visible in the student view at this time. Please note that students will not see this message.'
        )
        return HttpResponseRedirect(
            reverse('problemsets.views.list',
                    args=(course_prefix, course_suffix)))
    except ProblemSet.MultipleObjectsReturned:
        messages.add_message(
            request, messages.ERROR,
            'We found multiple problem sets with the same slug.  Please try to delete one.  This most likely happened due to copying content from another course.'
        )
        return HttpResponseRedirect(
            reverse('problemsets.views.list',
                    args=(course_prefix, course_suffix)))

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

    problem_activities = ProblemActivity.objects.select_related(
        'problemset_to_exercise').filter(student=request.user,
                                         problemset_to_exercise__problemSet=ps)
    psetToExs = ProblemSetToExercise.objects.getByProblemset(ps)
    activity_list = []
    for psetToEx in psetToExs:
        #attempts = problem_activities.filter(problemset_to_exercise=psetToEx).order_by('-time_created')
        #attempts = problem_activities.filter(problemset_to_exercise=psetToEx).order_by('-complete', '-attempt_number')
        attempts = problem_activities.filter(
            problemset_to_exercise__exercise__fileName=psetToEx.exercise.
            fileName).order_by('-complete', '-attempt_number')
        if attempts.exists():
            activity_list.append(attempts[0])
    return render_to_response('problemsets/problemset.html', {
        'common_page_data': common_page_data,
        'pset': ps,
        'pset_url': ps.path,
        'pset_type': ps.assessment_type,
        'pset_penalty': ps.resubmission_penalty,
        'pset_attempts_allowed': ps.submissions_permitted,
        'activity_list': activity_list,
    },
                              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

    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.º 8
0
def show(request, course_prefix, course_suffix, pset_slug):
    
    common_page_data = request.common_page_data 
    try:
        ps = ProblemSet.objects.getByCourse(course=common_page_data['course']).get(slug=pset_slug)
    except ProblemSet.DoesNotExist:
        messages.add_message(request,messages.ERROR, 'This Problemset is not visible in the student view at this time. Please note that students will not see this message.')
        return HttpResponseRedirect(reverse('problemsets.views.list', args=(course_prefix, course_suffix)))
    except ProblemSet.MultipleObjectsReturned:
        messages.add_message(request,messages.ERROR, 'We found multiple problem sets with the same slug.  Please try to delete one.  This most likely happened due to copying content from another course.')
        return HttpResponseRedirect(reverse('problemsets.views.list', args=(course_prefix, course_suffix)))


    if not common_page_data['is_course_admin']:
        visit_log = PageVisitLog(
            course = common_page_data['ready_course'],
            user = request.user,
            page_type = 'problemset',
            object_id = str(ps.id),
        )
        visit_log.save()
        
    problem_activities = ProblemActivity.objects.select_related('problemset_to_exercise').filter(student=request.user, problemset_to_exercise__problemSet=ps)
    psetToExs = ProblemSetToExercise.objects.getByProblemset(ps)
    activity_list = []
    for psetToEx in psetToExs:
        #attempts = problem_activities.filter(problemset_to_exercise=psetToEx).order_by('-time_created')
        #attempts = problem_activities.filter(problemset_to_exercise=psetToEx).order_by('-complete', '-attempt_number')
        attempts = problem_activities.filter(problemset_to_exercise__exercise__fileName=psetToEx.exercise.fileName).order_by('-complete', '-attempt_number')  
        if attempts.exists():
            activity_list.append(attempts[0])
    return render_to_response('problemsets/problemset.html',
                              {'common_page_data':common_page_data,
                               'pset': ps,
                               'pset_url':ps.path,
                               'pset_type':ps.assessment_type,
                               'pset_penalty':ps.resubmission_penalty,
                               'pset_attempts_allowed':ps.submissions_permitted,
                               'activity_list': activity_list,
                              },
                              context_instance=RequestContext(request))
Ejemplo n.º 9
0
def show(request, course_prefix, course_suffix, pset_slug):
    try:
        common_page_data = get_common_page_data(request, course_prefix, course_suffix)
    except:
        raise Http404
    try:
        ps = ProblemSet.objects.getByCourse(course=common_page_data['course']).get(slug=pset_slug)
    except:
        messages.error(request, 'This Problemset is not visible in the student view at this time. Please note that students will not see this message.')
        return HttpResponseRedirect(reverse('problemsets.views.list', args=(course_prefix, course_suffix)))

    if not common_page_data['is_course_admin']:
        visit_log = PageVisitLog(
            course = common_page_data['ready_course'],
            user = request.user,
            page_type = 'problemset',
            object_id = str(ps.id),
        )
        visit_log.save()
        
    problem_activities = ProblemActivity.objects.select_related('problemset_to_exercise').filter(student=request.user, problemset_to_exercise__problemSet=ps)
    psetToExs = ProblemSetToExercise.objects.getByProblemset(ps)
    activity_list = []
    for psetToEx in psetToExs:
        #attempts = problem_activities.filter(problemset_to_exercise=psetToEx).order_by('-time_created')
        #attempts = problem_activities.filter(problemset_to_exercise=psetToEx).order_by('-complete', '-attempt_number')
        attempts = problem_activities.filter(problemset_to_exercise__exercise__fileName=psetToEx.exercise.fileName).order_by('-complete', '-attempt_number')  
        if len(attempts) > 0:
            activity_list.append(attempts[0])
    return render(request, 'problemsets/problemset.html', {
        'common_page_data': common_page_data,
        'pset': ps,
        'pset_url': ps.path,
        'pset_type': ps.assessment_type,
        'pset_penalty': ps.resubmission_penalty,
        'pset_attempts_allowed': ps.submissions_permitted,
        'activity_list': activity_list
    })
Ejemplo n.º 10
0
def show(request, course_prefix, course_suffix, pset_slug):

    common_page_data = request.common_page_data
    try:
        ps = ProblemSet.objects.getByCourse(
            course=common_page_data['course']).get(slug=pset_slug)
    except ProblemSet.DoesNotExist:
        messages.add_message(
            request, messages.ERROR,
            'This Problemset is not visible in the student view at this time. Please note that students will not see this message.'
        )
        return HttpResponseRedirect(
            reverse('problemsets.views.listAll',
                    args=(course_prefix, course_suffix)))
    except ProblemSet.MultipleObjectsReturned:
        messages.add_message(
            request, messages.ERROR,
            'We found multiple problem sets with the same slug.  Please try to delete one.  This most likely happened due to copying content from another course.'
        )
        return HttpResponseRedirect(
            reverse('problemsets.views.listAll',
                    args=(course_prefix, course_suffix)))

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

    activity_list = []

    cursor = connection.cursor()

    #Used to test for valid data
    cursor.execute(
        "SELECT `c2g_problemset_to_exercise`.`problemSet_id`, `c2g_exercises`.`fileName`, c2g_problemset_to_exercise.number, \
                    min(case when c2g_problem_activity.complete = 1 then c2g_problem_activity.id else null end) as `first_correct_answer`, \
                    max(c2g_problem_activity.id) as `max_activity_id` \
                    FROM `c2g_problem_activity` \
                    LEFT OUTER JOIN `c2g_problemset_to_exercise` ON (`c2g_problem_activity`.`problemset_to_exercise_id` = `c2g_problemset_to_exercise`.`id`) \
                    INNER JOIN `c2g_problem_sets` ON (`c2g_problemset_to_exercise`.`problemSet_id` = `c2g_problem_sets`.`id`) \
                    INNER JOIN `c2g_exercises` ON (`c2g_problemset_to_exercise`.`exercise_id` = `c2g_exercises`.`id`) \
                    WHERE (`c2g_problemset_to_exercise`.`problemSet_id` = %s \
                    AND `c2g_problem_activity`.`student_id` = %s ) \
                    GROUP BY `c2g_problemset_to_exercise`.`problemSet_id`, `c2g_exercises`.`fileName`, c2g_problemset_to_exercise.number \
                    ORDER BY c2g_problemset_to_exercise.number",
        [ps.id, request.user.id])

    raw_activity_list = []
    for row in cursor.fetchall():
        problemset_id = row[0]
        filename = row[1]
        number = row[2]
        first_correct_answer = row[3]
        max_activity_id = row[4]

        raw_activity_item = {
            'problemset_id': problemset_id,
            'filename': filename,
            'number': number,
            'first_correct_answer': first_correct_answer,
            'max_activity_id': max_activity_id
        }
        raw_activity_list.append(raw_activity_item)

    #Find deleted files
    cursor.execute(
        "select e.fileName, p2e.problemSet_id, \
                                        count(case when p2e.is_deleted = 0 then 1 else null end) as `num_active` \
                                        from c2g_problemset_to_exercise p2e, c2g_exercises e \
                                        where p2e.exercise_id = e.id \
                                        and p2e.problemSet_id = %s \
                                        and p2e.mode = 'ready' \
                                        group by e.filename, p2e.problemSet_id \
                                        having num_active = 0", [ps.id])

    deleted_exercise_list = []
    for row in cursor.fetchall():
        filename = row[0]
        problemset_id = row[1]

        filename_item = {'filename': filename, 'problemset_id': problemset_id}
        deleted_exercise_list.append(filename_item)

    for raw_activity_item in raw_activity_list:
        problemset_id = raw_activity_item['problemset_id']
        filename = raw_activity_item['filename']
        number = raw_activity_item['number']
        first_correct_answer = raw_activity_item['first_correct_answer']
        max_activity_id = raw_activity_item['max_activity_id']

        if not filename_in_deleted_list(filename, problemset_id,
                                        deleted_exercise_list):
            if first_correct_answer == None or first_correct_answer == max_activity_id:
                activity_item = ProblemActivity.objects.get(id=max_activity_id)
            else:
                activity_item = ProblemActivity.objects.get(
                    id=first_correct_answer)

            activity_list.append((activity_item, number))

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

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

    return render_to_response('problemsets/problemset.html', {
        'common_page_data': common_page_data,
        'pset': ps,
        'pset_url': ps.path,
        'pset_type': ps.assessment_type,
        'pset_penalty': ps.resubmission_penalty,
        'pset_attempts_allowed': ps.submissions_permitted,
        'activity_list': activity_list,
        'contentsection_list': full_contentsection_list,
        'full_index_list': full_index_list,
        'is_logged_in': is_logged_in
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 11
0
def view(request, course_prefix, course_suffix):
    # Only use the ready course (for the piazza_id) since Piazza has no notion
    # of draft/live.
    course = request.common_page_data['ready_course']

    lti_params = {
        "lti_message_type": "basic-lti-launch-request",
        "lti_version": "LTI-1p0",
        "lis_person_sourcedid": "class2go:user",
        "resource_link_id": "class2go-forum",
        "resource_link_title": "Class2Go",
        "resource_link_description": "Class2Go Forum",
        "tool_consumer_instance_guid": "class2go guid",
        "tool_consumer_instance_description": "Class2Go",
        "oauth_callback": "about:blank",
        "ext_submit": "Press To Launch"
    }
    lti_params['user_id'] = request.user.id

    # TODO: once we get course policies in place, provide an override to enable using real
    # names (see #578)
    #
    # lti_params['lis_person_name_family'] = request.user.last_name
    # lti_params['lis_person_name_given'] = request.user.first_name
    # lti_params['lis_person_name_full'] = request.user.first_name + " " + request.user.last_name

    profile = request.user.get_profile()
    show_confirmation = False
    if (not profile.piazza_name):
        show_confirmation = True
        fullname = request.user.first_name + " " + request.user.last_name
        lti_params['lis_person_name_full'] = fullname.encode("utf-8")
    else:
        lti_params['lis_person_name_full'] = profile.piazza_name.encode(
            "utf-8")

    if (not profile.piazza_email):
        show_confirmation = True
        lti_params['lis_person_contact_email_primary'] = request.user.email
    else:
        lti_params['lis_person_contact_email_primary'] = profile.piazza_email

    # Piazza only supports two roles, instructor and strudent; TA's (readonly too) are instructors.
    if request.common_page_data['is_course_admin']:
        lti_params['roles'] = "Instructor"
    else:
        lti_params['roles'] = "Student"
        visit_log = PageVisitLog(
            course=course,
            user=request.user,
            page_type='forum',
        )
        visit_log.save()

    lti_params['context_id'] = course.piazza_id
    lti_params['context_label'] = request.common_page_data['course_prefix']
    lti_params['context_title'] = course.title

    # Use OAuthSimple to sign the request.
    signatures = {
        'consumer_key': PIAZZA_KEY,
        'shared_secret': PIAZZA_SECRET,
    }
    oauthsimple = OAuthSimple()
    signed_request = oauthsimple.sign({
        'path': PIAZZA_ENDPOINT,
        'action': "POST",
        'parameters': lti_params,
        'signatures': signatures,
    })

    form = PiazzaAuthForm(initial=signed_request['parameters'])

    querystring = request.META['QUERY_STRING']

    # Set common_page_data['can_switch_mode'] to false to hide mode switcher on this page.
    request.common_page_data['can_switch_mode'] = False

    return render_to_response('forums/piazza.html', {
        'common_page_data': request.common_page_data,
        'show_confirmation': show_confirmation,
        'form': form,
        'piazza_target_url': PIAZZA_ENDPOINT,
        'querystring': querystring,
    },
                              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

    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.º 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

    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.º 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 show(request, course_prefix, course_suffix, pset_slug):

    common_page_data = request.common_page_data
    try:
        ps = ProblemSet.objects.getByCourse(course=common_page_data["course"]).get(slug=pset_slug)
    except ProblemSet.DoesNotExist:
        messages.add_message(
            request,
            messages.ERROR,
            "This Problemset is not visible in the student view at this time. Please note that students will not see this message.",
        )
        return HttpResponseRedirect(reverse("problemsets.views.listAll", args=(course_prefix, course_suffix)))
    except ProblemSet.MultipleObjectsReturned:
        messages.add_message(
            request,
            messages.ERROR,
            "We found multiple problem sets with the same slug.  Please try to delete one.  This most likely happened due to copying content from another course.",
        )
        return HttpResponseRedirect(reverse("problemsets.views.listAll", args=(course_prefix, course_suffix)))

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

    activity_list = []

    cursor = connection.cursor()

    # Used to test for valid data
    cursor.execute(
        "SELECT `c2g_problemset_to_exercise`.`problemSet_id`, `c2g_exercises`.`fileName`, c2g_problemset_to_exercise.number, \
                    min(case when c2g_problem_activity.complete = 1 then c2g_problem_activity.id else null end) as `first_correct_answer`, \
                    max(c2g_problem_activity.id) as `max_activity_id` \
                    FROM `c2g_problem_activity` \
                    LEFT OUTER JOIN `c2g_problemset_to_exercise` ON (`c2g_problem_activity`.`problemset_to_exercise_id` = `c2g_problemset_to_exercise`.`id`) \
                    INNER JOIN `c2g_problem_sets` ON (`c2g_problemset_to_exercise`.`problemSet_id` = `c2g_problem_sets`.`id`) \
                    INNER JOIN `c2g_exercises` ON (`c2g_problemset_to_exercise`.`exercise_id` = `c2g_exercises`.`id`) \
                    WHERE (`c2g_problemset_to_exercise`.`problemSet_id` = %s \
                    AND `c2g_problem_activity`.`student_id` = %s ) \
                    GROUP BY `c2g_problemset_to_exercise`.`problemSet_id`, `c2g_exercises`.`fileName`, c2g_problemset_to_exercise.number \
                    ORDER BY c2g_problemset_to_exercise.number",
        [ps.id, request.user.id],
    )

    raw_activity_list = []
    for row in cursor.fetchall():
        problemset_id = row[0]
        filename = row[1]
        number = row[2]
        first_correct_answer = row[3]
        max_activity_id = row[4]

        raw_activity_item = {
            "problemset_id": problemset_id,
            "filename": filename,
            "number": number,
            "first_correct_answer": first_correct_answer,
            "max_activity_id": max_activity_id,
        }
        raw_activity_list.append(raw_activity_item)

    # Find deleted files
    cursor.execute(
        "select e.fileName, p2e.problemSet_id, \
                                        count(case when p2e.is_deleted = 0 then 1 else null end) as `num_active` \
                                        from c2g_problemset_to_exercise p2e, c2g_exercises e \
                                        where p2e.exercise_id = e.id \
                                        and p2e.problemSet_id = %s \
                                        and p2e.mode = 'ready' \
                                        group by e.filename, p2e.problemSet_id \
                                        having num_active = 0",
        [ps.id],
    )

    deleted_exercise_list = []
    for row in cursor.fetchall():
        filename = row[0]
        problemset_id = row[1]

        filename_item = {"filename": filename, "problemset_id": problemset_id}
        deleted_exercise_list.append(filename_item)

    for raw_activity_item in raw_activity_list:
        problemset_id = raw_activity_item["problemset_id"]
        filename = raw_activity_item["filename"]
        number = raw_activity_item["number"]
        first_correct_answer = raw_activity_item["first_correct_answer"]
        max_activity_id = raw_activity_item["max_activity_id"]

        if not filename_in_deleted_list(filename, problemset_id, deleted_exercise_list):
            if first_correct_answer == None or first_correct_answer == max_activity_id:
                activity_item = ProblemActivity.objects.get(id=max_activity_id)
            else:
                activity_item = ProblemActivity.objects.get(id=first_correct_answer)

            activity_list.append((activity_item, number))

    course = common_page_data["course"]
    contentsection_list = ContentSection.objects.getByCourse(course=course)
    video_list = 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(
        "problemsets/problemset.html",
        {
            "common_page_data": common_page_data,
            "pset": ps,
            "pset_url": ps.path,
            "pset_type": ps.assessment_type,
            "pset_penalty": ps.resubmission_penalty,
            "pset_attempts_allowed": ps.submissions_permitted,
            "activity_list": activity_list,
            "contentsection_list": full_contentsection_list,
            "full_index_list": full_index_list,
            "is_logged_in": is_logged_in,
        },
        context_instance=RequestContext(request),
    )
Ejemplo n.º 16
0
def show(request, course_prefix, course_suffix, pset_slug):
    
    def filename_in_deleted_list(filename, problem_set_id, deleted_exercise_list):
        """Used by course_materials templates for filtering"""
        for item in deleted_exercise_list:
            if item['filename'] == filename and item['problemset_id'] == problem_set_id:
                return True
        return False

    common_page_data = request.common_page_data 
    try:
        ps = ProblemSet.objects.getByCourse(course=common_page_data['course']).get(slug=pset_slug)
    except ProblemSet.DoesNotExist:
        messages.add_message(request,messages.ERROR, 'This Problemset is not visible in the student view at this time. Please note that students will not see this message.')
        return HttpResponseRedirect(reverse('problemsets.views.listAll', args=(course_prefix, course_suffix)))
    except ProblemSet.MultipleObjectsReturned:
        messages.add_message(request,messages.ERROR, 'We found multiple problem sets with the same slug.  Please try to delete one.  This most likely happened due to copying content from another course.')
        return HttpResponseRedirect(reverse('problemsets.views.listAll', args=(course_prefix, course_suffix)))

    if not common_page_data['is_course_admin']:
        visit_log = PageVisitLog(
            course = common_page_data['ready_course'],
            user = request.user,
            page_type = 'problemset',
            object_id = str(ps.id),
        )
        visit_log.save()
        
    activity_list = []
    
    cursor = connection.cursor()
    
    #Used to test for valid data
    cursor.execute("SELECT `c2g_problemset_to_exercise`.`problemSet_id`, `c2g_exercises`.`fileName`, c2g_problemset_to_exercise.number, \
                    min(case when c2g_problem_activity.complete = 1 then c2g_problem_activity.id else null end) as `first_correct_answer`, \
                    max(c2g_problem_activity.id) as `max_activity_id` \
                    FROM `c2g_problem_activity` \
                    LEFT OUTER JOIN `c2g_problemset_to_exercise` ON (`c2g_problem_activity`.`problemset_to_exercise_id` = `c2g_problemset_to_exercise`.`id`) \
                    INNER JOIN `c2g_problem_sets` ON (`c2g_problemset_to_exercise`.`problemSet_id` = `c2g_problem_sets`.`id`) \
                    INNER JOIN `c2g_exercises` ON (`c2g_problemset_to_exercise`.`exercise_id` = `c2g_exercises`.`id`) \
                    WHERE (`c2g_problemset_to_exercise`.`problemSet_id` = %s \
                    AND `c2g_problem_activity`.`student_id` = %s ) \
                    GROUP BY `c2g_problemset_to_exercise`.`problemSet_id`, `c2g_exercises`.`fileName`, c2g_problemset_to_exercise.number \
                    ORDER BY c2g_problemset_to_exercise.number", [ps.id, request.user.id])
    
    raw_activity_list = []
    for row in cursor.fetchall():
        problemset_id = row[0]
        filename = row[1]
        number = row[2]
        first_correct_answer = row[3]
        max_activity_id = row[4]                                
                                
        raw_activity_item = {'problemset_id' : problemset_id,
                             'filename' : filename,
                             'number' : number,
                             'first_correct_answer' : first_correct_answer,
                             'max_activity_id' : max_activity_id
                            }
        raw_activity_list.append(raw_activity_item)
            
    #Find deleted files
    cursor.execute("select e.fileName, p2e.problemSet_id, \
                                        count(case when p2e.is_deleted = 0 then 1 else null end) as `num_active` \
                                        from c2g_problemset_to_exercise p2e, c2g_exercises e \
                                        where p2e.exercise_id = e.id \
                                        and p2e.problemSet_id = %s \
                                        and p2e.mode = 'ready' \
                                        group by e.filename, p2e.problemSet_id \
                                        having num_active = 0", [ps.id])

    deleted_exercise_list = []
    for row in cursor.fetchall():
        filename = row[0]
        problemset_id = row[1]
        
        filename_item = {'filename' : filename,
                         'problemset_id' : problemset_id
                        }
        deleted_exercise_list.append(filename_item)                        
    
    for raw_activity_item in raw_activity_list:
        problemset_id = raw_activity_item['problemset_id']
        filename = raw_activity_item['filename']
        number = raw_activity_item['number']
        first_correct_answer = raw_activity_item['first_correct_answer']
        max_activity_id = raw_activity_item['max_activity_id']        
        
        if not filename_in_deleted_list(  filename, problemset_id, deleted_exercise_list):
            if first_correct_answer == None or first_correct_answer == max_activity_id:
                activity_item = ProblemActivity.objects.get(id=max_activity_id)
            else:
                activity_item = ProblemActivity.objects.get(id=first_correct_answer)
                
            activity_list.append((activity_item, number))

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

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

    return render_to_response('problemsets/problemset.html',
                              {'common_page_data':common_page_data,
                               'pset': ps,
                               'pset_url':ps.path,
                               'pset_type':ps.assessment_type,
                               'pset_penalty':ps.resubmission_penalty,
                               'pset_attempts_allowed':ps.submissions_permitted,
                               'activity_list': activity_list,
                               'contentsection_list': full_contentsection_list, 
                               'full_index_list': full_index_list,
                               'is_logged_in': is_logged_in
                              },
                              context_instance=RequestContext(request))
Ejemplo n.º 17
0
def view(request, course_prefix, course_suffix):
    # Only use the ready course (for the piazza_id) since Piazza has no notion
    # of draft/live.
    course = request.common_page_data['ready_course']

    lti_params = {
        "lti_message_type": "basic-lti-launch-request",
        "lti_version": "LTI-1p0",
        "resource_link_id": "class2go-forum",
    }
    lti_params['user_id'] = request.user.id

    # TODO: once we get course policies in place, provide an override to enable using real
    # names (see #578)
    # 
    # lti_params['lis_person_name_family'] = request.user.last_name
    # lti_params['lis_person_name_given'] = request.user.first_name
    # lti_params['lis_person_name_full'] = request.user.first_name + " " + request.user.last_name
            
    profile = request.user.get_profile()
    show_confirmation = False
    if (not profile.piazza_name):
        show_confirmation = True
        lti_params['lis_person_name_full'] = request.user.first_name + " " + request.user.last_name
    else:
        lti_params['lis_person_name_full'] = profile.piazza_name
        
    if (not profile.piazza_email):
        show_confirmation = True
        lti_params['lis_person_contact_email_primary'] = request.user.email
    else:
        lti_params['lis_person_contact_email_primary'] = profile.piazza_email
            

    # Piazza only supports two roles, instructor and strudent; TA's (readonly too) are instructors. 
    if request.common_page_data['is_course_admin']:
        lti_params['roles'] = "Instructor"
    else:
        lti_params['roles'] = "Student"
        visit_log = PageVisitLog(
            course = course,
            user = request.user,
            page_type= 'forum',
        )
        visit_log.save()

    lti_params['context_id'] = course.piazza_id
    lti_params['context_label'] = request.common_page_data['course_prefix']
    lti_params['context_title'] = course.title

    # Use OAuthSimple to sign the request. 
    signatures = {
        'consumer_key': settings.PIAZZA_KEY,
        'shared_secret': settings.PIAZZA_SECRET,
    }
    oauthsimple = OAuthSimple()
    signed_request = oauthsimple.sign({
        'path': settings.PIAZZA_ENDPOINT,
        'action': "POST",
        'parameters': lti_params, 
        'signatures': signatures,
    })

    form = PiazzaAuthForm(initial=signed_request['parameters'])

    querystring = request.META['QUERY_STRING']

    # Set common_page_data['can_switch_mode'] to false to hide mode switcher on this page.
    request.common_page_data['can_switch_mode'] = False
    
    return render_to_response('forums/piazza.html', {
            'common_page_data': request.common_page_data,
            'show_confirmation': show_confirmation,
            'form': form,
            'piazza_target_url': settings.PIAZZA_ENDPOINT,
            'querystring': querystring,
        }, context_instance=RequestContext(request))
Ejemplo n.º 18
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.º 19
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.º 20
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.º 21
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))