summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/admin.py4
-rw-r--r--yaksh/forms.py20
-rw-r--r--yaksh/models.py21
-rw-r--r--yaksh/templates/yaksh/course_forum.html32
-rw-r--r--yaksh/templates/yaksh/post_comments.html (renamed from yaksh/templates/yaksh/thread_comments.html)23
-rw-r--r--yaksh/test_models.py87
-rw-r--r--yaksh/test_views.py283
-rw-r--r--yaksh/urls.py17
-rw-r--r--yaksh/views.py52
9 files changed, 430 insertions, 109 deletions
diff --git a/yaksh/admin.py b/yaksh/admin.py
index 4489ffc..3d3ba89 100644
--- a/yaksh/admin.py
+++ b/yaksh/admin.py
@@ -1,7 +1,7 @@
from yaksh.models import Question, Quiz, QuestionPaper, Profile
from yaksh.models import (TestCase, StandardTestCase, StdIOBasedTestCase,
Course, AnswerPaper, CourseStatus, LearningModule,
- Lesson, Thread, Comment
+ Lesson, Post, Comment
)
from django.contrib import admin
@@ -48,7 +48,7 @@ class QuizAdmin(admin.ModelAdmin):
admin.site.register(Profile, ProfileAdmin)
admin.site.register(Question)
admin.site.register(TestCase)
-admin.site.register(Thread)
+admin.site.register(Post)
admin.site.register(Comment)
admin.site.register(StandardTestCase)
admin.site.register(StdIOBasedTestCase)
diff --git a/yaksh/forms.py b/yaksh/forms.py
index e66c898..819bb49 100644
--- a/yaksh/forms.py
+++ b/yaksh/forms.py
@@ -1,7 +1,7 @@
from django import forms
from yaksh.models import (
get_model_class, Profile, Quiz, Question, Course, QuestionPaper, Lesson,
- LearningModule, TestCase, languages, question_types, Thread, Comment
+ LearningModule, TestCase, languages, question_types, Post, Comment
)
from grades.models import GradingSystem
from django.contrib.auth import authenticate
@@ -32,7 +32,7 @@ test_case_types = (
)
status_types = (
- ('select','Select Status'),
+ ('select', 'Select Status'),
('active', 'Active'),
('closed', 'Inactive'),
)
@@ -369,7 +369,7 @@ class SearchFilterForm(forms.Form):
search_tags = forms.CharField(
label='Search Tags',
widget=forms.TextInput(attrs={'placeholder': 'Search',
- 'class': form_input_class,}),
+ 'class': form_input_class, }),
required=False
)
search_status = forms.CharField(max_length=16, widget=forms.Select(
@@ -554,23 +554,23 @@ class TestcaseForm(forms.ModelForm):
fields = ["type"]
-class ThreadForm(forms.ModelForm):
+class PostForm(forms.ModelForm):
class Meta:
- model = Thread
+ model = Post
fields = ["title", "description", "image"]
widgets = {
'title': forms.TextInput(
- attrs = {
+ attrs={
'class': 'form-control'
}
),
'description': forms.Textarea(
- attrs = {
+ attrs={
'class': 'form-control'
}
),
'image': forms.FileInput(
- attrs = {
+ attrs={
'class': 'form-control-file'
}
)
@@ -583,12 +583,12 @@ class CommentForm(forms.ModelForm):
fields = ["description", "image"]
widgets = {
'description': forms.Textarea(
- attrs = {
+ attrs={
'class': 'form-control'
}
),
'image': forms.FileInput(
- attrs = {
+ attrs={
'class': 'form-control-file'
}
)
diff --git a/yaksh/models.py b/yaksh/models.py
index d76d6aa..424e2f5 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -243,9 +243,10 @@ def validate_image(image):
def get_image_dir(instance, filename):
return os.sep.join((
- 'thread_%s' % (instance), filename
+ 'post_%s' % (instance), filename
))
+
###############################################################################
class CourseManager(models.Manager):
@@ -1176,7 +1177,9 @@ class CourseStatus(models.Model):
if self.is_course_complete():
self.calculate_percentage()
if self.course.grading_system is None:
- grading_system = GradingSystem.objects.get(name__contains='default')
+ grading_system = GradingSystem.objects.get(
+ name__contains='default'
+ )
else:
grading_system = self.course.grading_system
grade = grading_system.get_grade(self.percentage)
@@ -2646,6 +2649,7 @@ class TestCaseOrder(models.Model):
# Order of the test case for a question.
order = models.TextField()
+
##############################################################################
class ForumBase(models.Model):
uid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
@@ -2653,15 +2657,15 @@ class ForumBase(models.Model):
description = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True)
- image = models.ImageField(upload_to=get_image_dir, blank=True,
+ image = models.ImageField(upload_to=get_image_dir, blank=True,
null=True, validators=[validate_image])
active = models.BooleanField(default=True)
-class Thread(ForumBase):
+class Post(ForumBase):
title = models.CharField(max_length=200)
course = models.ForeignKey(Course,
- on_delete=models.CASCADE, related_name='thread')
+ on_delete=models.CASCADE, related_name='post')
def __str__(self):
return self.title
@@ -2674,10 +2678,9 @@ class Thread(ForumBase):
class Comment(ForumBase):
- thread_field = models.ForeignKey(Thread,
- on_delete=models.CASCADE,
- related_name='comment')
+ post_field = models.ForeignKey(Post, on_delete=models.CASCADE,
+ related_name='comment')
def __str__(self):
return 'Comment by {0}: {1}'.format(self.creator.username,
- self.thread_field.title)
+ self.post_field.title)
diff --git a/yaksh/templates/yaksh/course_forum.html b/yaksh/templates/yaksh/course_forum.html
index 41dbd7b..407296f 100644
--- a/yaksh/templates/yaksh/course_forum.html
+++ b/yaksh/templates/yaksh/course_forum.html
@@ -10,16 +10,16 @@
<center>Discussion Forum</center>
</div>
<div class="pull-right">
- <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#newThreadModal">New Thread</button>
+ <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#newPostModal">New Post</button>
</div>
<!-- Modal -->
- <div id="newThreadModal" class="modal fade" role="dialog">
+ <div id="newPostModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
- <h4 class="modal-title">Create a new thread</h4>
+ <h4 class="modal-title">Create a new Post</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
@@ -28,7 +28,7 @@
{% csrf_token %}
{{form}}
</div>
- <input type="submit" class="btn btn-primary" value="Create Thread">
+ <input type="submit" class="btn btn-primary" value="Create Post">
</form>
</div>
<div class="modal-footer">
@@ -41,31 +41,33 @@
<br>
<br>
<div>
- <h3>Threads:</h3>
- {% if threads %}
- {% for thread in threads %}
+ <h3>Posts:</h3>
+ {% if posts %}
+ {% for post in posts %}
<div class="card">
<div class="card-body">
- <a href="{% url "yaksh:thread_comments" course.id thread.uid %}">{{thread.title}}</a>
+ <a href="{% url "yaksh:post_comments" course.id post.uid %}">{{post.title}}</a>
<br>
- {% if thread.image %}
- <img src="{{thread.image.url}}" class="thread_image">
+ {% if post.image %}
+ <img src="{{post.image.url}}" class="post_image">
{% endif %}
- <p class="pull-right"><small>{{thread.get_comments_count}}{% if thread.get_comments_count > 1 %} replies{% else %} reply{% endif %}</small></p>
+ <p class="pull-right"><small>{{post.get_comments_count}}{% if post.get_comments_count > 1 %} replies{% else %} reply{% endif %}</small></p>
</div>
<div class="card-footer">
- {% with thread.get_last_comment as last_comment %}
- <small> {% if thread.creator.profile.is_moderator %} INSTRUCTOR CREATED {% endif %} Last Post by: <strong>{{last_comment.creator}}</strong> . {{last_comment.modified_at|naturaltime}}</small>
+ {% with post.get_last_comment as last_comment %}
+ {% if last_comment %}
+ <small> {% if post.creator.profile.is_moderator %} INSTRUCTOR CREATED {% endif %} Last Post by: <strong>{{last_comment.creator}}</strong> . {{last_comment.modified_at|naturaltime}}</small>
+ {% endif %}
{% endwith %}
{% if user.profile.is_moderator %}
- <small><a href="{% url "yaksh:hide_thread" course.id thread.uid %}" class="pull-right">Delete</i></a></small>
+ <small><a href="{% url "yaksh:hide_post" course.id post.uid %}" class="pull-right">Delete</i></a></small>
{% endif %}
</div>
</div>
<br>
{% endfor %}
{% else %}
- No discussion threads are there yet. Create one to start discussing.
+ No discussion posts are there yet. Create one to start discussing.
{% endif %}
</div>
</div>
diff --git a/yaksh/templates/yaksh/thread_comments.html b/yaksh/templates/yaksh/post_comments.html
index f614b7a..89f0762 100644
--- a/yaksh/templates/yaksh/thread_comments.html
+++ b/yaksh/templates/yaksh/post_comments.html
@@ -1,25 +1,28 @@
{% extends "user.html" %}
{% block title %}
- {{thread.title}}
+ {{post.title}}
{% endblock title %}
{% block content %}
<div class="container">
- <a class="btn btn-primary" href="{% url "yaksh:course_forum" thread.course.id %}">Back to Threads</a>
+ <a class="btn btn-primary" href="{% url "yaksh:course_forum" post.course.id %}">Back to Posts</a>
<div class="card">
<div class="card-header">
- {{thread.title}}
+ {{post.title}}
<br>
<small>
- <strong>{{thread.creator.username}}</strong>
- {{thread.created_at}}
- {% if user.profile.is_moderator %}<a href="{% url "yaksh:hide_thread" thread.course.id thread.uid %}" class="pull-right">Delete</a>{% endif %}
+ <strong>{{post.creator.username}}</strong>
+ {{post.created_at}}
+ {% if user.profile.is_moderator %}<a href="{% url "yaksh:hide_post" post.course.id post.uid %}" class="pull-right">Delete</a>{% endif %}
</small>
</div>
<div class="card-body">
- <p>{{thread.description}}</p>
+ <p>{{post.description}}</p>
+ <a href="{{post.image.url}}" target="_blank">
+ <img src="{{post.image.url}}" alt="">
+ </a>
</div>
</div>
<br>
@@ -36,18 +39,18 @@
<p>{{comment.description}}</p>
<small class="pull-right">
by: <strong>{{comment.creator.username}} </strong>. {{comment.created_at}}
- {% if user.profile.is_moderator %}<a href="{% url "yaksh:hide_comment" thread.course.id comment.uid %}">Delete</a>{% endif %}
+ {% if user.profile.is_moderator %}<a href="{% url "yaksh:hide_comment" post.course.id comment.uid %}">Delete</a>{% endif %}
</small>
</div>
<hr>
{% endfor %}
{% else %}
- No comments on this thread.
+ No comments on this post.
{% endif %}
</div>
<br>
<div>
- <form action="{% url "yaksh:thread_comments" thread.course.id thread.uid %}" method="POST" enctype='multipart/form-data'>
+ <form action="{% url "yaksh:post_comments" post.course.id post.uid %}" method="POST" enctype='multipart/form-data'>
<div class="form-group">
{% csrf_token %}
{{form}}
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'], '<p>test description</p>')
+
+
+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<course_id>\d+)/$',
views.course_modules, name='course_modules'),
- url(r'^forum/(?P<course_id>\d+)/$', views.course_forum, name='course_forum'),
- url(r'^forum/(?P<course_id>\d+)/thread/(?P<uuid>[0-9a-f-]+)/$', views.thread_comments, name='thread_comments'),
- url(r'^forum/(?P<course_id>\d+)/thread/(?P<uuid>[0-9a-f-]+)/delete/', views.hide_thread, name='hide_thread'),
- url(r'^forum/(?P<course_id>\d+)/comment/(?P<uuid>[0-9a-f-]+)/delete/', views.hide_comment, name='hide_comment'),
-
+ url(r'^forum/(?P<course_id>\d+)/$',
+ views.course_forum,
+ name='course_forum'),
+ url(r'^forum/(?P<course_id>\d+)/post/(?P<uuid>[0-9a-f-]+)/$',
+ views.post_comments,
+ name='post_comments'),
+ url(r'^forum/(?P<course_id>\d+)/post/(?P<uuid>[0-9a-f-]+)/delete/',
+ views.hide_post,
+ name='hide_post'),
+ url(r'^forum/(?P<course_id>\d+)/comment/(?P<uuid>[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<question_id>\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)