diff --git a/courses/models.py b/courses/models.py index 3bf697f..4b490ab 100644 --- a/courses/models.py +++ b/courses/models.py @@ -100,9 +100,6 @@ class Material(Resource): topic = models.ForeignKey(Topic, verbose_name = _('Topic')) student = models.ForeignKey(User, verbose_name = _('student')) - - - """ It is a category for each subject. """ diff --git a/courses/templates/subject/form_view_teacher.html b/courses/templates/subject/form_view_teacher.html index 22311e2..0528bef 100644 --- a/courses/templates/subject/form_view_teacher.html +++ b/courses/templates/subject/form_view_teacher.html @@ -1,4 +1,4 @@ -{% load static i18n %} +{% load static i18n list_topic_foruns %} {% block javascript %} @@ -19,7 +19,7 @@
{{ topic.description|linebreaks }}
- Forum + {% list_topic_foruns request topic %}
Python
-Description:High-level Language
-Opened in: September 1st
+ ++{% endfor %} \ No newline at end of file diff --git a/courses/templatetags/list_topic_foruns.py b/courses/templatetags/list_topic_foruns.py new file mode 100644 index 0000000..574e132 --- /dev/null +++ b/courses/templatetags/list_topic_foruns.py @@ -0,0 +1,19 @@ +from django import template + +from forum.models import Forum + +register = template.Library() + +""" + Template tag to load all the foruns of a post +""" + +@register.inclusion_tag('topic/list_topic_foruns.html') +def list_topic_foruns(request, topic): + context = { + 'request': request, + } + + context['foruns'] = Forum.objects.filter(topic = topic) + + return context \ No newline at end of file diff --git a/forum/migrations/0003_forum_create_date.py b/forum/migrations/0003_forum_create_date.py new file mode 100644 index 0000000..9970a9e --- /dev/null +++ b/forum/migrations/0003_forum_create_date.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2016-09-28 02:17 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('forum', '0002_remove_forum_title'), + ] + + operations = [ + migrations.AddField( + model_name='forum', + name='create_date', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now, verbose_name='Create Date'), + preserve_default=False, + ), + ] diff --git a/forum/models.py b/forum/models.py index a793868..092fc35 100644 --- a/forum/models.py +++ b/forum/models.py @@ -12,6 +12,7 @@ It works like a 'topic' of forum, which users can post to it and answer posts of """ class Forum(Activity): description = models.TextField(_('Description'), blank = True) + create_date = models.DateTimeField(_('Create Date'), auto_now_add = True) class Meta: verbose_name = _('Forum') diff --git a/forum/static/js/forum.js b/forum/static/js/forum.js index e816baf..21f0cd5 100644 --- a/forum/static/js/forum.js +++ b/forum/static/js/forum.js @@ -1,7 +1,12 @@ -function showForum(url, topic) { +/* +* +* Function to load forum to modal +* +*/ +function showForum(url, forum_id) { $.ajax({ url: url, - data: {'topic': topic}, + data: {'forum_id': forum_id}, success: function(data) { $(".forum_topics").html(data); } diff --git a/forum/templates/forum/forum_list.html b/forum/templates/forum/forum_list.html index 6bd92b3..f2e4b0b 100644 --- a/forum/templates/forum/forum_list.html +++ b/forum/templates/forum/forum_list.html @@ -1,6 +1,16 @@ -{% load i18n permission_tags %} +{% load i18n permission_tags list_post %} -{% if foruns|length > 0 %} +
{{ forum }}
+{% trans 'Description' %}: {{ forum.description }}
+{% trans 'Opened in' %}: {{ forum.create_date }}
+- {% for post in posts %} --
+ {% for post in posts %}
+
+
+
+
+
+
+ {% list_post_answer request post %}
+ {% endfor %}
+{% endif %}
+
\ No newline at end of file
diff --git a/forum/templates/post_answers/post_answer_list.html b/forum/templates/post_answers/post_answer_list.html
index e24b012..21f0e76 100644
--- a/forum/templates/post_answers/post_answer_list.html
+++ b/forum/templates/post_answers/post_answer_list.html
@@ -1,47 +1,30 @@
{% load i18n permission_tags %}
{% if answers|length > 0 %}
-
+ {{ post.user }} + {% if request.user|has_role:'system_admin' or request.user|has_role:'professor' and request.user == post.user %} +
+
+
+ more_horiz
+
+
+
+ {% endif %}
+
++- create {% trans 'Edit' %}
+ - delete_sweep {% trans 'Remove' %}
+
+{{ post.post_date }}
+{{ post.message|linebreaks }}
+- {% for answer in answers %} --
-
-
-
-
-
-
- {% if user|has_role:'system_admin' or user|has_role:'professor' and user == forum.topic.owner %}
-
-
-
- more_horiz
-
-
-
- {% endif %}
-
-
-
-
+
+
+ {% endif %}
+
+
+
-
- {% endfor %}
-
-{% else %}
-
+
+ {% endfor %}
{% endif %}
\ No newline at end of file
diff --git a/forum/templatetags/__init__.py b/forum/templatetags/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/forum/templatetags/__init__.py
diff --git a/forum/templatetags/list_post.py b/forum/templatetags/list_post.py
new file mode 100644
index 0000000..b35bed9
--- /dev/null
+++ b/forum/templatetags/list_post.py
@@ -0,0 +1,19 @@
+from django import template
+
+from forum.models import Post
+
+register = template.Library()
+
+"""
+ Template tag to load all the posts of a post
+"""
+
+@register.inclusion_tag('post/post_list.html')
+def list_posts(request, forum):
+ context = {
+ 'request': request,
+ }
+
+ context['posts'] = Post.objects.filter(forum = forum)
+
+ return context
\ No newline at end of file
diff --git a/forum/templatetags/list_post_answer.py b/forum/templatetags/list_post_answer.py
new file mode 100644
index 0000000..e50b1a0
--- /dev/null
+++ b/forum/templatetags/list_post_answer.py
@@ -0,0 +1,19 @@
+from django import template
+
+from forum.models import PostAnswer
+
+register = template.Library()
+
+"""
+ Template tag to load all the posts of a post
+"""
+
+@register.inclusion_tag('post_answers/post_answer_list.html')
+def list_post_answer(request, post):
+ context = {
+ 'request': request,
+ }
+
+ context['answers'] = PostAnswer.objects.filter(post = post)
+
+ return context
\ No newline at end of file
diff --git a/forum/views.py b/forum/views.py
index 77a6f1a..54380de 100644
--- a/forum/views.py
+++ b/forum/views.py
@@ -14,12 +14,12 @@ class ForumIndex(LoginRequiredMixin, generic.ListView):
redirect_field_name = 'next'
template_name = "forum/forum_list.html"
- context_object_name = 'foruns'
+ context_object_name = 'forum'
def get_queryset(self):
- topic = get_object_or_404(Topic, slug = self.request.GET.get('topic', ''))
+ forum_id = self.request.GET.get('forum_id', 0)
- context = Forum.objects.filter(topic = topic)
+ context = Forum.objects.get(id = forum_id)
return context
--
libgit2 0.21.2
-- create Edit
- - delete_sweep Remove
-
-{{ answer.user }}
-{{ answer.message|linebreaks }}
+ {% for answer in answers %} ++ {{ answer.user }} + {% if request.user|has_role:'system_admin' or request.user|has_role:'professor' and request.user == answer.user %} +
+
+
+ more_horiz
+
+
-
-
+- create {% trans 'Edit' %}
+ - delete_sweep {% trans 'Remove' %}
+
- - - {{ answer.answer_date|timesince }} - {% trans ' ago' %} - -
{{ answer.answer_date|timesince }} {% trans 'ago' %}
{% trans 'Nobody answered this post yet.' %}
+{{ answer.message|linebreaks }}
+