summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authorCruiseDevice2020-04-11 17:45:31 +0530
committerCruiseDevice2020-04-11 17:45:31 +0530
commit2a9f81cb32acfd7a2efc18f58c4529b39ce4061b (patch)
tree4bf11c11a597101a99f09784517ca54923a63407 /yaksh/views.py
parent4802a89acef7567c6a8861daab60924fe862367f (diff)
downloadonline_test-2a9f81cb32acfd7a2efc18f58c4529b39ce4061b.tar.gz
online_test-2a9f81cb32acfd7a2efc18f58c4529b39ce4061b.tar.bz2
online_test-2a9f81cb32acfd7a2efc18f58c4529b39ce4061b.zip
Discussion forum for a course
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py45
1 files changed, 43 insertions, 2 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 9efcbe9..9350f0a 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -1,6 +1,6 @@
import os
import csv
-from django.http import HttpResponse, JsonResponse
+from django.http import HttpResponse, JsonResponse, HttpResponseRedirect
from django.contrib.auth import login, logout, authenticate
from django.shortcuts import render, get_object_or_404, redirect
from django.template import Context, Template
@@ -37,7 +37,7 @@ from yaksh.models import (
QuestionPaper, QuestionSet, Quiz, Question, StandardTestCase,
StdIOBasedTestCase, StringTestCase, TestCase, User,
get_model_class, FIXTURES_DIR_PATH, MOD_GROUP_NAME, Lesson, LessonFile,
- LearningUnit, LearningModule, CourseStatus, question_types
+ LearningUnit, LearningModule, CourseStatus, question_types, Thread, Comment
)
from yaksh.forms import (
UserRegisterForm, UserLoginForm, QuizForm, QuestionForm,
@@ -3191,3 +3191,44 @@ def download_course_progress(request, course_id):
for student in stud_details:
writer.writerow(student)
return response
+
+
+def course_forum(request, course_id):
+ user = request.user
+ course = get_object_or_404(Course, id=course_id)
+ threads = course.thread.all().order_by('modified_at')
+ if request.method == "POST":
+ title = request.POST['title']
+ description = request.POST['description']
+ if title and description:
+ new_thread = Thread.objects.create(title=title,
+ description=description,
+ creator=user, course=course)
+ new_thread.save()
+ return render(request, 'yaksh/thread_comments.html', {
+ 'thread': new_thread,
+ 'course': course,
+ 'user': user,
+ })
+ return render(request, 'yaksh/course_forum.html', {
+ 'user': user,
+ 'course': course,
+ 'threads': threads
+ })
+
+
+def thread_comments(request, course_id, uuid):
+ thread = get_object_or_404(Thread, uid=uuid)
+ comments = thread.comment.filter(active=True)
+ if request.method == "POST":
+ comment = request.POST.get('comment')
+ if comment is not None:
+ new_comment = Comment.objects.create(thread=thread,
+ body=comment,
+ user=request.user)
+ new_comment.save()
+ return HttpResponseRedirect(request.path_info)
+ return render(request, 'yaksh/thread_comments.html', {
+ 'thread': thread,
+ 'comments': comments
+ }) \ No newline at end of file