summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCruiseDevice2020-04-25 19:21:04 +0530
committerCruiseDevice2020-04-25 19:21:04 +0530
commit66939d00dab998c7c0e649938527271551f22980 (patch)
tree0fa82441bcd547f8c7ce51384bcbddf269453105
parent8f66c175447bc335c9121d5bf5ae1cb5b181cef9 (diff)
downloadonline_test-66939d00dab998c7c0e649938527271551f22980.tar.gz
online_test-66939d00dab998c7c0e649938527271551f22980.tar.bz2
online_test-66939d00dab998c7c0e649938527271551f22980.zip
Resolve comments, fix tests, add pagination
-rw-r--r--online_test/settings.py1
-rw-r--r--yaksh/templates/yaksh/course_forum.html15
-rw-r--r--yaksh/templates/yaksh/post_comments.html13
-rw-r--r--yaksh/test_views.py6
-rw-r--r--yaksh/views.py22
5 files changed, 37 insertions, 20 deletions
diff --git a/online_test/settings.py b/online_test/settings.py
index 82def90..7b9a231 100644
--- a/online_test/settings.py
+++ b/online_test/settings.py
@@ -45,7 +45,6 @@ INSTALLED_APPS = (
'taggit',
'social_django',
'grades',
- 'django.contrib.humanize'
)
MIDDLEWARE = (
diff --git a/yaksh/templates/yaksh/course_forum.html b/yaksh/templates/yaksh/course_forum.html
index 17dc287..bf098d3 100644
--- a/yaksh/templates/yaksh/course_forum.html
+++ b/yaksh/templates/yaksh/course_forum.html
@@ -1,5 +1,4 @@
-{% extends "user.html" %}
-{% load humanize %}
+{% extends base_template %}
{% load static %}
{% block title %}
{{course.name}}: Discussion Forum
@@ -10,7 +9,12 @@
<h2><center>{{course.name}}</center></h2>
<center>Discussion Forum</center>
</div>
- <div class="pull-right">
+ {% if moderator %}
+ <a href="{% url 'yaksh:course_detail' course.id %}" class="btn btn-primary">Back to Course</a>
+ {% else %}
+ <a href="{% url 'yaksh:course_modules' course.id %}" class="btn btn-primary">Back to Course</a>
+ {% endif %}
+ <div class="pull-right">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#newPostModal">New Post</button>
</div>
<!-- Modal -->
@@ -56,7 +60,7 @@
{% for post in posts %}
<tr>
<td>
- <a href="{% url "yaksh:post_comments" course.id post.uid %}">{{post.title}}</a>
+ <a href="{% url 'yaksh:post_comments' course.id post.uid %}">{{post.title}}</a>
<small class="text-muted d-block">{{ post.description|truncatewords:30 }}</small>
<small class="text-muted"><strong>Last updated: {{post.modified_at}}</strong></small>
</td>
@@ -73,7 +77,7 @@
</td>
<td>
{% if user.profile.is_moderator %}
- <small><a href="{% url "yaksh:hide_post" course.id post.uid %}" class="pull-right btn btn-danger">Delete</i></a></small>
+ <small><a href="{% url 'yaksh:hide_post' course.id post.uid %}" class="pull-right btn btn-danger">Delete</i></a></small>
{% endif %}
</td>
</tr>
@@ -83,6 +87,7 @@
{% else %}
No discussion posts are there yet. Create one to start discussing.
{% endif %}
+ {% include "yaksh/paginator.html" %}
</div>
{% endblock content %}
{% block script %}
diff --git a/yaksh/templates/yaksh/post_comments.html b/yaksh/templates/yaksh/post_comments.html
index 227530e..463103e 100644
--- a/yaksh/templates/yaksh/post_comments.html
+++ b/yaksh/templates/yaksh/post_comments.html
@@ -1,13 +1,12 @@
-{% extends "user.html" %}
+{% extends base_template %}
{% load static %}
-{% load humanize %}
{% block title %}
{{post.title}}
{% endblock title %}
{% block content %}
<div class="container">
- <a class="btn btn-primary" href="{% url "yaksh:course_forum" post.course.id %}">Back to Posts</a>
+ <a class="btn btn-primary" href="{% url 'yaksh:course_forum' post.course.id %}">Back to Posts</a>
<br>
<br>
<div class="card mb-2 border-dark">
@@ -16,8 +15,8 @@
<br>
<small>
<strong>{{post.creator.username}}</strong>
- {{post.created_at|naturaltime}}
- {% if user.profile.is_moderator %}<a href="{% url "yaksh:hide_post" post.course.id post.uid %}" class="pull-right btn btn-danger">Delete</a>{% endif %}
+ {{post.created_at}}
+ {% if user.profile.is_moderator %}<a href="{% url 'yaksh:hide_post' post.course.id post.uid %}" class="pull-right btn btn-danger">Delete</a>{% endif %}
</small>
</div>
@@ -40,7 +39,7 @@
<strong class="text-muted">{{comment.creator.username}}</strong>
</div>
<div class="col-6 text-right">
- <small class="text-muted">{{comment.created_at}} {% if user.profile.is_moderator %} <a href="{% url "yaksh:hide_comment" post.course.id comment.uid %}" class="btn btn-danger">Delete</a>{% endif %}</small>
+ <small class="text-muted">{{comment.created_at}} {% if user.profile.is_moderator %} <a href="{% url 'yaksh:hide_comment' post.course.id comment.uid %}" class="btn btn-danger">Delete</a>{% endif %}</small>
</div>
</div>
<p class="card-text description">{{comment.description}}</p>
@@ -57,7 +56,7 @@
{% endif %}
<br>
<div>
- <form action="{% url "yaksh:post_comments" post.course.id post.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_views.py b/yaksh/test_views.py
index 39d5865..0ae97ba 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -6740,10 +6740,10 @@ class TestPostComment(TestCase):
def test_hide_post_comment(self):
self.client.login(
- username=self.student.username,
- password=self.student_plaintext_pass
+ username=self.user.username,
+ password=self.user_plaintext_pass
)
- self.course.students.add(self.student)
+ self.course.students.add(self.user)
comment = Comment.objects.create(
post_field=self.post,
description='post 1 comment',
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