From fc50841ee866be0522aa4d42dc2a3ce3e9d94743 Mon Sep 17 00:00:00 2001 From: Zambom Date: Tue, 27 Sep 2016 23:52:12 -0300 Subject: [PATCH] Refactoring [Issue: #73] --- courses/models.py | 3 --- courses/templates/subject/form_view_teacher.html | 19 +++++++++++-------- courses/templates/topic/list_topic_foruns.html | 3 +++ courses/templatetags/list_topic_foruns.py | 19 +++++++++++++++++++ forum/migrations/0003_forum_create_date.py | 22 ++++++++++++++++++++++ forum/models.py | 1 + forum/static/js/forum.js | 9 +++++++-- forum/templates/forum/forum_list.html | 16 +++++++++++++--- forum/templates/post/post_list.html | 41 +++++++++++++++++++++++++++++++---------- forum/templates/post_answers/post_answer_list.html | 63 +++++++++++++++++++++++---------------------------------------- forum/templatetags/__init__.py | 0 forum/templatetags/list_post.py | 19 +++++++++++++++++++ forum/templatetags/list_post_answer.py | 19 +++++++++++++++++++ forum/views.py | 6 +++--- 14 files changed, 171 insertions(+), 69 deletions(-) create mode 100644 courses/templates/topic/list_topic_foruns.html create mode 100644 courses/templatetags/list_topic_foruns.py create mode 100644 forum/migrations/0003_forum_create_date.py create mode 100644 forum/templatetags/__init__.py create mode 100644 forum/templatetags/list_post.py create mode 100644 forum/templatetags/list_post_answer.py 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 %}
@@ -31,14 +31,17 @@ + + {% 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