Exemplo n.º 1
0
def main(request):
	""" main question list """
	view_page(request.user, UserActivityLog.QALIST)
	questions = Question.objects.all().order_by("-created")
	paginator = Paginator(questions, 10)
	activity_logs = UserActivityLog.objects.all().filter(page_viewed = UserActivityLog.QA)	

	try: page = int(request.GET.get("page", '1'))
	except ValueError: page = 1

	try:
		questions = paginator.page(page)
	except (InvalidPage, EmptyPage):
		questions = paginator.page(paginator.num_pages)
	votes = {}
	views = {}
	for question in questions:
		if (len(question.body) > 500):
			question.body = question.body[:500] + "..."
		#get votes for question
		answers = Answer.objects.all().filter(question = question)
		num_votes = 0
		for a in answers:
			num_votes += a.score
		votes[question.pk] = num_votes
		views[question.pk] = activity_logs.filter(id_viewed = question.pk).count()
	context_dict = {'votes': votes, 'views': views, 'questions':questions, 'user':UserProfile.objects.get(user=request.user)}
	return render(request, 'qa/list.html', context_dict)
Exemplo n.º 2
0
def getVideo(request, vidNumber):
	view_page(request.user, UserActivityLog.VIDEO, vidNumber)	

	video = Video.objects.get(id=vidNumber)
	viewed_count = UserActivityLog.objects.filter(id_viewed=vidNumber).count()

	if request.method == 'POST':
		form = VideoCommentForm(request.POST)
		if form.is_valid():
			newComment = VideoComment()
			newComment.poster = request.user
			newComment.post = video
			newComment.body = form.cleaned_data['body']
			newComment.save()
		form = VideoCommentForm()
	else:
		form = VideoCommentForm()
		
	args = {
		'video': video,
		'comments': VideoComment.objects.filter(post=video),
		'myform': form,
		'viewCount': viewed_count,
	}
        return render(request, 'main/video.html', args)
Exemplo n.º 3
0
def getVideos(request, topicName):
	view_page(request.user, UserActivityLog.VIDEOS)	

	params = {
		'videos': Video.objects.filter(topic=Topic.objects.get(name=topicName)),
		'topic': topicName,
	}
        return render(request, 'main/videos.html', params)
Exemplo n.º 4
0
def home(request):
	view_page(request.user, UserActivityLog.HOME)
	params = {
		'videos': Video.objects.all()[:5],
		'blogs': Post.objects.all().order_by('-created')[:5],
		'questions': qaQuestion.objects.all()[:5]
	}
	return render(request, 'main/home.html', params)
Exemplo n.º 5
0
def topicList(request):
	view_page(request.user, UserActivityLog.TOPICS)	

	allTopics = Topic.objects.all().order_by('grade').order_by('order_value')
	topicsWithVideos = []
	for topic in allTopics:
		if len(Video.objects.filter(topic=topic)) > 0:
			topicsWithVideos.append(topic)
	return render(request, 'main/topics.html', {'topics': topicsWithVideos})
Exemplo n.º 6
0
def post(request, pk):
    """ Single post with comments and a comment form """
    view_page(request.user, UserActivityLog.BLOG, pk)

    post = Post.objects.get(pk=int(pk))
    comments = Comment.objects.filter(post=post)
    context_dic = {'post':post, 'comments':comments, 'form':CommentForm(), 'user':request.user}
    context_dic.update(csrf(request))
    return render(request, "blog/post.html", context_dic)
Exemplo n.º 7
0
def post(request, pk):
    """
    view for an individual post
    pk: id of the post to be displayed
    url: mathfeud.org/blog/pk/
    """
    view_page(request.user, UserActivityLog.BLOG, pk)

    post = Post.objects.get(pk=int(pk))
    d = {'post':post, 'user':request.user}
    return render(request, 'blog/post.html', d)
Exemplo n.º 8
0
def question(request, pk):
	view_page(request.user, UserActivityLog.QA, pk)

	question = Question.objects.get(pk=int(pk))
	answers = Answer.objects.filter(question=question)
	d = {'question':question, 'user':UserProfile.objects.get(user=request.user), 'answers': answers, 'form': AnswerForm()}
	if not question.solved and request.user == question.poster.user:
		d['allowSelect'] = True
	else:
		d['allowSelect'] = False
	return render(request, "qa/question.html", d)
Exemplo n.º 9
0
def getVideoQuiz(request, vidNumber):
	""" Renders a view.
	Ouput Parameters:
		@questionDict: A Dictionary of Questions to sets of Answers
		that belong to that question
	"""
	view_page(request.user, UserActivityLog.QUIZ, vidNumber)	

	currentUser = UserProfile.objects.get(user=request.user)
	video = Video.objects.get(id=vidNumber)
	questions = Question.objects.filter(video_ref=video)
	questionDict = {}
	for question in questions:
		hasBeenAnswered = False
		isCorrect = False
		responsesFromUser = QuestionResponse.objects.filter(user=currentUser)
		if responsesFromUser:
			responsesForThisQuestion = responsesFromUser.filter(question=question)
			if len(responsesForThisQuestion) == 1:
				hasBeenAnswered = True
				isCorrect = responsesForThisQuestion[0].correct
			elif len(responsesForThisQuestion) > 1:
				# Shouldn't ever reach here. This means this user
				# has answered this question multiple times
				hasBeenAnswered = True
				isCorrect = False

		answers_for_question = []
		answer_query_set = Answer.objects.filter(question_ref=question)
		for answer in answer_query_set:
			answers_for_question.append(answer)
		shuffle(answers_for_question)
		questionDict[question] = [answers_for_question, hasBeenAnswered, isCorrect]
		#questionDict[question] = answers_for_question
	args = {
		'questionDict': questionDict,
		'questionCount': len(questionDict),
		'vidNumber': vidNumber,
		'vidTopic': video.topic,
	}
	return render(request, 'quiz/questions.html', args)
Exemplo n.º 10
0
def main(request):
    """ 
    Main listing of the blog
    url: mathfeud.org/blog/
    """
    view_page(request.user, UserActivityLog.BLOG_LIST)	
    current_group = UserProfile.objects.get(user=request.user).group
    posts = Post.objects.all().filter(group=current_group).order_by("-created")
    paginator = Paginator(posts, 10)

    try: page = int(request.GET.get("page", '1'))
    except ValueError: page = 1

    try:
        posts = paginator.page(page)
    except (InvalidPage, EmptyPage):
        posts = paginator.page(paginator.num_pages)
    for post in posts:
	if (len(post.body) > 500):
		post.body = post.body[:500] + "..."
    context_dict = {'posts':posts, 'user':request.user}
    return render(request, 'blog/list.html', context_dict)