Commit c919fcb774e01371e69816e5ed9d2459f3471f98
Exists in
master
and in
5 other branches
Merge branch 'dev' of https://github.com/amadeusproject/amadeuslms into dev
Showing
8 changed files
with
146 additions
and
66 deletions
Show diff stats
forum/static/js/forum.js
... | ... | @@ -46,7 +46,7 @@ $(document).ready(function (){ |
46 | 46 | |
47 | 47 | /* |
48 | 48 | * |
49 | -* Function to load create forum's form and set the submit function | |
49 | +* Function to load create forum's form | |
50 | 50 | * |
51 | 51 | */ |
52 | 52 | function createForum(url, topic) { |
... | ... | @@ -57,35 +57,45 @@ function createForum(url, topic) { |
57 | 57 | $(".forum_form").html(data); |
58 | 58 | $("#id_topic").val(topic); |
59 | 59 | |
60 | - $('.date-picker').datepicker({ | |
61 | - format: 'dd/mm/yyyy', | |
62 | - }); | |
60 | + setForumCreateFormSubmit(); | |
61 | + } | |
62 | + }); | |
63 | 63 | |
64 | - var frm = $('#forum_create'); | |
65 | - frm.submit(function () { | |
66 | - $.ajax({ | |
67 | - type: frm.attr('method'), | |
68 | - url: frm.attr('action'), | |
69 | - data: frm.serialize(), | |
70 | - success: function (data) { | |
71 | - data = data.split('-'); | |
64 | + $("#createForum").modal(); | |
65 | +} | |
72 | 66 | |
73 | - $('.foruns_list').append("<a id='forum_"+data[1]+"' href='"+data[0]+"'>"+data[2]+"<br /></a>"); | |
67 | +/* | |
68 | +* | |
69 | +* Function to set the forum's create form submit function | |
70 | +* | |
71 | +*/ | |
72 | +function setForumCreateFormSubmit() { | |
73 | + $('.date-picker').datepicker({ | |
74 | + format: 'dd/mm/yyyy', | |
75 | + }); | |
74 | 76 | |
75 | - $("#createForum").modal('hide'); | |
77 | + var frm = $('#forum_create'); | |
78 | + frm.submit(function () { | |
79 | + $.ajax({ | |
80 | + type: frm.attr('method'), | |
81 | + url: frm.attr('action'), | |
82 | + data: frm.serialize(), | |
83 | + success: function (data) { | |
84 | + data = data.split('-'); | |
76 | 85 | |
77 | - showForum(data[0], data[1]); | |
78 | - }, | |
79 | - error: function(data) { | |
80 | - $(".forum_form").html(data.responseText); | |
81 | - } | |
82 | - }); | |
83 | - return false; | |
84 | - }); | |
85 | - } | |
86 | - }); | |
86 | + $('.foruns_list').append("<a id='forum_"+data[1]+"' href='"+data[0]+"'>"+data[2]+"<br /></a>"); | |
87 | 87 | |
88 | - $("#createForum").modal(); | |
88 | + $("#createForum").modal('hide'); | |
89 | + | |
90 | + showForum(data[0], data[1]); | |
91 | + }, | |
92 | + error: function(data) { | |
93 | + $(".forum_form").html(data.responseText); | |
94 | + setForumCreateFormSubmit(); | |
95 | + } | |
96 | + }); | |
97 | + return false; | |
98 | + }); | |
89 | 99 | } |
90 | 100 | |
91 | 101 | /* |
... | ... | @@ -100,29 +110,7 @@ function editForum(url, forum, success_message) { |
100 | 110 | success: function(data) { |
101 | 111 | $(".forum_form").html(data); |
102 | 112 | |
103 | - $('.date-picker').datepicker({ | |
104 | - format: 'dd/mm/yyyy', | |
105 | - }); | |
106 | - | |
107 | - var frm = $('#forum_create'); | |
108 | - frm.submit(function () { | |
109 | - $.ajax({ | |
110 | - type: frm.attr('method'), | |
111 | - url: frm.attr('action'), | |
112 | - data: frm.serialize(), | |
113 | - success: function (data) { | |
114 | - $('.forum_view').html(data); | |
115 | - | |
116 | - alertify.success(success_message); | |
117 | - | |
118 | - $("#editForum").modal('hide'); | |
119 | - }, | |
120 | - error: function(data) { | |
121 | - $(".forum_form").html(data.responseText); | |
122 | - } | |
123 | - }); | |
124 | - return false; | |
125 | - }); | |
113 | + setForumUpdateFormSubmit(success_message); | |
126 | 114 | } |
127 | 115 | }); |
128 | 116 | |
... | ... | @@ -131,6 +119,39 @@ function editForum(url, forum, success_message) { |
131 | 119 | |
132 | 120 | /* |
133 | 121 | * |
122 | +* Function to set the forum's update form submit function | |
123 | +* | |
124 | +*/ | |
125 | +function setForumUpdateFormSubmit(success_message) { | |
126 | + $('.date-picker').datepicker({ | |
127 | + format: 'dd/mm/yyyy', | |
128 | + }); | |
129 | + | |
130 | + var frm = $('#forum_create'); | |
131 | + frm.submit(function () { | |
132 | + $.ajax({ | |
133 | + type: frm.attr('method'), | |
134 | + url: frm.attr('action'), | |
135 | + data: frm.serialize(), | |
136 | + success: function (data) { | |
137 | + $('.forum_view').html(data); | |
138 | + | |
139 | + alertify.success(success_message); | |
140 | + | |
141 | + $("#editForum").modal('hide'); | |
142 | + }, | |
143 | + error: function(data) { | |
144 | + $(".forum_form").html(data.responseText); | |
145 | + | |
146 | + setForumUpdateFormSubmit(success_message); | |
147 | + } | |
148 | + }); | |
149 | + return false; | |
150 | + }); | |
151 | +} | |
152 | + | |
153 | +/* | |
154 | +* | |
134 | 155 | * Function to delete a forum |
135 | 156 | * |
136 | 157 | */ | ... | ... |
forum/templates/forum/forum_view.html
forum/templates/post/post_list.html
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | <a class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
17 | 17 | <i class="material-icons">more_horiz</i> |
18 | 18 | </a> |
19 | - <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> | |
19 | + <ul class="dropdown-menu pull-right" aria-labelledby="dropdownMenu1"> | |
20 | 20 | <li><a href="javascript:edit_post('{% url 'course:forum:update_post' post.id %}', '{{ post.id }}', '{% trans 'Post edited successfully!' %}')"><i class="material-icons">create</i> {% trans 'Edit' %}</a></li> |
21 | 21 | <li><a href="javascript:javascript:delete_post('{% url 'course:forum:delete_post' post.id %}', '{{ post.id }}')"><i class="material-icons">delete_sweep</i> {% trans 'Remove' %}</a></li> |
22 | 22 | </ul> | ... | ... |
forum/templates/post/post_render.html
... | ... | @@ -14,7 +14,7 @@ |
14 | 14 | <a class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
15 | 15 | <i class="material-icons">more_horiz</i> |
16 | 16 | </a> |
17 | - <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> | |
17 | + <ul class="dropdown-menu pull-right" aria-labelledby="dropdownMenu1"> | |
18 | 18 | <li><a href="javascript:edit_post('{% url 'course:forum:update_post' post.id %}', '{{ post.id }}', '{% trans 'Post edited successfully!' %}')"></li> |
19 | 19 | <li><a href="javascript:delete_post('{% url 'course:forum:delete_post' post.id %}', '{{ post.id }}')"><i class="material-icons">delete_sweep</i> {% trans 'Remove' %}</a></li> |
20 | 20 | </ul> | ... | ... |
forum/templates/post_answers/post_answer_list.html
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | <a class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
14 | 14 | <i class="material-icons">more_horiz</i> |
15 | 15 | </a> |
16 | - <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> | |
16 | + <ul class="dropdown-menu pull-right" aria-labelledby="dropdownMenu1"> | |
17 | 17 | <li><a href="javascript:edit_post_answer('{% url 'course:forum:update_post_answer' answer.id %}', '{{ answer.id }}', '{% trans 'Answer edited sucessfully!' %}')"><i class="material-icons">create</i> {% trans 'Edit' %}</a></li> |
18 | 18 | <li><a href="javascript:delete_answer('{% url 'course:forum:delete_answer' answer.id %}', '{{ answer.id }}', '{% trans "Are you sure you want to delete this answer?" %}')"><i class="material-icons">delete_sweep</i> {% trans 'Remove' %}</a></li> |
19 | 19 | </ul> | ... | ... |
forum/templates/post_answers/post_answer_render.html
... | ... | @@ -11,7 +11,7 @@ |
11 | 11 | <a class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
12 | 12 | <i class="material-icons">more_horiz</i> |
13 | 13 | </a> |
14 | - <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> | |
14 | + <ul class="dropdown-menu pull-right" aria-labelledby="dropdownMenu1"> | |
15 | 15 | <li><a href="javascript:edit_post_answer('{% url 'course:forum:update_post_answer' answer.id %}', '{{ answer.id }}', '{% trans 'Answer edited sucessfully!' %}')"><i class="material-icons">create</i> {% trans 'Edit' %}</a></li> |
16 | 16 | <li><a href="javascript:delete_answer('{% url 'course:forum:delete_answer' answer.id %}', '{{ answer.id }}', '{% trans "Are you sure you want to delete this answer?" %}')"><i class="material-icons">delete_sweep</i> {% trans 'Remove' %}</a></li> |
17 | 17 | </ul> | ... | ... |
forum/tests/test_view_forum.py
... | ... | @@ -4,10 +4,10 @@ from django.core.urlresolvers import reverse |
4 | 4 | from rolepermissions.shortcuts import assign_role |
5 | 5 | |
6 | 6 | from users.models import User |
7 | -from courses.models import Category, Course, Subject, Topic | |
7 | +from courses.models import CourseCategory, Course, Subject, Topic | |
8 | 8 | from forum.models import Forum |
9 | 9 | |
10 | -class ForumDetailViewTestCase (TestCase): | |
10 | +class ForumViewTestCase (TestCase): | |
11 | 11 | |
12 | 12 | def setUp(self): |
13 | 13 | self.client = Client() |
... | ... | @@ -21,7 +21,7 @@ class ForumDetailViewTestCase (TestCase): |
21 | 21 | ) |
22 | 22 | assign_role(self.user, 'system_admin') |
23 | 23 | |
24 | - self.category = Category.objects.create( | |
24 | + self.category = CourseCategory.objects.create( | |
25 | 25 | name = 'Category test', |
26 | 26 | slug = 'category_test' |
27 | 27 | ) |
... | ... | @@ -69,22 +69,78 @@ class ForumDetailViewTestCase (TestCase): |
69 | 69 | ) |
70 | 70 | self.forum.save() |
71 | 71 | |
72 | - self.url = reverse('course:forum:view', kwargs={'slug':self.forum.slug}) | |
73 | - | |
74 | - def test_view_ok (self): | |
72 | + | |
75 | 73 | self.client.login(username='test', password='testing') |
74 | + self.index_url = reverse('course:forum:view', kwargs={'slug':self.forum.slug}) | |
75 | + self.create_url = reverse('course:forum:create') | |
76 | + self.update_url = reverse('course:forum:update', kwargs={'pk':self.forum.pk}) | |
77 | + | |
78 | +######################### ForumDetailView ######################### | |
76 | 79 | |
77 | - response = self.client.get(self.url) | |
80 | + def test_ForumDetail_view_ok (self): | |
81 | + response = self.client.get(self.index_url) | |
78 | 82 | self.assertEquals(response.status_code, 200) |
79 | 83 | self.assertTemplateUsed(response, 'forum/forum_view.html') |
80 | 84 | |
81 | - def test_context(self): | |
82 | - self.client.login(username='test', password='testing') | |
85 | + def test_ForumDetail_context(self): | |
86 | + response = self.client.get(self.index_url) | |
87 | + self.assertTrue('forum' in response.context) | |
83 | 88 | |
84 | - response = self.client.get(self.url) | |
89 | +######################### CreateForumView ######################### | |
90 | + | |
91 | + def test_CreateForum_view_ok (self): | |
92 | + response = self.client.get(self.create_url) | |
93 | + self.assertEquals(response.status_code, 200) | |
94 | + self.assertTemplateUsed(response, 'forum/forum_form.html') | |
85 | 95 | |
96 | + def test_CreateForum_context(self): | |
97 | + response = self.client.get(self.create_url) | |
86 | 98 | self.assertTrue('form' in response.context) |
87 | - self.assertTrue('forum' in response.context) | |
88 | - self.assertTrue('title' in response.context) | |
89 | 99 | |
100 | + def test_CreateForum_form_error (self): | |
101 | + data = {'name':'', 'limit_date': '', 'description':'', 'topic':''} | |
102 | + response = self.client.post(self.create_url, data) | |
103 | + self.assertEquals (response.status_code, 400) | |
104 | + | |
105 | + def test_CreateForum_form_ok (self): | |
106 | + data = { | |
107 | + 'name':'Forum Test2', | |
108 | + 'limit_date': '2017-10-05', | |
109 | + 'description':'Test', | |
110 | + 'topic':str(self.topic.id) | |
111 | + } | |
112 | + | |
113 | + response = self.client.post(self.create_url, data) | |
114 | + self.assertEquals (response.status_code, 302) | |
115 | + | |
116 | + forum = Forum.objects.get(name='Forum Test2') | |
117 | + | |
118 | +######################### UpdateForumView ######################### | |
119 | + | |
120 | + def test_UpdateForum_view_ok (self): | |
121 | + response = self.client.get(self.update_url) | |
122 | + self.assertEquals(response.status_code, 200) | |
123 | + self.assertTemplateUsed(response, 'forum/forum_form.html') | |
124 | + | |
125 | + def test_UpdateForum_context(self): | |
126 | + response = self.client.get(self.update_url) | |
127 | + self.assertTrue('form' in response.context) | |
128 | + | |
129 | + def test_UpdateForum_form_error (self): | |
130 | + data = {'name':'', 'limit_date': '', 'description':''} | |
131 | + | |
132 | + response = self.client.post(self.update_url, data) | |
133 | + self.assertEquals (response.status_code, 400) | |
134 | + | |
135 | + def test_UpdateForum_form_ok (self): | |
136 | + data = { | |
137 | + 'name':'Forum Updated', | |
138 | + 'limit_date': '2017-10-05', | |
139 | + 'description':'Test', | |
140 | + 'topic':str(self.topic.id) | |
141 | + } | |
142 | + | |
143 | + response = self.client.post(self.update_url, data) | |
144 | + self.assertEquals (response.status_code, 302) | |
90 | 145 | |
146 | + forum = Forum.objects.get(name='Forum Updated') | |
91 | 147 | \ No newline at end of file | ... | ... |
forum/views.py
... | ... | @@ -44,7 +44,10 @@ class CreateForumView(LoginRequiredMixin, generic.edit.CreateView): |
44 | 44 | form_class = ForumForm |
45 | 45 | |
46 | 46 | def form_invalid(self, form): |
47 | - return self.render_to_response(self.get_context_data(form = form), status = 400) | |
47 | + context = super(CreateForumView, self).form_invalid(form) | |
48 | + context.status_code = 400 | |
49 | + | |
50 | + return context | |
48 | 51 | |
49 | 52 | def get_success_url(self): |
50 | 53 | self.success_url = reverse('course:forum:render_forum', args = (self.object.id, )) | ... | ... |