Commit fc50841ee866be0522aa4d42dc2a3ce3e9d94743
1 parent
5e97189c
Exists in
master
and in
5 other branches
Refactoring [Issue: #73]
Showing
14 changed files
with
171 additions
and
69 deletions
Show diff stats
courses/models.py
@@ -100,9 +100,6 @@ class Material(Resource): | @@ -100,9 +100,6 @@ class Material(Resource): | ||
100 | topic = models.ForeignKey(Topic, verbose_name = _('Topic')) | 100 | topic = models.ForeignKey(Topic, verbose_name = _('Topic')) |
101 | student = models.ForeignKey(User, verbose_name = _('student')) | 101 | student = models.ForeignKey(User, verbose_name = _('student')) |
102 | 102 | ||
103 | - | ||
104 | - | ||
105 | - | ||
106 | """ | 103 | """ |
107 | It is a category for each subject. | 104 | It is a category for each subject. |
108 | """ | 105 | """ |
courses/templates/subject/form_view_teacher.html
1 | -{% load static i18n %} | 1 | +{% load static i18n list_topic_foruns %} |
2 | 2 | ||
3 | {% block javascript %} | 3 | {% block javascript %} |
4 | <script type="text/javascript" src="{% static 'js/forum.js' %}"></script> | 4 | <script type="text/javascript" src="{% static 'js/forum.js' %}"></script> |
@@ -19,7 +19,7 @@ | @@ -19,7 +19,7 @@ | ||
19 | </a> | 19 | </a> |
20 | <div class="panel-body"> | 20 | <div class="panel-body"> |
21 | <p>{{ topic.description|linebreaks }}</p> | 21 | <p>{{ topic.description|linebreaks }}</p> |
22 | - <a href="javascript:showForum('{% url 'forum:index' %}', '{{topic.slug}}')">Forum</a> | 22 | + {% list_topic_foruns request topic %} |
23 | </div> | 23 | </div> |
24 | </div> | 24 | </div> |
25 | 25 | ||
@@ -31,14 +31,17 @@ | @@ -31,14 +31,17 @@ | ||
31 | </div> | 31 | </div> |
32 | <div class="modal-body"> | 32 | <div class="modal-body"> |
33 | <section> | 33 | <section> |
34 | - <div class="comments-list"> | ||
35 | - <div class="section-heading"> | ||
36 | - <h1>Python</h1> | ||
37 | - <h4><b>Description:</b>High-level Language</h4> | ||
38 | - <h4><b>Opened in:</b> September 1st</h4> | 34 | + <div class="forum_topics"></div> |
35 | + <div class="form-group"> | ||
36 | + <div class="input-group"> | ||
37 | + <textarea type="text" id="addon3a" class="form-control" placeholder="{% trans 'Post a comment...' %}"></textarea> | ||
38 | + <span class="input-group-btn"> | ||
39 | + <button type="button" class="btn btn-fab btn-fab-mini"> | ||
40 | + <i class="material-icons">send</i> | ||
41 | + </button> | ||
42 | + </span> | ||
39 | </div> | 43 | </div> |
40 | </div> | 44 | </div> |
41 | - <div class="forum_topics"></div> | ||
42 | </section> | 45 | </section> |
43 | </div> | 46 | </div> |
44 | <div class="modal-footer"> | 47 | <div class="modal-footer"> |
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +from django import template | ||
2 | + | ||
3 | +from forum.models import Forum | ||
4 | + | ||
5 | +register = template.Library() | ||
6 | + | ||
7 | +""" | ||
8 | + Template tag to load all the foruns of a post | ||
9 | +""" | ||
10 | + | ||
11 | +@register.inclusion_tag('topic/list_topic_foruns.html') | ||
12 | +def list_topic_foruns(request, topic): | ||
13 | + context = { | ||
14 | + 'request': request, | ||
15 | + } | ||
16 | + | ||
17 | + context['foruns'] = Forum.objects.filter(topic = topic) | ||
18 | + | ||
19 | + return context | ||
0 | \ No newline at end of file | 20 | \ No newline at end of file |
@@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
1 | +# -*- coding: utf-8 -*- | ||
2 | +# Generated by Django 1.10 on 2016-09-28 02:17 | ||
3 | +from __future__ import unicode_literals | ||
4 | + | ||
5 | +from django.db import migrations, models | ||
6 | +import django.utils.timezone | ||
7 | + | ||
8 | + | ||
9 | +class Migration(migrations.Migration): | ||
10 | + | ||
11 | + dependencies = [ | ||
12 | + ('forum', '0002_remove_forum_title'), | ||
13 | + ] | ||
14 | + | ||
15 | + operations = [ | ||
16 | + migrations.AddField( | ||
17 | + model_name='forum', | ||
18 | + name='create_date', | ||
19 | + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now, verbose_name='Create Date'), | ||
20 | + preserve_default=False, | ||
21 | + ), | ||
22 | + ] |
forum/models.py
@@ -12,6 +12,7 @@ It works like a 'topic' of forum, which users can post to it and answer posts of | @@ -12,6 +12,7 @@ It works like a 'topic' of forum, which users can post to it and answer posts of | ||
12 | """ | 12 | """ |
13 | class Forum(Activity): | 13 | class Forum(Activity): |
14 | description = models.TextField(_('Description'), blank = True) | 14 | description = models.TextField(_('Description'), blank = True) |
15 | + create_date = models.DateTimeField(_('Create Date'), auto_now_add = True) | ||
15 | 16 | ||
16 | class Meta: | 17 | class Meta: |
17 | verbose_name = _('Forum') | 18 | verbose_name = _('Forum') |
forum/static/js/forum.js
1 | -function showForum(url, topic) { | 1 | +/* |
2 | +* | ||
3 | +* Function to load forum to modal | ||
4 | +* | ||
5 | +*/ | ||
6 | +function showForum(url, forum_id) { | ||
2 | $.ajax({ | 7 | $.ajax({ |
3 | url: url, | 8 | url: url, |
4 | - data: {'topic': topic}, | 9 | + data: {'forum_id': forum_id}, |
5 | success: function(data) { | 10 | success: function(data) { |
6 | $(".forum_topics").html(data); | 11 | $(".forum_topics").html(data); |
7 | } | 12 | } |
forum/templates/forum/forum_list.html
1 | -{% load i18n permission_tags %} | 1 | +{% load i18n permission_tags list_post %} |
2 | 2 | ||
3 | -{% if foruns|length > 0 %} | 3 | +<div class="comments-list"> |
4 | + <div class="section-heading"> | ||
5 | + <h1>{{ forum }}</h1> | ||
6 | + <h4><b>{% trans 'Description' %}:</b> {{ forum.description }}</h4> | ||
7 | + <h4><b>{% trans 'Opened in' %}:</b> {{ forum.create_date }}</h4> | ||
8 | + </div> | ||
9 | +</div> | ||
10 | + | ||
11 | +{% list_posts request forum %} | ||
12 | + | ||
13 | +<!--{% if foruns|length > 0 %} | ||
4 | {% for forum in foruns %} | 14 | {% for forum in foruns %} |
5 | <a class="forum_collapse" role="button" href="javascript: showPosts('{% url 'forum:posts' %}', '{{ forum.slug }}')" aria-expanded="true"> | 15 | <a class="forum_collapse" role="button" href="javascript: showPosts('{% url 'forum:posts' %}', '{{ forum.slug }}')" aria-expanded="true"> |
6 | <div class="page-header"> | 16 | <div class="page-header"> |
@@ -20,4 +30,4 @@ | @@ -20,4 +30,4 @@ | ||
20 | <div class="page-header"> | 30 | <div class="page-header"> |
21 | <p>{% trans 'No forum created yet.' %}</p> | 31 | <p>{% trans 'No forum created yet.' %}</p> |
22 | </div> | 32 | </div> |
23 | -{% endif %} | 33 | +{% endif %}--> |
forum/templates/post/post_list.html
1 | -{% load i18n permission_tags %} | 1 | +{% load i18n permission_tags list_post_answer %} |
2 | 2 | ||
3 | {% if posts|length > 0 %} | 3 | {% if posts|length > 0 %} |
4 | - <ul class="timeline post"> | ||
5 | - {% for post in posts %} | ||
6 | - <li> | 4 | + {% for post in posts %} |
5 | + <div class="row"> | ||
6 | + <div class="col-sm-12 col-xs-12"> | ||
7 | + <h3 class="user-name"> | ||
8 | + {{ post.user }} | ||
9 | + {% if request.user|has_role:'system_admin' or request.user|has_role:'professor' and request.user == post.user %} | ||
10 | + <div class="pull-right"> | ||
11 | + <div class="btn-group icon-more-horiz"> | ||
12 | + <a class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
13 | + <i class="material-icons">more_horiz</i> | ||
14 | + </a> | ||
15 | + <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> | ||
16 | + <li><a href="javascript:void(0)"><i class="material-icons">create</i> {% trans 'Edit' %}</a></li> | ||
17 | + <li><a href="javascript:void(0)"><i class="material-icons">delete_sweep</i> {% trans 'Remove' %}</a></li> | ||
18 | + </ul> | ||
19 | + </div> | ||
20 | + </div> | ||
21 | + {% endif %} | ||
22 | + </h3> | ||
23 | + <div class="card-data"> | ||
24 | + <p class="comment-date"><i class="fa fa-clock-o"></i> {{ post.post_date }}</p> | ||
25 | + </div> | ||
26 | + <p class="comment-text">{{ post.message|linebreaks }}</p> | ||
27 | + </div> | ||
28 | + </div> | ||
29 | + {% list_post_answer request post %} | ||
30 | + {% endfor %} | ||
31 | +{% endif %} | ||
32 | + <!--<li> | ||
7 | <a class="post_collapse" role="button" href="javascript: showPostsAnswers('{% url 'forum:post_answers' %}', '{{ post.id }}')" aria-expanded="false"> | 33 | <a class="post_collapse" role="button" href="javascript: showPostsAnswers('{% url 'forum:post_answers' %}', '{{ post.id }}')" aria-expanded="false"> |
8 | <div class="timeline-panel"> | 34 | <div class="timeline-panel"> |
9 | <div class="row"> | 35 | <div class="row"> |
@@ -32,9 +58,4 @@ | @@ -32,9 +58,4 @@ | ||
32 | <div class="well"> | 58 | <div class="well"> |
33 | </div> | 59 | </div> |
34 | </div> | 60 | </div> |
35 | - </li> | ||
36 | - {% endfor %} | ||
37 | - </ul> | ||
38 | -{% else %} | ||
39 | - <p>{% trans 'No posts were made yet.' %}</p> | ||
40 | -{% endif %} | ||
41 | \ No newline at end of file | 61 | \ No newline at end of file |
62 | + </li>--> | ||
42 | \ No newline at end of file | 63 | \ No newline at end of file |
forum/templates/post_answers/post_answer_list.html
1 | {% load i18n permission_tags %} | 1 | {% load i18n permission_tags %} |
2 | 2 | ||
3 | {% if answers|length > 0 %} | 3 | {% if answers|length > 0 %} |
4 | - <ul class="timeline post"> | ||
5 | - {% for answer in answers %} | ||
6 | - <li> | ||
7 | - <div class="timeline-panel"> | ||
8 | - <div class="row"> | ||
9 | - <div class="col-xs-2 col-sm-2 col-md-2"> | ||
10 | - <img class="img-responsive img-rounded" src="{{ answer.user.image_url }}" /> | ||
11 | - </div> | ||
12 | - <div class="col-xs-10 col-sm-10 col-md-10"> | ||
13 | - {% if user|has_role:'system_admin' or user|has_role:'professor' and user == forum.topic.owner %} | ||
14 | - <div class="pull-right"> | ||
15 | - <div class="btn-group icon-more-horiz"> | ||
16 | - <a class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
17 | - <i class="material-icons">more_horiz</i> | ||
18 | - </a> | ||
19 | - <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> | ||
20 | - <li><a href="javascript:void(0)"><i class="material-icons">create</i> Edit</a></li> | ||
21 | - <li><a href="javascript:void(0)"><i class="material-icons">delete_sweep</i> Remove</a></li> | ||
22 | - </ul> | ||
23 | - </div> | ||
24 | - </div> | ||
25 | - {% endif %} | ||
26 | - <div class="timeline-heading"> | ||
27 | - <h3> {{ answer.user }}</h3> | ||
28 | - </div> | ||
29 | - <div class="timeline-body"> | ||
30 | - <p><em>{{ answer.message|linebreaks }}</em></p> | 4 | + {% for answer in answers %} |
5 | + <div class="row" style="background-color: #e0e0e0"> | ||
6 | + <div class="col-sm-12 col-xs-12"> | ||
7 | + <h3 class="user-name"> | ||
8 | + {{ answer.user }} | ||
9 | + {% if request.user|has_role:'system_admin' or request.user|has_role:'professor' and request.user == answer.user %} | ||
10 | + <div class="pull-right"> | ||
11 | + <div class="btn-group icon-more-horiz"> | ||
12 | + <a class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
13 | + <i class="material-icons">more_horiz</i> | ||
14 | + </a> | ||
15 | + <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> | ||
16 | + <li><a href="javascript:void(0)"><i class="material-icons">create</i> {% trans 'Edit' %}</a></li> | ||
17 | + <li><a href="javascript:void(0)"><i class="material-icons">delete_sweep</i> {% trans 'Remove' %}</a></li> | ||
18 | + </ul> | ||
31 | </div> | 19 | </div> |
32 | - <hr> | ||
33 | - <small class="text-muted"> | ||
34 | - <span class="pull-right"> | ||
35 | - <i class="glyphicon glyphicon-time"></i> {{ answer.answer_date|timesince }} | ||
36 | - {% trans ' ago' %} | ||
37 | - </span> | ||
38 | - </small> | ||
39 | </div> | 20 | </div> |
40 | - </div> | 21 | + {% endif %} |
22 | + </h3> | ||
23 | + <div class="card-data"> | ||
24 | + <p class="comment-date"><i class="fa fa-clock-o"></i> {{ answer.answer_date|timesince }} {% trans 'ago' %}</p> | ||
41 | </div> | 25 | </div> |
42 | - </li> | ||
43 | - {% endfor %} | ||
44 | - </ul> | ||
45 | -{% else %} | ||
46 | - <p>{% trans 'Nobody answered this post yet.' %}</p> | 26 | + <p class="comment-text">{{ answer.message|linebreaks }}</p> |
27 | + </div> | ||
28 | + </div> | ||
29 | + {% endfor %} | ||
47 | {% endif %} | 30 | {% endif %} |
48 | \ No newline at end of file | 31 | \ No newline at end of file |
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +from django import template | ||
2 | + | ||
3 | +from forum.models import Post | ||
4 | + | ||
5 | +register = template.Library() | ||
6 | + | ||
7 | +""" | ||
8 | + Template tag to load all the posts of a post | ||
9 | +""" | ||
10 | + | ||
11 | +@register.inclusion_tag('post/post_list.html') | ||
12 | +def list_posts(request, forum): | ||
13 | + context = { | ||
14 | + 'request': request, | ||
15 | + } | ||
16 | + | ||
17 | + context['posts'] = Post.objects.filter(forum = forum) | ||
18 | + | ||
19 | + return context | ||
0 | \ No newline at end of file | 20 | \ No newline at end of file |
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +from django import template | ||
2 | + | ||
3 | +from forum.models import PostAnswer | ||
4 | + | ||
5 | +register = template.Library() | ||
6 | + | ||
7 | +""" | ||
8 | + Template tag to load all the posts of a post | ||
9 | +""" | ||
10 | + | ||
11 | +@register.inclusion_tag('post_answers/post_answer_list.html') | ||
12 | +def list_post_answer(request, post): | ||
13 | + context = { | ||
14 | + 'request': request, | ||
15 | + } | ||
16 | + | ||
17 | + context['answers'] = PostAnswer.objects.filter(post = post) | ||
18 | + | ||
19 | + return context | ||
0 | \ No newline at end of file | 20 | \ No newline at end of file |
forum/views.py
@@ -14,12 +14,12 @@ class ForumIndex(LoginRequiredMixin, generic.ListView): | @@ -14,12 +14,12 @@ class ForumIndex(LoginRequiredMixin, generic.ListView): | ||
14 | redirect_field_name = 'next' | 14 | redirect_field_name = 'next' |
15 | 15 | ||
16 | template_name = "forum/forum_list.html" | 16 | template_name = "forum/forum_list.html" |
17 | - context_object_name = 'foruns' | 17 | + context_object_name = 'forum' |
18 | 18 | ||
19 | def get_queryset(self): | 19 | def get_queryset(self): |
20 | - topic = get_object_or_404(Topic, slug = self.request.GET.get('topic', '')) | 20 | + forum_id = self.request.GET.get('forum_id', 0) |
21 | 21 | ||
22 | - context = Forum.objects.filter(topic = topic) | 22 | + context = Forum.objects.get(id = forum_id) |
23 | 23 | ||
24 | return context | 24 | return context |
25 | 25 |