Exemple #1
0
def main(request, course_prefix, course_suffix, slug):
    try:
        common_page_data = get_common_page_data(request, course_prefix, course_suffix)
        page = AdditionalPage.objects.get(course=common_page_data['course'], slug=slug)
    except:
        raise Http404
    
    if not common_page_data['is_course_admin']:
        visit_log = PageVisitLog(
            course = common_page_data['ready_course'],
            user = request.user,
            page_type = 'additional_page',
            object_id = str(page.id),
        )
        visit_log.save()
        
    if common_page_data['is_course_admin'] and common_page_data['course_mode'] == 'draft' and common_page_data['view_mode'] == 'edit':
        template = 'additional_pages/edit.html'
    else:
        template = 'additional_pages/view.html'
        
    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)
    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(template,
                              {'common_page_data': common_page_data,
                               'page': page,
                               'contentsection_list': full_contentsection_list, 
                               'full_index_list': full_index_list,
                               'is_logged_in': is_logged_in},
                               context_instance=RequestContext(request))
Exemple #2
0
def main(request, course_prefix, course_suffix, slug):
    try:
        common_page_data = get_common_page_data(request, course_prefix, course_suffix)
        page = AdditionalPage.objects.get(course=common_page_data["course"], slug=slug)
    except:
        raise Http404

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

    if (
        common_page_data["is_course_admin"]
        and common_page_data["course_mode"] == "draft"
        and common_page_data["view_mode"] == "edit"
    ):
        template = "additional_pages/edit.html"
    else:
        template = "additional_pages/view.html"

    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(
        template,
        {
            "common_page_data": common_page_data,
            "page": page,
            "contentsection_list": full_contentsection_list,
            "full_index_list": full_index_list,
            "is_logged_in": is_logged_in,
        },
        context_instance=RequestContext(request),
    )
Exemple #3
0
def main(request, course_prefix, course_suffix, slug):
    try:
        common_page_data = get_common_page_data(request, course_prefix, course_suffix)
        page = AdditionalPage.objects.get(course=common_page_data['course'], slug=slug)
    except:
        raise Http404
    
    if not common_page_data['is_course_admin']:
        visit_log = PageVisitLog(
            course = common_page_data['ready_course'],
            user = request.user,
            page_type = 'additional_page',
            object_id = str(page.id),
        )
        visit_log.save()
        
    if common_page_data['is_course_admin'] and common_page_data['course_mode'] == 'draft' and common_page_data['view_mode'] == 'edit':
        template = 'additional_pages/edit.html'
    else:
        template = 'additional_pages/view.html'
        
    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(template,
                              {'common_page_data': common_page_data,
                               'page': page,
                               'contentsection_list': full_contentsection_list, 
                               'full_index_list': full_index_list,
                               'is_logged_in': is_logged_in},
                               context_instance=RequestContext(request))
Exemple #4
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))
Exemple #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
    
    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))
Exemple #6
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))
Exemple #7
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))
Exemple #8
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),
    )
Exemple #9
0
def main(request, course_prefix, course_suffix, slug):
    try:
        common_page_data = get_common_page_data(request, course_prefix, course_suffix)
        page = AdditionalPage.objects.get(course=common_page_data["course"], slug=slug)
    except:
        raise Http404

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

    contentgroup_info = None  # Empty for view mode
    sections = ContentSection.objects.getByCourse(course=common_page_data["course"])

    if common_page_data["is_course_admin"] and common_page_data["course_mode"] == "draft":
        template = "additional_pages/edit.html"

        groupable_page = page
        if page.mode != "ready":
            groupable_page = page.image
        contentgroup_info = ContentGroup.groupinfo_by_id("additional_page", groupable_page.id)
        # Oh, so it turns out you can't dereference variables starting with _
        # from Django templates
        if contentgroup_info:
            contentgroup_info["PARENT"] = contentgroup_info["__parent"]
            contentgroup_info["PARENT_TAG"] = contentgroup_info["__parent_tag"]
    else:
        template = "additional_pages/view.html"

    course = common_page_data["course"]

    course_instructors = CourseInstructor.objects.getByCourse(course=common_page_data["course"])
    instructor_list = []

    for ci in course_instructors:
        instructor_list.append(ci.instructor)

    full_contentsection_list, full_index_list = get_full_contentsection_list(course)

    try:
        video = Video.objects.getByCourse(course=common_page_data["course"]).get(slug="intro")
    except Video.DoesNotExist:
        video = None

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

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

    return render_to_response(
        template,
        {
            "common_page_data": common_page_data,
            "page": page,
            "contentsection_list": full_contentsection_list,
            "full_index_list": full_index_list,
            "instructor_list": instructor_list,
            "course": course,
            "is_logged_in": is_logged_in,
            "intro_video": video,
            "ready_section": ready_section,
            "contentgroup_info": contentgroup_info,
            "sections": sections,
        },
        context_instance=RequestContext(request),
    )
Exemple #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()

    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))
Exemple #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 = ""

    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))
Exemple #12
0
def main(request, course_prefix, course_suffix, slug):
    try:
        common_page_data = get_common_page_data(request, course_prefix,
                                                course_suffix)
        page = AdditionalPage.objects.get(course=common_page_data['course'],
                                          slug=slug)
    except:
        raise Http404

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

    contentgroup_info = None  # Empty for view mode
    sections = ContentSection.objects.getByCourse(
        course=common_page_data['course'])

    if common_page_data['is_course_admin'] and common_page_data[
            'course_mode'] == 'draft':
        template = 'additional_pages/edit.html'

        groupable_page = page
        if page.mode != 'ready':
            groupable_page = page.image
        contentgroup_info = ContentGroup.groupinfo_by_id(
            'additional_page', groupable_page.id)
        # Oh, so it turns out you can't dereference variables starting with _
        # from Django templates
        if contentgroup_info:
            contentgroup_info['PARENT'] = contentgroup_info['__parent']
            contentgroup_info['PARENT_TAG'] = contentgroup_info['__parent_tag']
    else:
        template = 'additional_pages/view.html'

    course = common_page_data['course']

    course_instructors = CourseInstructor.objects.getByCourse(
        course=common_page_data['course'])
    instructor_list = []

    for ci in course_instructors:
        instructor_list.append(ci.instructor)

    full_contentsection_list, full_index_list = get_full_contentsection_list(
        course)

    try:
        video = Video.objects.getByCourse(
            course=common_page_data['course']).get(slug='intro')
    except Video.DoesNotExist:
        video = None

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

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

    return render_to_response(template, {
        'common_page_data': common_page_data,
        'page': page,
        'contentsection_list': full_contentsection_list,
        'full_index_list': full_index_list,
        'instructor_list': instructor_list,
        'course': course,
        'is_logged_in': is_logged_in,
        'intro_video': video,
        'ready_section': ready_section,
        'contentgroup_info': contentgroup_info,
        'sections': sections,
    },
                              context_instance=RequestContext(request))
Exemple #13
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),
    )