+ {{ post.post_date }} + {% if post.is_modified %} + - {% trans 'Edited' %} + {% endif %} +
+{{ post.message|linebreaks }}
diff --git a/forum/models.py b/forum/models.py index fa9f4d0..834972f 100644 --- a/forum/models.py +++ b/forum/models.py @@ -41,6 +41,15 @@ class Post(models.Model): def __str__(self): return ''.join([self.user.name, " / ", str(self.post_date)]) + def is_modified(self): + create = self.post_date.strftime("%Y-%m-%d %H:%M:%S") + edit = self.modification_date.strftime("%Y-%m-%d %H:%M:%S") + + if create != edit: + return True + + return False + """ It represents an answer to a forum's post """ diff --git a/forum/static/js/forum.js b/forum/static/js/forum.js index a95b380..5a54c88 100644 --- a/forum/static/js/forum.js +++ b/forum/static/js/forum.js @@ -50,6 +50,54 @@ function showForum(url, forum_id) { $('#forumModal').modal(); } +/* +* +* Function to load form to edit post +* +*/ +function edit_post(url, post_id) { + $.ajax({ + url: url, + success: function(data) { + $("#post_"+post_id).find(".post_content").hide(); + $("#post_"+post_id).find(".post_content").after(data); + + var frm = $("#post_"+post_id).find(".edit_post_form"); + frm.submit(function () { + $.ajax({ + type: frm.attr('method'), + url: frm.attr('action'), + data: frm.serialize(), + success: function (data) { + $("#post_"+post_id).parent().after(data); + frm.parent().parent().remove(); + }, + error: function(data) { + console.log(frm.serialize()); + console.log('Error'); + } + }); + return false; + }); + } + }); +} + +/* +* +* Function to cancel post edition +* +*/ +function cancelEditPost(post_id) { + $("#post_"+post_id).find(".post_content").show(); + $("#post_"+post_id).find(".edit_post_form").remove(); +} + +/* +* +* Function to delete a post +* +*/ function delete_post(url, post) { var csrftoken = getCookie('csrftoken'); @@ -74,36 +122,4 @@ function answer(id, url) { }); $("#post_"+id).find(".answer_post").show(); -} - -function showPosts(url, forum) { - if ($("#collapse" + forum).hasClass('in')) { - $("#collapse" + forum).collapse('hide'); - } else { - $.ajax({ - url: url, - data: {'forum': forum}, - success: function(data) { - $("#collapse" + forum).find(".well").html(data); - } - }); - - $("#collapse" + forum).collapse('show'); - } -} - -function showPostsAnswers(url, post) { - if ($("#collapse" + post).hasClass('in')) { - $("#collapse" + post).collapse('hide'); - } else { - $.ajax({ - url: url, - data: {'post': post}, - success: function(data) { - $("#collapse" + post).find(".well").html(data); - } - }); - - $("#collapse" + post).collapse('show'); - } } \ No newline at end of file diff --git a/forum/templates/post/post_list.html b/forum/templates/post/post_list.html index ee4066e..97bc858 100644 --- a/forum/templates/post/post_list.html +++ b/forum/templates/post/post_list.html @@ -17,17 +17,24 @@ more_horiz
{% endif %} -{{ post.post_date }}
++ {{ post.post_date }} + {% if post.is_modified %} + - {% trans 'Edited' %} + {% endif %} +
+{{ post.message|linebreaks }}
{{ post.message|linebreaks }}
{{ post.post_date }}
++ {{ post.post_date }} + {% if post.post_date != post.modifiction_date %} + - {% trans 'Edited' %} + {% endif %} +
+{{ post.message|linebreaks }}
{{ post.message|linebreaks }}