Exemplo n.º 1
0
def profile_user(request, id, byid=False):

	if(not id):
		case = None
		if(not request.user.id):
			return HttpResponseRedirect('/auth/login')
		id = request.user.id
		user =  request.user
	else:
		case = _getCase(request,id)
		if byid:
			user = User.objects.get(pk=id)
		else:
			user = User.objects.get(username=id)
			id = user.id

	courses = get_courses_user_is_enrolled(user)

	return render_to_response('profile/user.html', {
		'id': id,
		'case': case,
		'badges_count': get_db().get_collection('badge').find({'id_user': id}).count(),
		'request': request,
		'courses': courses,
		'is_user': True,
		'user_view_profile': user,
		}, context_instance=RequestContext(request))
Exemplo n.º 2
0
def profile_courses(request, id, byid=False):

	if(not id):
		if(not request.user.id):
			return HttpResponseRedirect("/auth/login")
		user = request.user
		id = request.user.id
	else:
		if byid:
			user = User.objects.get(pk=id)
		else:
			user = User.objects.get(username=id)
			id = user.id

	case = _getCase(request,id)

	courses = get_courses_user_is_enrolled(user)
	courses_completed = 0
	for course in courses:
		if request.user.is_authenticated():
			course.is_enrolled = course.students.filter(id=user.id).exists()
			course.is_teacher = is_teacher_test(user, course)
			course.progress = get_course_progress_for_user(course, user)
			if course.progress == 100:
				courses_completed +=1
			course.has_passed = has_user_passed_course(user, course)
		else:
			course.is_enrolled = False
			course.is_teacher = False

	return render_to_response('profile/courses.html', {
		"id":id,
		"case":case,
		'request': request,
		'courses': courses,
		'courses_completed': courses_completed,
		"user_view_profile": user,
		"badges_count": get_db().get_collection('badge').find({"id_user": id}).count()
		}, context_instance=RequestContext(request))