def program(request,uri): if request.user.is_authenticated(): s = SimpleSequencing() # First, the requested_activity exists?? # Gets the Learning Activity object from uri requested_activity = _get_ula(request, s) if not requested_activity: return HttpResponseNotFound('<h1>Activity not found</h1>') # Gets the root of the User Learning Activity root = UserLearningActivity.objects.filter(learning_activity = requested_activity.learning_activity.get_root() ,user = request.user )[0] if request.method == 'GET': # Exits last activity, and sets requested activity as current # if choice_exit consider complete _set_current(request,requested_activity, root, s, objective_status=None, progress_status=None) if request.method == 'POST' and 'nav_event' in request.POST: # We are going to exit activity, get objective measure objective_measure = float(request.POST['objective_measure']) next_uri = None if request.POST['nav_event'] == 'next': # Go TO NEXT ACTIVITY next_uri = s.get_next(root) pool_writting(next_uri,request.user) elif request.POST['nav_event'] == 'prev': # Go TO PREV ACTIVITY next_uri = s.get_prev(root) print next_uri if next_uri is None: #No more activities ? return HttpResponseRedirect( root.learning_activity.uri) else: s.exit( requested_activity, progress_status = 'complete', objective_status = 'satisfied', objective_measure = objective_measure) next_activity = UserLearningActivity.objects.filter(learning_activity__uri = next_uri ,user = request.user )[0] return HttpResponseRedirect(next_activity.learning_activity.uri) # Gets the current navegation tree as HTML nav = s.get_nav(root) navegation_tree = s.nav_to_html(nav) return render_to_response('activitytree/program.html', {'program_quiz':activities[request.path], 'activity_uri':request.path, 'navegation': navegation_tree }, context_instance=RequestContext(request)) else: return HttpResponseRedirect('/login/?next=%s' % request.path)
def activity(request,uri): if request.user.is_authenticated(): s = SimpleSequencing() # First, the requested_activity exists?? # Gets the Learning Activity object from uri #print "hasta aqui" requested_activity = _get_ula(request, s) if not requested_activity: return HttpResponseNotFound('<h1>Activity not found</h1>') # Gets the root of the User Learning Activity root = UserLearningActivity.objects.filter(learning_activity = requested_activity.learning_activity.get_root() ,user = request.user )[0] #Aqui mando la actividad actual a redis para que la escuche el script que manejara la actividad de el muestreo de kinect if request.method == 'GET': # Exits last activity, and sets requested activity as current # if choice_exit consider complete _set_current(request,requested_activity, root, s, objective_status=None, progress_status=None) if request.method == 'POST' and 'nav_event' in request.POST: if requested_activity.learning_activity.is_container: progress_status = None objective_status = None else: ### ### What if status in POST?? ### progress_status = 'complete' objective_status = 'satisfied' if request.POST['nav_event'] == 'next': # Go TO NEXT ACTIVITY next_uri = s.get_next(root) #az.set(request.user,next_uri) az.set("user",request.user) az.set("activity",next_uri) # if next_uri=="/activity/POO" or next_uri==None: actividad="" else: actividad=next_uri print actividad,request.user pool_writting(actividad,request.user) elif request.POST['nav_event'] == 'prev': # Go TO PREV ACTIVITY next_uri = s.get_prev(root) if next_uri is None: #No more activities ? return HttpResponseRedirect( root.learning_activity.uri) else: s.exit( requested_activity, progress_status = progress_status, objective_status = objective_status) next_activity = UserLearningActivity.objects.filter(learning_activity__uri = next_uri ,user = request.user )[0] return HttpResponseRedirect(next_activity.learning_activity.uri) # Gets the current navegation tree as HTML nav = s.get_nav(root) navegation_tree = s.nav_to_html(nav) #### #### #### print requested_activity.learning_activity.uri content = activities[requested_activity.learning_activity.uri] return render_to_response('activitytree/'+ (requested_activity.learning_activity.uri).split('/')[1]+'.html', {'navegation': navegation_tree, 'uri':requested_activity.learning_activity.uri, 'content':content}, context_instance=RequestContext(request)) ##### ##### ##### else: return HttpResponseRedirect('/login/?next=%s' % request.path)
def test(request, uri, objective_status = None): if request.user.is_authenticated(): s = SimpleSequencing() # First, the requested_activity exists?? # Gets the Learning Activity object from uri requested_activity = _get_ula(request, s) if not requested_activity: return HttpResponseNotFound('<h1>Activity not found</h1>') # Gets the root of the User Learning Activity root = UserLearningActivity.objects.filter(learning_activity = requested_activity.learning_activity.get_root() ,user = request.user )[0] feedback = None if request.method == 'GET': # Exits last activity, and sets requested activity as current # if choice_exit consider complete _set_current(request,requested_activity, root, s, objective_status=None, progress_status=None) elif request.method == 'POST': if 'check' in request.POST: feedback = _check_quiz(request.POST, activities[requested_activity.learning_activity.uri]) # Exits the current Learning Activity objective_measure = feedback['total_correct'] if objective_measure >= activities[requested_activity.learning_activity.uri]['satisfied_at_least']: objective_status='satisfied' else: objective_status='notSatisfied' print requested_activity.learning_activity.uri, objective_measure,objective_status s.update(requested_activity, progress_status = None, objective_status = objective_status, objective_measure = objective_measure) elif 'nav_event' in request.POST: next_uri = None if request.POST['nav_event'] == 'next' : # Go TO NEXT ACTIVITY next_uri = s.get_next(root) progress_status = 'complete' pool_writting(next_uri,request.user) elif request.POST['nav_event'] == 'prev': # Go TO PREV ACTIVITY next_uri = s.get_prev(root) pool_writting(next_uri) if next_uri is None: #No more activities ? return HttpResponseRedirect( root.learning_activity.uri) else: next_activity = UserLearningActivity.objects.filter(learning_activity__uri = next_uri ,user = request.user )[0] return HttpResponseRedirect(next_activity.learning_activity.uri) # Gets the current navegation tree as HTML nav = s.get_nav(root) navegation_tree = s.nav_to_html(nav) content = activities[requested_activity.learning_activity.uri] if feedback: for q in content['questions']: if q['id'] in feedback: q['feedback'] = feedback[q['id']] if q['interaction'] in ['choiceInteraction','simpleChoice']: q['feedback_options'] = zip(q['options'], feedback[q['id']]['user_answer'], feedback[q['id']]['checked']) return render_to_response('activitytree/'+(requested_activity.learning_activity.uri).split('/')[1]+'.html', {'navegation': navegation_tree, 'uri':requested_activity.learning_activity.uri, 'content':content, 'feedback':feedback}, context_instance=RequestContext(request)) else: return HttpResponseRedirect('/login/?next=%s' % request.path)
def path_activity(request, path_id, uri): learning_activity = None try: learning_activity = LearningActivity.objects.get(pk=path_id) except ObjectDoesNotExist: return HttpResponseNotFound("<h1>Learning Activity not found</h1>") if request.user.is_authenticated(): root = None s = SimpleSequencing() requested_activity = None if request.method == "GET": try: requested_activity = UserLearningActivity.objects.get(learning_activity__id=path_id, user=request.user) except (ObjectDoesNotExist, IndexError) as e: requested_activity = None # The requested_activity was NOT FOUND if not requested_activity: # The requested_activity was not found # Maybe a # 'start' REQUEST? # if 'nav' in request.GET and request.GET['nav'] == 'start': if learning_activity and learning_activity.root is None: s.assignActivityTree(request.user, learning_activity) requested_activity = UserLearningActivity.objects.get( learning_activity__id=path_id, user=request.user ) _set_current(request, requested_activity, requested_activity, s) return HttpResponseRedirect("/%s%s" % (path_id, uri)) # If is not a root learning activity then sorry, not found else: return HttpResponseNotFound("<h1>Activity not found</h1>") # Else NOT FOUND # else: # return HttpResponseNotFound('<h1>Activity not found</h1>') # We have a valid requested_activity, lets handle OTHER NAVIGATION REQUEST # Get root of activity tree root = UserLearningActivity.objects.filter( learning_activity=requested_activity.learning_activity.get_root(), user=request.user )[0] # 'continue' REQUEST? if requested_activity.is_root() and "nav" in request.GET and request.GET["nav"] == "continue": current_activity = s.get_current(requested_activity) if current_activity: requested_activity = current_activity return HttpResponseRedirect( "/%s%s" % (requested_activity.learning_activity.id, requested_activity.learning_activity.uri) ) else: _set_current(request, requested_activity, root, s, objective_status=None, progress_status=None) # Else is a # 'choice' REQUEST else: _set_current(request, requested_activity, root, s) if request.method == "POST" and "nav_event" in request.POST: # Get root of activity tree root = None try: root = UserLearningActivity.objects.get(learning_activity__id=path_id, user=request.user) except (ObjectDoesNotExist, IndexError) as e: root = None if not root or not root.is_root(): return HttpResponseNotFound("<h1>Activity not found</h1>") current_activity = s.get_current(root) if current_activity.learning_activity.choice_exit: objective_status = "satisfied" progress_status = "complete" else: progress_status = None objective_status = None # 'next' REQUEST if request.POST["nav_event"] == "next": # Go TO NEXT ACTIVITY s.exit(current_activity, progress_status=progress_status, objective_status=objective_status) next_uri = s.get_next(root, current_activity) # 'prev' REQUEST elif request.POST["nav_event"] == "prev": # Go TO PREV ACTIVITY s.exit(current_activity, progress_status=progress_status, objective_status=objective_status) next_uri = s.get_prev(root, current_activity) # No more activities ? if next_uri is None: return HttpResponseRedirect("/%s%s" % (root.learning_activity.id, root.learning_activity.uri)) else: next_activity = UserLearningActivity.objects.get(learning_activity__id=next_uri, user=request.user) return HttpResponseRedirect( "/%s%s" % (next_activity.learning_activity.id, next_activity.learning_activity.uri) ) _XML = get_nav(root) # Escape for javascript XML = ET.tostring(_XML, "utf-8").replace('"', r"\"") breadcrumbs = s.get_current_path(requested_activity) rating_totals = LearningActivityRating.objects.filter( learning_activity__uri=requested_activity.learning_activity.uri ).aggregate(Count("rating"), Avg("rating")) activity_content = Activity.get(requested_activity.learning_activity.uri) if activity_content and "content" in activity_content: content = activity_content["content"] else: content = "" update_pool(requested_activity.learning_activity.uri) if (requested_activity.learning_activity.uri).split("/")[2] == "video": return render_to_response( "activitytree/video.html", { "XML_NAV": XML, "uri": requested_activity.learning_activity.uri, "uri_id": requested_activity.learning_activity.id, "video": activity_content, "breadcrumbs": breadcrumbs, "root": requested_activity.learning_activity.get_root().uri, "root_id": "/%s" % requested_activity.learning_activity.get_root().id, "rating_totals": rating_totals, }, context_instance=RequestContext(request), ) elif requested_activity.learning_activity.is_container: return render_to_response( "activitytree/container.html", { "XML_NAV": XML, "children": requested_activity.get_children(), "uri": requested_activity.learning_activity.uri, "uri_id": "/%s" % requested_activity.learning_activity.id, "content": content, "root": requested_activity.learning_activity.get_root().uri, "root_id": "/%s" % requested_activity.learning_activity.get_root().id, "breadcrumbs": breadcrumbs, }, context_instance=RequestContext(request), ) else: return render_to_response( "activitytree/activity.html", { "XML_NAV": XML, "uri": requested_activity.learning_activity.uri, "uri_id": "/%s" % requested_activity.learning_activity.id, "content": content, "root": requested_activity.learning_activity.get_root().uri, "root_id": "/%s" % requested_activity.learning_activity.get_root().id, "breadcrumbs": breadcrumbs, "rating_totals": rating_totals, }, context_instance=RequestContext(request), ) else: return HttpResponseRedirect("/login/?next=%s" % request.path)