From 5e49406420207123afec88a1ca7138e7a58c2acc Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Wed, 16 Sep 2020 07:23:36 +0530 Subject: Show Lesson post and comments in discussion forum - Use trash icon instead of DELETE button - Sidebar to navigate between course forum and lesson forum - Course forum displays all the questions (posts) linked with the course model, and Lesson forum displays all the questions (posts) linked with the Lesson model. --- yaksh/models.py | 19 +++ yaksh/static/yaksh/css/custom.css | 49 ++++++- yaksh/templates/yaksh/course_forum.html | 224 ++++++++++++++++--------------- yaksh/templates/yaksh/lessons_forum.html | 70 ++++++++++ yaksh/templates/yaksh/post_comments.html | 6 +- yaksh/templates/yaksh/show_video.html | 2 +- yaksh/templates/yaksh/sidebar.html | 8 ++ yaksh/urls.py | 4 +- yaksh/views.py | 29 +++- 9 files changed, 286 insertions(+), 125 deletions(-) create mode 100644 yaksh/templates/yaksh/lessons_forum.html create mode 100644 yaksh/templates/yaksh/sidebar.html (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 67f981e..df70fc1 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1102,6 +1102,25 @@ class Course(models.Model): learning_units.extend(module.get_learning_units()) return learning_units + def get_lesson_posts(self, user): + learning_units = self.get_learning_units() + comments = [] + for unit in learning_units: + if unit.lesson is not None: + lesson_ct = ContentType.objects.get_for_model(unit.lesson) + title = unit.lesson.name + try: + post = Post.objects.get( + target_ct=lesson_ct, + target_id=unit.lesson.id, + active=True, title=title, creator=user + ) + except Post.DoesNotExist: + post = None + if post is not None: + comments.append(post) + return comments + def remove_trial_modules(self): learning_modules = self.learning_module.all() for module in learning_modules: diff --git a/yaksh/static/yaksh/css/custom.css b/yaksh/static/yaksh/css/custom.css index 26efbed..edb9530 100644 --- a/yaksh/static/yaksh/css/custom.css +++ b/yaksh/static/yaksh/css/custom.css @@ -109,12 +109,49 @@ body, .dropdown-menu { FORUM STYLE ----------------------------------------------------- */ -.brown-light { - background: #f4a460; - padding-left: 0.3em; - padding-right: 0.3em; - padding-top: 0.2em; - padding-bottom: 0.2em; + #wrapper { + overflow-x: hidden; + } + +#sidebar-wrapper { + min-height: 100vh; + margin-left: -15rem; + -webkit-transition: margin .25s ease-out; + -moz-transition: margin .25s ease-out; + -o-transition: margin .25s ease-out; + transition: margin .25s ease-out; +} + +#sidebar-wrapper .sidebar-heading { + padding: 0.875rem 1.25rem; + font-size: 1.2rem; +} + +#sidebar-wrapper .list-group { + width: 15rem; +} + +#page-content-wrapper { + min-width: 100vw; +} + +#wrapper.toggled #sidebar-wrapper { + margin-left: 0; +} + +@media (min-width: 768px) { + #sidebar-wrapper { + margin-left: 0; + } + + #page-content-wrapper { + min-width: 0; + width: 100%; + } + + #wrapper.toggled #sidebar-wrapper { + margin-left: -15rem; + } } .post_image, .comment_image { diff --git a/yaksh/templates/yaksh/course_forum.html b/yaksh/templates/yaksh/course_forum.html index 4724981..a9bda6f 100644 --- a/yaksh/templates/yaksh/course_forum.html +++ b/yaksh/templates/yaksh/course_forum.html @@ -4,124 +4,126 @@ {{course.name}}: Discussion Forum {% endblock title %} {% block content %} -
-
-

{{course.name}}

-
Discussion Forum
-
-
-
- {% if moderator %} - -  Back - - {% else %} - -  Back - - {% endif %} +
+ {% include "yaksh/sidebar.html" %} +
+
+

{{course.name}}

+
Discussion Forum
-
- +
+
+ {% if moderator %} + +  Back + + {% else %} + +  Back + + {% endif %} +
+
+ +
-
- - {% endblock content %} {% block script %} diff --git a/yaksh/templates/yaksh/lessons_forum.html b/yaksh/templates/yaksh/lessons_forum.html new file mode 100644 index 0000000..a4fd23b --- /dev/null +++ b/yaksh/templates/yaksh/lessons_forum.html @@ -0,0 +1,70 @@ +{% extends base_template %} +{% load static %} +{% block title %} + {{course.name}}: Lessons Forum +{% endblock title %} +{% block content %} +
+ {% include "yaksh/sidebar.html" %} +
+
+

{{course.name}}

+
Discussion Forum
+
+
+
+ {% if moderator %} + +  Back + + {% else %} + +  Back + + {% endif %} +
+
+ {% if posts %} + + + + + + + + + + + + {% for post in posts %} + + + + + + + + {% endfor %} + +
PostsCreated byRepliesLast reply
+ {{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 %} + + {% endif %} +
+ {% endif %} +
+
+{% endblock content %} + diff --git a/yaksh/templates/yaksh/post_comments.html b/yaksh/templates/yaksh/post_comments.html index f0f1593..6051b6e 100644 --- a/yaksh/templates/yaksh/post_comments.html +++ b/yaksh/templates/yaksh/post_comments.html @@ -6,7 +6,7 @@ {% block content %}
- +  Back to Posts
@@ -18,7 +18,7 @@ {{post.creator.username}} {{post.created_at}} - {% if user.profile.is_moderator %}Delete{% endif %} + {% if user.profile.is_moderator %}{% endif %}
@@ -41,7 +41,7 @@ {{comment.creator.username}}
- {{comment.created_at}} {% if user.profile.is_moderator %} Delete{% endif %} + {{comment.created_at}} {% if user.profile.is_moderator %} {% endif %}

{{comment.description}}

diff --git a/yaksh/templates/yaksh/show_video.html b/yaksh/templates/yaksh/show_video.html index 76a48d4..ef6f459 100644 --- a/yaksh/templates/yaksh/show_video.html +++ b/yaksh/templates/yaksh/show_video.html @@ -236,7 +236,7 @@ {{comment.creator.username}}
- {{comment.created_at}} {% if user.profile.is_moderator %} Delete{% endif %} + {{comment.created_at}} {% if user.profile.is_moderator %} {% endif %}

{{comment.description}}

diff --git a/yaksh/templates/yaksh/sidebar.html b/yaksh/templates/yaksh/sidebar.html new file mode 100644 index 0000000..7d0ac74 --- /dev/null +++ b/yaksh/templates/yaksh/sidebar.html @@ -0,0 +1,8 @@ + + + diff --git a/yaksh/urls.py b/yaksh/urls.py index b60b5f5..82785ca 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -60,9 +60,11 @@ 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+)/$', + url(r'^forum/course_forum/(?P\d+)/$', views.course_forum, name='course_forum'), + url(r'^forum/lessons_forum/(?P\d+)/$', + views.lessons_forum, name='lessons_forum'), url(r'^forum/(?P\d+)/post/(?P[0-9a-f-]+)/$', views.post_comments, name='post_comments'), diff --git a/yaksh/views.py b/yaksh/views.py index ae00fc6..084ec1e 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -2811,7 +2811,6 @@ def show_lesson(request, lesson_id, module_id, course_id): post = Post.objects.get( target_ct=lesson_ct, target_id=learn_unit.lesson.id, active=True, title=title, creator=user, - description=f'Discussion on {title} lesson', ) except Post.DoesNotExist: post = Post.objects.create( @@ -3517,6 +3516,27 @@ def course_forum(request, course_id): }) +@login_required +@email_verified +def lessons_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) + course_ct = ContentType.objects.get_for_model(course) + lesson_posts = course.get_lesson_posts(user) + return render(request, 'yaksh/lessons_forum.html', { + 'user': user, + 'base_template': base_template, + 'moderator': moderator, + 'course': course, + 'posts': lesson_posts, + }) + + @login_required @email_verified def post_comments(request, course_id, uuid): @@ -3545,6 +3565,7 @@ def post_comments(request, course_id, uuid): 'base_template': base_template, 'form': form, 'user': user, + 'course': course }) @@ -3554,7 +3575,9 @@ 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) or not course.is_teacher(user)): - raise Http404(f'Only a course creator or a teacher can delete the post.') + raise Http404( + 'Only a course creator or a teacher can delete the post.' + ) post = get_object_or_404(Post, uid=uuid) post.comment.active = False post.active = False @@ -3570,7 +3593,7 @@ def hide_comment(request, course_id, uuid): course = get_object_or_404(Course, id=course_id) if (not course.is_creator(user) or not course.is_teacher(user)): raise Http404( - f'Only a course creator or a teacher can delete the comments' + 'Only a course creator or a teacher can delete the comments' ) comment = get_object_or_404(Comment, uid=uuid) post_uid = comment.post_field.uid -- cgit