From 2a9f81cb32acfd7a2efc18f58c4529b39ce4061b Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Sat, 11 Apr 2020 17:45:31 +0530 Subject: Discussion forum for a course --- yaksh/views.py | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'yaksh/views.py') 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 -- cgit From 0e6c7d589114450d5cd1bc581ee1692c235f1a73 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 13 Apr 2020 16:45:42 +0530 Subject: Add feature for uploading images --- yaksh/views.py | 55 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 22 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 9350f0a..afa21df 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -44,7 +44,7 @@ from yaksh.forms import ( QuestionFilterForm, CourseForm, ProfileForm, UploadFileForm, FileForm, QuestionPaperForm, LessonForm, LessonFileForm, LearningModuleForm, ExerciseForm, TestcaseForm, - SearchFilterForm + SearchFilterForm, ThreadForm, CommentForm ) from yaksh.settings import SERVER_POOL_PORT, SERVER_HOST_NAME from .settings import URL_ROOT @@ -3193,42 +3193,53 @@ def download_course_progress(request, course_id): return response +@login_required +@email_verified 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') + 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) + form = ThreadForm(request.POST, request.FILES) + if form.is_valid(): + new_thread = form.save(commit=False) + new_thread.creator = user + new_thread.course = course new_thread.save() - return render(request, 'yaksh/thread_comments.html', { - 'thread': new_thread, - 'course': course, - 'user': user, - }) + return redirect('yaksh:thread_comments', + course_id=course.id, uuid=new_thread.uid) + else: + form = ThreadForm() return render(request, 'yaksh/course_forum.html', { 'user': user, 'course': course, - 'threads': threads + 'threads': threads, + 'form': form }) +@login_required +@email_verified def thread_comments(request, course_id, uuid): thread = get_object_or_404(Thread, uid=uuid) comments = thread.comment.filter(active=True) + form = CommentForm() 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) + form = CommentForm(request.POST, request.FILES) + if form.is_valid(): + new_comment = form.save(commit=False) + new_comment.creator=request.user + new_comment.thread_field=thread new_comment.save() - return HttpResponseRedirect(request.path_info) + return redirect(request.path_info) return render(request, 'yaksh/thread_comments.html', { 'thread': thread, - 'comments': comments - }) \ No newline at end of file + 'comments': comments, + 'form': form + }) + + +@login_required +@email_verified +def delete_thread(request, course_id, uuid): + thread = get_object_or_404(Thread, uid=uuid) -- cgit From 2f9331717075b34534f2745706f57a98f7dce20d Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 13 Apr 2020 17:27:49 +0530 Subject: Add feature to hide thread or comments --- yaksh/views.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index afa21df..0567f3d 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -3198,7 +3198,7 @@ def download_course_progress(request, course_id): 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') + threads = course.thread.filter(active=True).order_by('-modified_at') if request.method == "POST": form = ThreadForm(request.POST, request.FILES) if form.is_valid(): @@ -3214,13 +3214,15 @@ def course_forum(request, course_id): 'user': user, 'course': course, 'threads': threads, - 'form': form + 'form': form, + 'user': user }) @login_required @email_verified def thread_comments(request, course_id, uuid): + user = request.user thread = get_object_or_404(Thread, uid=uuid) comments = thread.comment.filter(active=True) form = CommentForm() @@ -3235,11 +3237,24 @@ def thread_comments(request, course_id, uuid): return render(request, 'yaksh/thread_comments.html', { 'thread': thread, 'comments': comments, - 'form': form + 'form': form, + 'user': user }) @login_required @email_verified -def delete_thread(request, course_id, uuid): +def hide_thread(request, course_id, uuid): thread = get_object_or_404(Thread, uid=uuid) + thread.comment.active = False + thread.active = False + thread.save() + return redirect('yaksh:course_forum', course_id) + + +def hide_comment(request, course_id, uuid): + comment = get_object_or_404(Comment, uid=uuid) + thread_uid = comment.thread_field.uid + comment.active = False + comment.save() + return redirect('yaksh:thread_comments', course_id, thread_uid) -- cgit From 508e0e78bb0bd3e8ebbad81e948f13de5c01b20f Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Tue, 14 Apr 2020 20:13:52 +0530 Subject: Change model name Thread to Post to avoid conflicts - Thread class from threading conflicts with the forum Thread model. - Tests for models and views. - PEP8 fix. --- yaksh/views.py | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 0567f3d..197891c 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -37,14 +37,14 @@ 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, Thread, Comment + LearningUnit, LearningModule, CourseStatus, question_types, Post, Comment ) from yaksh.forms import ( UserRegisterForm, UserLoginForm, QuizForm, QuestionForm, QuestionFilterForm, CourseForm, ProfileForm, UploadFileForm, FileForm, QuestionPaperForm, LessonForm, LessonFileForm, LearningModuleForm, ExerciseForm, TestcaseForm, - SearchFilterForm, ThreadForm, CommentForm + SearchFilterForm, PostForm, CommentForm ) from yaksh.settings import SERVER_POOL_PORT, SERVER_HOST_NAME from .settings import URL_ROOT @@ -3198,22 +3198,22 @@ def download_course_progress(request, course_id): def course_forum(request, course_id): user = request.user course = get_object_or_404(Course, id=course_id) - threads = course.thread.filter(active=True).order_by('-modified_at') + posts = course.post.filter(active=True).order_by('-modified_at') if request.method == "POST": - form = ThreadForm(request.POST, request.FILES) + form = PostForm(request.POST, request.FILES) if form.is_valid(): - new_thread = form.save(commit=False) - new_thread.creator = user - new_thread.course = course - new_thread.save() - return redirect('yaksh:thread_comments', - course_id=course.id, uuid=new_thread.uid) + new_post = form.save(commit=False) + new_post.creator = user + new_post.course = course + new_post.save() + return redirect('yaksh:post_comments', + course_id=course.id, uuid=new_post.uid) else: - form = ThreadForm() + form = PostForm() return render(request, 'yaksh/course_forum.html', { 'user': user, 'course': course, - 'threads': threads, + 'posts': posts, 'form': form, 'user': user }) @@ -3221,21 +3221,21 @@ def course_forum(request, course_id): @login_required @email_verified -def thread_comments(request, course_id, uuid): +def post_comments(request, course_id, uuid): user = request.user - thread = get_object_or_404(Thread, uid=uuid) - comments = thread.comment.filter(active=True) + post = get_object_or_404(Post, uid=uuid) + comments = post.comment.filter(active=True) form = CommentForm() if request.method == "POST": form = CommentForm(request.POST, request.FILES) if form.is_valid(): new_comment = form.save(commit=False) - new_comment.creator=request.user - new_comment.thread_field=thread + new_comment.creator = request.user + new_comment.post_field = post new_comment.save() return redirect(request.path_info) - return render(request, 'yaksh/thread_comments.html', { - 'thread': thread, + return render(request, 'yaksh/post_comments.html', { + 'post': post, 'comments': comments, 'form': form, 'user': user @@ -3244,17 +3244,17 @@ def thread_comments(request, course_id, uuid): @login_required @email_verified -def hide_thread(request, course_id, uuid): - thread = get_object_or_404(Thread, uid=uuid) - thread.comment.active = False - thread.active = False - thread.save() +def hide_post(request, course_id, uuid): + post = get_object_or_404(Post, uid=uuid) + post.comment.active = False + post.active = False + post.save() return redirect('yaksh:course_forum', course_id) def hide_comment(request, course_id, uuid): comment = get_object_or_404(Comment, uid=uuid) - thread_uid = comment.thread_field.uid + post_uid = comment.post_field.uid comment.active = False comment.save() - return redirect('yaksh:thread_comments', course_id, thread_uid) + return redirect('yaksh:post_comments', course_id, post_uid) -- cgit From 169228186d8c9ad880ee33c5190e49203d2c5243 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Wed, 15 Apr 2020 21:19:09 +0530 Subject: Resolve comments - Fix "'image' attribute has no file associated with it" issue. - Don't allow users who are not part of a course to see the discussion forum of that course. - Add Discussion forum link in moderator interface under course_details page. - Remove custom css for post and comments in Discussion forum. Use bootstrap 'img-fluid' class instead. 'img-fluid' fills the height and width of the card. - Use instance.uid instead of just instance in get_image_dir. --- yaksh/views.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 197891c..c154d4e 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -3198,6 +3198,9 @@ def download_course_progress(request, course_id): def course_forum(request, course_id): user = request.user course = get_object_or_404(Course, id=course_id) + if (not course.is_creator(user) and not course.is_teacher(user) + and not course.is_student(user)): + raise Http404('You are not enrolled in {0} course'.format(course.name)) posts = course.post.filter(active=True).order_by('-modified_at') if request.method == "POST": form = PostForm(request.POST, request.FILES) @@ -3225,6 +3228,10 @@ def post_comments(request, course_id, uuid): user = request.user post = get_object_or_404(Post, uid=uuid) comments = post.comment.filter(active=True) + course = get_object_or_404(Course, id=course_id) + if (not course.is_creator(user) and not course.is_teacher(user) + and not course.is_student(user)): + raise Http404('You are not enrolled in {0} course'.format(course.name)) form = CommentForm() if request.method == "POST": form = CommentForm(request.POST, request.FILES) @@ -3245,6 +3252,10 @@ def post_comments(request, course_id, uuid): @login_required @email_verified def hide_post(request, course_id, uuid): + course = get_object_or_404(Course, id=course_id) + if (not course.is_creator(user) and not course.is_teacher(user) + and not course.is_student(user)): + raise Http404('You are not enrolled in {0} course'.format(course.name)) post = get_object_or_404(Post, uid=uuid) post.comment.active = False post.active = False @@ -3253,6 +3264,10 @@ def hide_post(request, course_id, uuid): def hide_comment(request, course_id, uuid): + course = get_object_or_404(Course, id=course_id) + if (not course.is_creator(user) and not course.is_teacher(user) + and not course.is_student(user)): + raise Http404('You are not enrolled in {0} course'.format(course.name)) comment = get_object_or_404(Comment, uid=uuid) post_uid = comment.post_field.uid comment.active = False -- cgit From eb9f6cb240268735e08ebc2a6d26d88c7e5097f7 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Wed, 15 Apr 2020 22:15:53 +0530 Subject: Improve UI slightly --- yaksh/views.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index c154d4e..01d5f48 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -3252,6 +3252,7 @@ def post_comments(request, course_id, uuid): @login_required @email_verified def hide_post(request, course_id, uuid): + user = request.user course = get_object_or_404(Course, id=course_id) if (not course.is_creator(user) and not course.is_teacher(user) and not course.is_student(user)): @@ -3263,7 +3264,10 @@ def hide_post(request, course_id, uuid): return redirect('yaksh:course_forum', course_id) +@login_required +@email_verified def hide_comment(request, course_id, uuid): + user = request.user course = get_object_or_404(Course, id=course_id) if (not course.is_creator(user) and not course.is_teacher(user) and not course.is_student(user)): -- cgit From d60c6b528e893266da10f7e83b5f2e7ef4d4b6dc Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Thu, 16 Apr 2020 18:45:11 +0530 Subject: PEP8 fix --- yaksh/views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 01d5f48..afb07f4 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -3199,7 +3199,7 @@ def course_forum(request, course_id): user = request.user course = get_object_or_404(Course, id=course_id) if (not course.is_creator(user) and not course.is_teacher(user) - and not course.is_student(user)): + and not course.is_student(user)): raise Http404('You are not enrolled in {0} course'.format(course.name)) posts = course.post.filter(active=True).order_by('-modified_at') if request.method == "POST": @@ -3230,7 +3230,7 @@ def post_comments(request, course_id, uuid): comments = post.comment.filter(active=True) course = get_object_or_404(Course, id=course_id) if (not course.is_creator(user) and not course.is_teacher(user) - and not course.is_student(user)): + and not course.is_student(user)): raise Http404('You are not enrolled in {0} course'.format(course.name)) form = CommentForm() if request.method == "POST": @@ -3255,7 +3255,7 @@ def hide_post(request, course_id, uuid): user = request.user course = get_object_or_404(Course, id=course_id) if (not course.is_creator(user) and not course.is_teacher(user) - and not course.is_student(user)): + and not course.is_student(user)): raise Http404('You are not enrolled in {0} course'.format(course.name)) post = get_object_or_404(Post, uid=uuid) post.comment.active = False @@ -3270,7 +3270,7 @@ def hide_comment(request, course_id, uuid): user = request.user course = get_object_or_404(Course, id=course_id) if (not course.is_creator(user) and not course.is_teacher(user) - and not course.is_student(user)): + and not course.is_student(user)): raise Http404('You are not enrolled in {0} course'.format(course.name)) comment = get_object_or_404(Comment, uid=uuid) post_uid = comment.post_field.uid -- cgit From 66939d00dab998c7c0e649938527271551f22980 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Sat, 25 Apr 2020 19:21:04 +0530 Subject: Resolve comments, fix tests, add pagination --- yaksh/views.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index afb07f4..cd53d55 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -3197,11 +3197,20 @@ def download_course_progress(request, course_id): @email_verified def course_forum(request, course_id): user = request.user + base_template = 'user.html' + moderator = False + if is_moderator(user): + base_template = 'manage.html' + moderator = True course = get_object_or_404(Course, id=course_id) if (not course.is_creator(user) and not course.is_teacher(user) and not course.is_student(user)): raise Http404('You are not enrolled in {0} course'.format(course.name)) + sort = request.GET.get('desc') posts = course.post.filter(active=True).order_by('-modified_at') + paginator = Paginator(posts, 10) + page = request.GET.get('page') + posts = paginator.get_page(page) if request.method == "POST": form = PostForm(request.POST, request.FILES) if form.is_valid(): @@ -3216,7 +3225,10 @@ def course_forum(request, course_id): return render(request, 'yaksh/course_forum.html', { 'user': user, 'course': course, + 'base_template': base_template, 'posts': posts, + 'moderator': moderator, + 'objects': posts, 'form': form, 'user': user }) @@ -3226,6 +3238,9 @@ def course_forum(request, course_id): @email_verified def post_comments(request, course_id, uuid): user = request.user + base_template = 'user.html' + if is_moderator(user): + base_template = 'manage.html' post = get_object_or_404(Post, uid=uuid) comments = post.comment.filter(active=True) course = get_object_or_404(Course, id=course_id) @@ -3244,6 +3259,7 @@ def post_comments(request, course_id, uuid): return render(request, 'yaksh/post_comments.html', { 'post': post, 'comments': comments, + 'base_template': base_template, 'form': form, 'user': user }) @@ -3254,8 +3270,7 @@ def post_comments(request, course_id, uuid): def hide_post(request, course_id, uuid): user = request.user course = get_object_or_404(Course, id=course_id) - if (not course.is_creator(user) and not course.is_teacher(user) - and not course.is_student(user)): + if (not course.is_creator(user) and not course.is_teacher(user)): raise Http404('You are not enrolled in {0} course'.format(course.name)) post = get_object_or_404(Post, uid=uuid) post.comment.active = False @@ -3269,8 +3284,7 @@ def hide_post(request, course_id, uuid): def hide_comment(request, course_id, uuid): user = request.user course = get_object_or_404(Course, id=course_id) - if (not course.is_creator(user) and not course.is_teacher(user) - and not course.is_student(user)): + if (not course.is_creator(user) and not course.is_teacher(user)): raise Http404('You are not enrolled in {0} course'.format(course.name)) comment = get_object_or_404(Comment, uid=uuid) post_uid = comment.post_field.uid -- cgit From e261686554ad339449ba9fec6c2391faaefc0eff Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Sun, 26 Apr 2020 22:21:41 +0530 Subject: Add search bar in forum to search posts --- yaksh/views.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index cd53d55..be33a5e 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -3206,8 +3206,11 @@ def course_forum(request, course_id): if (not course.is_creator(user) and not course.is_teacher(user) and not course.is_student(user)): raise Http404('You are not enrolled in {0} course'.format(course.name)) - sort = request.GET.get('desc') - posts = course.post.filter(active=True).order_by('-modified_at') + if 'search' in request.GET: + search_term = request.GET['search'] + posts = course.post.filter(active=True, title__icontains=search_term) + else: + posts = course.post.filter(active=True).order_by('-modified_at') paginator = Paginator(posts, 10) page = request.GET.get('page') posts = paginator.get_page(page) -- cgit