Commit 4be136ddb44c6bf344c080c40f88d7ab7bb40ea4
1 parent
61689fc2
Exists in
master
and in
5 other branches
Fixing some forum bugs
Showing
7 changed files
with
78 additions
and
54 deletions
Show diff stats
forum/static/js/forum.js
| @@ -46,7 +46,7 @@ $(document).ready(function (){ | @@ -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 | function createForum(url, topic) { | 52 | function createForum(url, topic) { |
| @@ -57,35 +57,45 @@ function createForum(url, topic) { | @@ -57,35 +57,45 @@ function createForum(url, topic) { | ||
| 57 | $(".forum_form").html(data); | 57 | $(".forum_form").html(data); |
| 58 | $("#id_topic").val(topic); | 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,29 +110,7 @@ function editForum(url, forum, success_message) { | ||
| 100 | success: function(data) { | 110 | success: function(data) { |
| 101 | $(".forum_form").html(data); | 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,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 | * Function to delete a forum | 155 | * Function to delete a forum |
| 135 | * | 156 | * |
| 136 | */ | 157 | */ |
forum/templates/forum/forum_view.html
| @@ -50,7 +50,7 @@ | @@ -50,7 +50,7 @@ | ||
| 50 | {% endblock %} | 50 | {% endblock %} |
| 51 | 51 | ||
| 52 | {% block content %} | 52 | {% block content %} |
| 53 | - <div class="row panel panel-default"> | 53 | + <div class="panel panel-default"> |
| 54 | <div class="panel-body"> | 54 | <div class="panel-body"> |
| 55 | <div class="comments-list"> | 55 | <div class="comments-list"> |
| 56 | <div class="section-heading forum_view"> | 56 | <div class="section-heading forum_view"> |
forum/templates/post/post_list.html
| @@ -16,7 +16,7 @@ | @@ -16,7 +16,7 @@ | ||
| 16 | <a class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | 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> | 17 | <i class="material-icons">more_horiz</i> |
| 18 | </a> | 18 | </a> |
| 19 | - <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> | 19 | + <ul class="dropdown-menu pull-right" aria-labelledby="dropdownMenu1"> |
| 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> | 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 | <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> | 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 | </ul> | 22 | </ul> |
forum/templates/post/post_render.html
| @@ -14,7 +14,7 @@ | @@ -14,7 +14,7 @@ | ||
| 14 | <a class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | 14 | <a class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
| 15 | <i class="material-icons">more_horiz</i> | 15 | <i class="material-icons">more_horiz</i> |
| 16 | </a> | 16 | </a> |
| 17 | - <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> | 17 | + <ul class="dropdown-menu pull-right" aria-labelledby="dropdownMenu1"> |
| 18 | <li><a href="javascript:edit_post('{% url 'course:forum:update_post' post.id %}', '{{ post.id }}', '{% trans 'Post edited successfully!' %}')"></li> | 18 | <li><a href="javascript:edit_post('{% url 'course:forum:update_post' post.id %}', '{{ post.id }}', '{% trans 'Post edited successfully!' %}')"></li> |
| 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> | 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 | </ul> | 20 | </ul> |
forum/templates/post_answers/post_answer_list.html
| @@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
| 13 | <a class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | 13 | <a class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
| 14 | <i class="material-icons">more_horiz</i> | 14 | <i class="material-icons">more_horiz</i> |
| 15 | </a> | 15 | </a> |
| 16 | - <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> | 16 | + <ul class="dropdown-menu pull-right" aria-labelledby="dropdownMenu1"> |
| 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> | 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 | <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> | 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 | </ul> | 19 | </ul> |
forum/templates/post_answers/post_answer_render.html
| @@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
| 11 | <a class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | 11 | <a class="btn btn-default btn-xs dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
| 12 | <i class="material-icons">more_horiz</i> | 12 | <i class="material-icons">more_horiz</i> |
| 13 | </a> | 13 | </a> |
| 14 | - <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> | 14 | + <ul class="dropdown-menu pull-right" aria-labelledby="dropdownMenu1"> |
| 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> | 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 | <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> | 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 | </ul> | 17 | </ul> |
forum/views.py
| @@ -44,7 +44,10 @@ class CreateForumView(LoginRequiredMixin, generic.edit.CreateView): | @@ -44,7 +44,10 @@ class CreateForumView(LoginRequiredMixin, generic.edit.CreateView): | ||
| 44 | form_class = ForumForm | 44 | form_class = ForumForm |
| 45 | 45 | ||
| 46 | def form_invalid(self, form): | 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 | def get_success_url(self): | 52 | def get_success_url(self): |
| 50 | self.success_url = reverse('course:forum:render_forum', args = (self.object.id, )) | 53 | self.success_url = reverse('course:forum:render_forum', args = (self.object.id, )) |