diff --git a/yaksh/templates/yaksh/post_comments.html b/yaksh/templates/yaksh/post_comments.html
new file mode 100644
index 0000000..89f0762
--- /dev/null
+++ b/yaksh/templates/yaksh/post_comments.html
@@ -0,0 +1,62 @@
+{% extends "user.html" %}
+
+{% block title %}
+ {{post.title}}
+{% endblock title %}
+
+{% block content %}
+
+
Back to Posts
+
+
+
+
{{post.description}}
+
+
+
+
+
+
+
+ {% if comments %}
+
+ {% for comment in comments %}
+
+ {% if comment.image %}
+
+
+
+ {% endif %}
+
{{comment.description}}
+
+ by: {{comment.creator.username}} . {{comment.created_at}}
+ {% if user.profile.is_moderator %}Delete{% endif %}
+
+
+
+ {% endfor %}
+ {% else %}
+ No comments on this post.
+ {% endif %}
+
+
+
+
+{% endblock content %}
\ No newline at end of file
diff --git a/yaksh/templates/yaksh/thread_comments.html b/yaksh/templates/yaksh/thread_comments.html
deleted file mode 100644
index f614b7a..0000000
--- a/yaksh/templates/yaksh/thread_comments.html
+++ /dev/null
@@ -1,59 +0,0 @@
-{% extends "user.html" %}
-
-{% block title %}
- {{thread.title}}
-{% endblock title %}
-
-{% block content %}
-
-
Back to Threads
-
-
-
-
{{thread.description}}
-
-
-
-
- {% if comments %}
-
- {% for comment in comments %}
-
- {% if comment.image %}
-
-
-
- {% endif %}
-
{{comment.description}}
-
- by: {{comment.creator.username}} . {{comment.created_at}}
- {% if user.profile.is_moderator %}Delete{% endif %}
-
-
-
- {% endfor %}
- {% else %}
- No comments on this thread.
- {% endif %}
-
-
-
-
-{% endblock content %}
\ No newline at end of file
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index a60a1d6..a57a61b 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -5,7 +5,7 @@ from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\
QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\
StdIOBasedTestCase, FileUpload, McqTestCase, AssignmentUpload,\
LearningModule, LearningUnit, Lesson, LessonFile, CourseStatus, \
- create_group, legend_display_types
+ create_group, legend_display_types, Post, Comment
from yaksh.code_server import (
ServerPool, get_result as get_result_from_code_server
)
@@ -191,7 +191,6 @@ class LearningModuleTestCases(unittest.TestCase):
self.prereq_course.students.add(self.student)
self.prereq_course.save()
-
def tearDown(self):
# Remove unit from course status completed units
self.course_status.completed_units.remove(self.learning_unit_one)
@@ -495,7 +494,7 @@ class QuestionTestCases(unittest.TestCase):
self.assertEqual(self.question1.snippet, 'def myfunc()')
tag_list = []
for tag in self.question1.tags.all():
- tag_list.append(tag.name)
+ tag_list.append(tag.name)
for tag in tag_list:
self.assertIn(tag, ['python', 'function'])
@@ -2239,3 +2238,85 @@ class FileUploadTestCases(unittest.TestCase):
if os.path.isfile(self.file_upload.file.path):
os.remove(self.file_upload.file.path)
self.file_upload.delete()
+
+
+class PostModelTestCases(unittest.TestCase):
+ def setUp(self):
+ self.user1 = User.objects.create(
+ username='bart',
+ password='bart',
+ email='bart@test.com'
+ )
+ Profile.objects.create(
+ user=self.user1,
+ roll_number=1,
+ institute='IIT',
+ department='Chemical',
+ position='Student'
+ )
+
+ self.user2 = User.objects.create(
+ username='dart',
+ password='dart',
+ email='dart@test.com'
+ )
+ Profile.objects.create(
+ user=self.user2,
+ roll_number=2,
+ institute='IIT',
+ department='Chemical',
+ position='Student'
+ )
+
+ self.user3 = User.objects.create(
+ username='user3',
+ password='user3',
+ email='user3@test.com'
+ )
+ Profile.objects.create(
+ user=self.user3,
+ roll_number=3,
+ is_moderator=True,
+ department='Chemical',
+ position='Teacher'
+ )
+
+ self.course = Course.objects.create(
+ name='Python Course',
+ enrollment='Enroll Request',
+ creator=self.user3
+ )
+ self.post1 = Post.objects.create(
+ title='Post 1',
+ course=self.course,
+ creator=self.user1,
+ description='Post 1 description'
+ )
+ self.comment1 = Comment.objects.create(
+ post_field=self.post1,
+ creator=self.user2,
+ description='Post 1 comment 1'
+ )
+ self.comment2 = Comment.objects.create(
+ post_field=self.post1,
+ creator=self.user3,
+ description='Post 1 user3 comment 2'
+ )
+
+ def test_get_last_comment(self):
+ last_comment = self.post1.get_last_comment()
+ self.assertEquals(last_comment.description, 'Post 1 user3 comment 2')
+
+ def test_get_comments_count(self):
+ count = self.post1.get_comments_count()
+ self.assertEquals(count, 2)
+
+ def test__str__(self):
+ self.assertEquals(str(self.post1.title), self.post1.title)
+
+ def tearDown(self):
+ self.user1.delete()
+ self.user2.delete()
+ self.user3.delete()
+ self.course.delete()
+ self.post1.delete()
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 8f811c5..5cbedc6 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -27,7 +27,7 @@ from yaksh.models import (
User, Profile, Question, Quiz, QuestionPaper, AnswerPaper, Answer, Course,
AssignmentUpload, McqTestCase, IntegerTestCase, StringTestCase,
FloatTestCase, FIXTURES_DIR_PATH, LearningModule, LearningUnit, Lesson,
- LessonFile, CourseStatus, dict_to_yaml
+ LessonFile, CourseStatus, dict_to_yaml, Post, Comment
)
from yaksh.views import add_as_moderator
from yaksh.decorators import user_has_profile
@@ -1123,11 +1123,10 @@ class TestAddQuiz(TestCase):
If not logged in redirect to login page
"""
response = self.client.get(
- reverse('yaksh:add_quiz',
- kwargs={'course_id': self.course.id,
- 'module_id': self.module.id}),
- follow=True
- )
+ reverse('yaksh:add_quiz', kwargs={
+ 'course_id': self.course.id,
+ 'module_id': self.module.id
+ }), follow=True)
redirect_destination = (
'/exam/login/?next=/exam/manage/addquiz/{0}/{1}/'.format(
self.course.id, self.module.id
@@ -1144,11 +1143,10 @@ class TestAddQuiz(TestCase):
password=self.student_plaintext_pass
)
response = self.client.get(
- reverse('yaksh:add_quiz',
- kwargs={'course_id': self.course.id,
- 'module_id': self.module.id}),
- follow=True
- )
+ reverse('yaksh:add_quiz', kwargs={
+ 'course_id': self.course.id,
+ 'module_id': self.module.id
+ }), follow=True)
self.assertEqual(response.status_code, 404)
def test_add_quiz_get(self):
@@ -1160,11 +1158,10 @@ class TestAddQuiz(TestCase):
password=self.user_plaintext_pass
)
response = self.client.get(
- reverse('yaksh:add_quiz',
- kwargs={'course_id': self.course.id,
- 'module_id': self.module.id}
- )
- )
+ reverse('yaksh:add_quiz', kwargs={
+ 'course_id': self.course.id,
+ 'module_id': self.module.id
+ }))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'yaksh/add_quiz.html')
self.assertIsNotNone(response.context['form'])
@@ -1179,10 +1176,11 @@ class TestAddQuiz(TestCase):
)
tzone = pytz.timezone('UTC')
response = self.client.post(
- reverse('yaksh:edit_quiz',
- kwargs={'course_id': self.course.id,
- 'module_id': self.module.id,
- 'quiz_id': self.quiz.id}),
+ reverse('yaksh:edit_quiz', kwargs={
+ 'course_id': self.course.id,
+ 'module_id': self.module.id,
+ 'quiz_id': self.quiz.id
+ }),
data={
'start_date_time': '2016-01-10 09:00:15',
'end_date_time': '2016-01-15 09:00:15',
@@ -1316,10 +1314,11 @@ class TestAddQuiz(TestCase):
password=self.user_plaintext_pass
)
response = self.client.post(
- reverse('yaksh:edit_exercise',
- kwargs={'course_id': self.course.id,
- 'module_id': self.module.id,
- 'quiz_id': self.exercise.id}),
+ reverse('yaksh:edit_exercise', kwargs={
+ 'course_id': self.course.id,
+ 'module_id': self.module.id,
+ 'quiz_id': self.exercise.id
+ }),
data={
'description': 'updated demo exercise',
'active': True
@@ -1344,9 +1343,10 @@ class TestAddQuiz(TestCase):
password=self.user_plaintext_pass
)
response = self.client.post(
- reverse('yaksh:add_exercise',
- kwargs={'course_id': self.course.id,
- 'module_id': self.module.id}),
+ reverse('yaksh:add_exercise', kwargs={
+ 'course_id': self.course.id,
+ 'module_id': self.module.id
+ }),
data={
'description': "Demo Exercise",
'active': True
@@ -2281,7 +2281,7 @@ class TestSearchFilters(TestCase):
# Create moderator group
self.mod_group = Group.objects.create(name="moderator")
- #Create user1 with profile
+ # Create user1 with profile
self.user1_plaintext_pass = "demo1"
self.user1 = User.objects.create_user(
username='demo_user1',
@@ -4359,7 +4359,9 @@ class TestDownloadCsv(TestCase):
kwargs={'course_id': self.course.id}),
follow=True
)
- file_name = "{0}.csv".format(self.course.name.lower().replace(" ", "_"))
+ file_name = "{0}.csv".format(
+ self.course.name.lower().replace(" ", "_")
+ )
self.assertEqual(response.status_code, 200)
self.assertEqual(response.get('Content-Disposition'),
'attachment; filename="{0}"'.format(file_name))
@@ -6286,3 +6288,226 @@ class TestLessons(TestCase):
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()['data'], '
test description
')
+
+
+class TestPost(TestCase):
+ def setUp(self):
+ self.client = Client()
+ self.mod_group = Group.objects.create(name='moderator')
+
+ self.student_plaintext_pass = 'student'
+ self.student = User.objects.create_user(
+ username='student',
+ password=self.student_plaintext_pass,
+ first_name='first_name',
+ last_name='last_name',
+ email='student@test.com'
+ )
+
+ Profile.objects.create(
+ user=self.student,
+ roll_number=10,
+ institute='IIT',
+ department='Chemical',
+ position='student',
+ timezone='UTC'
+ )
+
+ # moderator
+ self.user_plaintext_pass = 'demo'
+ self.user = User.objects.create_user(
+ username='demo_user',
+ password=self.user_plaintext_pass,
+ first_name='first_name',
+ last_name='last_name',
+ email='demo@test.com'
+ )
+
+ Profile.objects.create(
+ user=self.user,
+ roll_number=10,
+ institute='IIT',
+ department='Chemical',
+ position='Moderator',
+ timezone='UTC'
+ )
+
+ self.course = Course.objects.create(
+ name="Python Course",
+ enrollment="Enroll Request", creator=self.user
+ )
+
+ def test_view_course_forum_denies_anonymous_user(self):
+ url = '/exam/login/?next=/exam/forum/' + str(self.course.id) + '/'
+ response = self.client.get(reverse('yaksh:course_forum', kwargs={
+ 'course_id': self.course.id
+ }), follow=True)
+ self.assertEqual(response.status_code, 200)
+ redirection_url = url
+ self.assertRedirects(response, redirection_url)
+
+ def test_view_course_forum(self):
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+ response = self.client.get(reverse('yaksh:course_forum', kwargs={
+ 'course_id': self.course.id
+ }), follow=True)
+ self.assertEquals(response.status_code, 200)
+ self.assertTemplateUsed(response, 'yaksh/course_forum.html')
+
+ def test_create_post(self):
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+ response = self.client.post(reverse('yaksh:course_forum', kwargs={
+ 'course_id': self.course.id
+ }), {
+ 'title': 'post 1',
+ 'description': 'post 1 description',
+ 'course': self.course,
+ 'creator': self.student
+ })
+ self.assertEquals(response.status_code, 302)
+ url = response.url.split('/')
+ uid = url[5]
+ test_against = Post.objects.get(uid=uid)
+ self.assertEqual(test_against.title, 'post 1')
+
+ def test_open_created_post_denies_anonymous_user(self):
+ post = Post.objects.create(
+ title='post 1',
+ description='post 1 description',
+ course=self.course,
+ creator=self.student
+ )
+ response = self.client.get(reverse('yaksh:post_comments', kwargs={
+ 'course_id': self.course.id,
+ 'uuid': post.uid
+ }), follow=True)
+ self.assertEqual(response.status_code, 200)
+ redirection_url = '/exam/login/?next=/exam/forum/' \
+ + str(self.course.id) + '/post/' + str(post.uid) + '/'
+ self.assertRedirects(response, redirection_url)
+
+ def test_hide_post(self):
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+ post = Post.objects.create(
+ title='post 1',
+ description='post 1 description',
+ course=self.course,
+ creator=self.student
+ )
+ response = self.client.get(reverse('yaksh:hide_post', kwargs={
+ 'course_id': self.course.id,
+ 'uuid': post.uid
+ }), follow=True)
+ self.assertEqual(response.status_code, 200)
+
+ def tearDown(self):
+ self.client.logout()
+ self.user.delete()
+ self.course.delete()
+ self.mod_group.delete()
+
+
+class TestPostComment(TestCase):
+ def setUp(self):
+ self.client = Client()
+ self.mod_group = Group.objects.create(name='moderator')
+
+ self.student_plaintext_pass = 'student'
+ self.student = User.objects.create_user(
+ username='student',
+ password=self.student_plaintext_pass,
+ first_name='first_name',
+ last_name='last_name',
+ email='student@test.com'
+ )
+
+ Profile.objects.create(
+ user=self.student,
+ roll_number=10,
+ institute='IIT',
+ department='Chemical',
+ position='student',
+ timezone='UTC'
+ )
+
+ # moderator
+ self.user_plaintext_pass = 'demo'
+ self.user = User.objects.create_user(
+ username='demo_user',
+ password=self.user_plaintext_pass,
+ first_name='first_name',
+ last_name='last_name',
+ email='demo@test.com'
+ )
+
+ Profile.objects.create(
+ user=self.user,
+ roll_number=10,
+ institute='IIT',
+ department='Chemical',
+ position='Moderator',
+ timezone='UTC'
+ )
+
+ self.course = Course.objects.create(
+ name="Python Course",
+ enrollment="Enroll Request", creator=self.user
+ )
+
+ self.post = Post.objects.create(
+ title='post 1',
+ description='post 1 description',
+ course=self.course,
+ creator=self.student
+ )
+
+ def test_create_post_comment(self):
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+ response = self.client.post(reverse('yaksh:post_comments', kwargs={
+ 'course_id': self.course.id,
+ 'uuid': self.post.uid
+ }), {
+ 'post_field': self.post,
+ 'description': 'post 1 comment',
+ 'creator': self.user,
+ })
+ self.assertEquals(response.status_code, 302)
+ url = response.url.split('/')
+ uid = url[5]
+ test_against = Comment.objects.filter(post_field__uid=uid)
+ comment = test_against[0]
+ self.assertEqual(comment.post_field, self.post)
+
+ def test_hide_post_comment(self):
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+ comment = Comment.objects.create(
+ post_field=self.post,
+ description='post 1 comment',
+ creator=self.user
+ )
+ response = self.client.get(reverse('yaksh:hide_comment', kwargs={
+ 'course_id': self.course.id,
+ 'uuid': comment.uid
+ }))
+ self.assertEquals(response.status_code, 302)
+
+ def tearDown(self):
+ self.client.logout()
+ self.user.delete()
+ self.course.delete()
+ self.mod_group.delete()
diff --git a/yaksh/urls.py b/yaksh/urls.py
index 1b86ae8..72febc0 100644
--- a/yaksh/urls.py
+++ b/yaksh/urls.py
@@ -59,11 +59,18 @@ urlpatterns = [
views.get_next_unit, name='next_unit'),
url(r'^course_modules/(?P
\d+)/$',
views.course_modules, name='course_modules'),
- url(r'^forum/(?P\d+)/$', views.course_forum, name='course_forum'),
- url(r'^forum/(?P\d+)/thread/(?P[0-9a-f-]+)/$', views.thread_comments, name='thread_comments'),
- url(r'^forum/(?P\d+)/thread/(?P[0-9a-f-]+)/delete/', views.hide_thread, name='hide_thread'),
- url(r'^forum/(?P\d+)/comment/(?P[0-9a-f-]+)/delete/', views.hide_comment, name='hide_comment'),
-
+ url(r'^forum/(?P\d+)/$',
+ views.course_forum,
+ name='course_forum'),
+ url(r'^forum/(?P\d+)/post/(?P[0-9a-f-]+)/$',
+ views.post_comments,
+ name='post_comments'),
+ url(r'^forum/(?P\d+)/post/(?P[0-9a-f-]+)/delete/',
+ views.hide_post,
+ name='hide_post'),
+ url(r'^forum/(?P\d+)/comment/(?P[0-9a-f-]+)/delete/',
+ views.hide_comment,
+ name='hide_comment'),
url(r'^manage/$', views.prof_manage, name='manage'),
url(r'^manage/addquestion/$', views.add_question, name="add_question"),
url(r'^manage/addquestion/(?P\d+)/$', views.add_question,
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/models.py | 2 +-
yaksh/static/yaksh/css/custom.css | 9 ---------
yaksh/templates/yaksh/course_detail_options.html | 5 +++++
yaksh/templates/yaksh/course_forum.html | 5 +----
yaksh/templates/yaksh/post_comments.html | 10 ++++++----
yaksh/views.py | 15 +++++++++++++++
6 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/yaksh/models.py b/yaksh/models.py
index 424e2f5..4a7c4ba 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -243,7 +243,7 @@ def validate_image(image):
def get_image_dir(instance, filename):
return os.sep.join((
- 'post_%s' % (instance), filename
+ 'post_%s' % (instance.uid), filename
))
diff --git a/yaksh/static/yaksh/css/custom.css b/yaksh/static/yaksh/css/custom.css
index d6b9bdc..63ee455 100644
--- a/yaksh/static/yaksh/css/custom.css
+++ b/yaksh/static/yaksh/css/custom.css
@@ -97,12 +97,3 @@ body, .dropdown-menu {
min-height: 100vh;
transition: all 0.3s;
}
-
-/* ---------------------------------------------------
- Forum STYLE
------------------------------------------------------ */
-
-.comment_image {
- width: 350px;
- height: 350px;
-}
\ No newline at end of file
diff --git a/yaksh/templates/yaksh/course_detail_options.html b/yaksh/templates/yaksh/course_detail_options.html
index 90662d6..4dd4dda 100644
--- a/yaksh/templates/yaksh/course_detail_options.html
+++ b/yaksh/templates/yaksh/course_detail_options.html
@@ -29,6 +29,11 @@
Send Mail
+
+
+ Discussion Forum
+
+
Add Teachers/TAs
diff --git a/yaksh/templates/yaksh/course_forum.html b/yaksh/templates/yaksh/course_forum.html
index 407296f..3e4d07b 100644
--- a/yaksh/templates/yaksh/course_forum.html
+++ b/yaksh/templates/yaksh/course_forum.html
@@ -41,16 +41,13 @@
-
Posts:
{% if posts %}
+
Posts:
{% for post in posts %}
{{post.title}}
- {% if post.image %}
-
- {% endif %}
{{post.get_comments_count}}{% if post.get_comments_count > 1 %} replies{% else %} reply{% endif %}
{{post.description}}
-
-
-
+ {% if post.image %}
+
+
+
+ {% endif %}
@@ -33,7 +35,7 @@
{% if comment.image %}
-
+
{% endif %}
{{comment.description}}
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/static/yaksh/css/custom.css | 12 ++++++++++++
yaksh/templates/yaksh/course_forum.html | 4 +---
yaksh/templates/yaksh/post_comments.html | 6 +++---
yaksh/views.py | 4 ++++
4 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/yaksh/static/yaksh/css/custom.css b/yaksh/static/yaksh/css/custom.css
index 63ee455..299f5d3 100644
--- a/yaksh/static/yaksh/css/custom.css
+++ b/yaksh/static/yaksh/css/custom.css
@@ -97,3 +97,15 @@ body, .dropdown-menu {
min-height: 100vh;
transition: all 0.3s;
}
+
+/* ---------------------------------------------------
+ FORUM STYLE
+----------------------------------------------------- */
+
+.brown-light {
+ background: #f4a460;
+ padding-left: 0.3em;
+ padding-right: 0.3em;
+ padding-top: 0.2em;
+ padding-bottom: 0.2em;
+}
\ No newline at end of file
diff --git a/yaksh/templates/yaksh/course_forum.html b/yaksh/templates/yaksh/course_forum.html
index 3e4d07b..ef6dbf8 100644
--- a/yaksh/templates/yaksh/course_forum.html
+++ b/yaksh/templates/yaksh/course_forum.html
@@ -52,9 +52,7 @@
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 d018db505471226bba8a2e031782676b646396c0 Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Thu, 16 Apr 2020 15:11:21 +0530
Subject: Set post_image, comment_image height, width to 50%
- img-fluid took more space of a card than required. Made it hard
to read the remaining description in a forum.
---
yaksh/static/yaksh/css/custom.css | 5 +++++
yaksh/templates/yaksh/course_forum.html | 3 +--
yaksh/templates/yaksh/post_comments.html | 9 +++++----
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/yaksh/static/yaksh/css/custom.css b/yaksh/static/yaksh/css/custom.css
index 299f5d3..6687c4b 100644
--- a/yaksh/static/yaksh/css/custom.css
+++ b/yaksh/static/yaksh/css/custom.css
@@ -108,4 +108,9 @@ body, .dropdown-menu {
padding-right: 0.3em;
padding-top: 0.2em;
padding-bottom: 0.2em;
+}
+
+.post_image, .comment_image {
+ width: 50%;
+ height: 50%;
}
\ No newline at end of file
diff --git a/yaksh/templates/yaksh/course_forum.html b/yaksh/templates/yaksh/course_forum.html
index ef6dbf8..63e577b 100644
--- a/yaksh/templates/yaksh/course_forum.html
+++ b/yaksh/templates/yaksh/course_forum.html
@@ -42,12 +42,11 @@
{% if posts %}
-
Posts:
{% for post in posts %}
{{post.title}}
-
+
{{post.description|truncatewords:30}}
{{post.get_comments_count}}{% if post.get_comments_count > 1 %} replies{% else %} reply{% endif %}
-
{{post.description}}
+
{{post.description}}
{% if post.image %}
@@ -40,7 +41,7 @@
{% endif %}
-
{{comment.description}}
+
{{comment.description}}
by: {{comment.creator.username}} . {{comment.created_at|naturaltime}}
{% if user.profile.is_moderator %}Delete{% endif %}
@@ -62,4 +63,7 @@
-{% endblock content %}
\ No newline at end of file
+{% endblock content %}
+{% block script %}
+
+{% endblock script %}
\ No newline at end of file
--
cgit
From 04b59bef46557f5e7a1230ab8e5a4929b48c5d59 Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Tue, 21 Apr 2020 22:13:28 +0530
Subject: Improve Post list UI
---
yaksh/templates/yaksh/course_forum.html | 66 +++++++++++++++++++++------------
1 file changed, 42 insertions(+), 24 deletions(-)
diff --git a/yaksh/templates/yaksh/course_forum.html b/yaksh/templates/yaksh/course_forum.html
index 12f5241..ff83c1a 100644
--- a/yaksh/templates/yaksh/course_forum.html
+++ b/yaksh/templates/yaksh/course_forum.html
@@ -41,30 +41,48 @@
-
- {% if posts %}
- {% for post in posts %}
-
-
-
{{post.title}}
-
{{post.description|truncatewords:30}}
-
{{post.get_comments_count}}{% if post.get_comments_count > 1 %} replies{% else %} reply{% endif %}
-
-
-
-
- {% endfor %}
- {% else %}
- No discussion posts are there yet. Create one to start discussing.
- {% endif %}
-
+ {% if posts %}
+
+
+
+ Questions |
+ Created by |
+ Replies |
+ Last reply |
+ |
+
+
+
+ {% for post in posts %}
+
+
+ {{post.title}}
+ {{ post.description|truncatewords:30 }}
+ Last updated: {{post.modified_at}}
+ |
+ {{post.creator.username}} |
+ {{post.get_comments_count}} |
+
+ {% with post.get_last_comment as last_comment %}
+ {% if last_comment %}
+ {{last_comment.creator}}
+ {% else %}
+ None
+ {% endif %}
+ {% endwith %}
+ |
+
+ {% if user.profile.is_moderator %}
+ Delete
+ {% endif %}
+ |
+
+ {% endfor %}
+
+
+ {% else %}
+ No discussion posts are there yet. Create one to start discussing.
+ {% endif %}
{% endblock content %}
{% block script %}
--
cgit
From 3a01e7eb424a0eadfe27386db275682b9d5ca5bd Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Wed, 22 Apr 2020 18:26:44 +0530
Subject: More Tests
---
yaksh/templates/yaksh/course_forum.html | 2 +-
yaksh/templates/yaksh/post_comments.html | 4 +-
yaksh/test_models.py | 44 +++++
yaksh/test_views.py | 290 ++++++++++++++++++++++++++++---
4 files changed, 316 insertions(+), 24 deletions(-)
diff --git a/yaksh/templates/yaksh/course_forum.html b/yaksh/templates/yaksh/course_forum.html
index ff83c1a..17dc287 100644
--- a/yaksh/templates/yaksh/course_forum.html
+++ b/yaksh/templates/yaksh/course_forum.html
@@ -73,7 +73,7 @@
{% if user.profile.is_moderator %}
- Delete
+ Delete
{% endif %}
|
diff --git a/yaksh/templates/yaksh/post_comments.html b/yaksh/templates/yaksh/post_comments.html
index ee54c74..97d6eec 100644
--- a/yaksh/templates/yaksh/post_comments.html
+++ b/yaksh/templates/yaksh/post_comments.html
@@ -17,7 +17,7 @@
{{post.creator.username}}
{{post.created_at|naturaltime}}
- {% if user.profile.is_moderator %}Delete{% endif %}
+ {% if user.profile.is_moderator %}Delete{% endif %}