Пример #1
0
def vid_action(request):
    print 'in vid action'
    action_type = request.POST['action']
    learner_id = request.POST['learner_id']
    learner = get_object_or_404(Learner, pk=learner_id)
    video = get_object_or_404(Video, pk=request.POST['video_id'])

    #TODO: DUMMY VIDEO
    learner = get_object_or_404(Learner, pk=1)
    subgoal = get_object_or_404(Subgoal, pk=1)

    if request.is_ajax():
        action = Action(video=video,
                        learner=learner,
                        subgoal=subgoal,
                        action_type=action_type,
                        stage=0)
        try:
            action.session_id = get_session_key(request.session.session_key)
        except (NameError, AttributeError):
            pass
        action.save()
        results = {'success': True, 'action': action_type}
    else:
        raise Http404
    json = simplejson.dumps(results)
    print results
    return HttpResponse(json, content_type='application/json')
Пример #2
0
def subgoal_undelete(request):
    video_id = request.POST['video_id']
    subgoal_id = request.POST['subgoal_id']
    learner_id = request.POST['learner_id']
    video = get_object_or_404(Video, pk=video_id)
    subgoal = get_object_or_404(Subgoal, pk=subgoal_id)
    learner = get_object_or_404(Learner, pk=learner_id)
    if request.is_ajax():
        # not actually removing the subgoal, but simply marking it as deleted
        subgoal.state = "undeleted"
        subgoal.save()

        action = Action(video=video,
                        learner=learner,
                        subgoal=subgoal,
                        action_type="subgoal_undelete",
                        stage=request.POST['stage'])
        try:
            action.session_id = get_session_key(request.session.session_key)
        except (NameError, AttributeError):
            pass
        action.save()
        results = {'success': True, 'subgoal_id': subgoal.id}
    else:
        raise Http404
    json = simplejson.dumps(results)
    return HttpResponse(json, content_type='application/json')
Пример #3
0
def subgoal_brief_click(request):
    #create action named "brief_clicked"

    accepted = request.POST['agree']

    #PLACEHOLDER TODO
    video = get_object_or_404(Video, pk=1)
    learner = get_object_or_404(Learner, pk=1)
    subgoal = get_object_or_404(Subgoal, pk=1)
    action_type = 'brief_clicked'
    stage = 1

    #action for clicking the briefing
    action = Action(video=video,
                    learner=learner,
                    subgoal=subgoal,
                    action_type=action_type,
                    stage=stage)
    try:
        action.session_id = get_session_key(request.session.session_key)
    except (NameError, AttributeError):
        pass
    action.save()

    #action for agreeing or not
    action_agree = Action(video=video,
                          learner=learner,
                          subgoal=subgoal,
                          action_type=accepted,
                          stage=stage)
    try:
        action_agree.session_id = get_session_key(request.session.session_key)
    except (NameError, AttributeError):
        pass
    action_agree.save()

    results = {'success': True}
    json = simplejson.dumps(results)
    return HttpResponse(json, content_type='application/json')
Пример #4
0
def subgoal_vote(request):
    video_id = request.POST['video_id']

    learner_id = request.POST['learner_id']
    video = get_object_or_404(Video, pk=video_id)

    learner = get_object_or_404(Learner, pk=learner_id)
    if request.is_ajax():
        # print request.POST['votes']
        votes = simplejson.loads(request.POST['votes'])
        print votes
        # request.POST['votes'].getlist
        # for (subgoal_id, vote_type) in enumerate(votes):
        for subgoal_id in votes:
            vote_type = votes[subgoal_id]
            print subgoal_id, vote_type
            subgoal = get_object_or_404(Subgoal, pk=subgoal_id)
            new_vote_val = getattr(subgoal, vote_type) + 1
            setattr(subgoal, vote_type, new_vote_val)
            # subgoal[vote_type] = subgoal[vote_type] + 1
            # subgoal.votes = subgoal.votes + 1
            subgoal.state = "voted"
            subgoal.save()

            action_type = "subgoal_" + vote_type
            #action = Action(video=video, learner=learner, subgoal=subgoal, action_type="subgoal_vote", stage=request.POST['stage'])
            action = Action(video=video,
                            learner=learner,
                            subgoal=subgoal,
                            action_type=action_type,
                            stage=request.POST['stage'])
            try:
                action.session_id = get_session_key(
                    request.session.session_key)
            except (NameError, AttributeError):
                pass
            action.save()
            results = {'success': True, 'subgoal_id': subgoal.id}
    else:
        raise Http404
    json = simplejson.dumps(results)
    return HttpResponse(json, content_type='application/json')
Пример #5
0
def subgoal_instr_click(request):
    #create action named "instr_clicked"

    #PLACEHOLDER TODO
    video = get_object_or_404(Video, pk=1)
    learner = get_object_or_404(Learner, pk=1)
    subgoal = get_object_or_404(Subgoal, pk=1)
    action_type = 'instr_clicked'
    stage = 1

    action = Action(video=video,
                    learner=learner,
                    subgoal=subgoal,
                    action_type=action_type,
                    stage=stage)
    try:
        action.session_id = get_session_key(request.session.session_key)
    except (NameError, AttributeError):
        pass
    action.save()

    results = {'success': True}
    json = simplejson.dumps(results)
    return HttpResponse(json, content_type='application/json')
Пример #6
0
def subgoal_create(request):
    video_id = request.POST['video_id']
    learner_id = request.POST['learner_id']
    video = get_object_or_404(Video, pk=video_id)
    learner = get_object_or_404(Learner, pk=learner_id)
    if request.is_ajax():
        subgoal = Subgoal(video=video,
                          time=int(request.POST['time']),
                          label=request.POST['label'],
                          learner=learner,
                          state="created",
                          stage_added=int(request.POST['stage']),
                          upvotes_s2=0,
                          downvotes_s2=0,
                          upvotes_s3=0,
                          downvotes_s3=0)
        # only add an upvote when replacing ones from a diected question. Ignore manual addition from the Wiki panel.
        if 'is_vote' in request.POST:
            if request.POST['stage'] == 2:
                subgoal.upvotes_s2 = 1
            elif request.POST['stage'] == 3:
                subgoal.upvotes_s3 = 1

        try:
            sesh = get_session_key(request.session.session_key)
        except (NameError, AttributeError):
            pass

        agree = Action.objects.filter(session_id=sesh,
                                      action_type='agree').count()
        no_agree = Action.objects.filter(session_id=sesh,
                                         action_type='no_agree').count()
        if (agree > 0):
            print 'SAVED!!!!'
            subgoal.save()
            action = Action(video=video,
                            learner=learner,
                            subgoal=subgoal,
                            action_type="subgoal_create",
                            stage=request.POST['stage'])
            try:
                action.session_id = get_session_key(
                    request.session.session_key)
            except (NameError, AttributeError):
                pass
            action.save()
            results = {
                'success': True,
                'subgoal_id': subgoal.id,
                'subgoal': model_to_json([subgoal])
            }
        else:
            print 'NOT SAVED!!!!!'
            results = {
                'success': True,
                'subgoal_id': subgoal.id,
                'subgoal': model_to_json([subgoal])
            }
    else:
        raise Http404
    json = simplejson.dumps(results)
    return HttpResponse(json, content_type='application/json')