Commit 4be136ddb44c6bf344c080c40f88d7ab7bb40ea4

Authored by Zambom
1 parent 61689fc2

Fixing some forum bugs

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
... ... @@ -50,7 +50,7 @@
50 50 {% endblock %}
51 51  
52 52 {% block content %}
53   - <div class="row panel panel-default">
  53 + <div class="panel panel-default">
54 54 <div class="panel-body">
55 55 <div class="comments-list">
56 56 <div class="section-heading forum_view">
... ...
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/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, ))
... ...