diff --git a/forum/static/js/forum.js b/forum/static/js/forum.js
index 0ccd594..244ff27 100644
--- a/forum/static/js/forum.js
+++ b/forum/static/js/forum.js
@@ -212,6 +212,11 @@ function delete_post(url, post) {
});
}
+/*
+*
+* Function to load answer post form and set the submit function
+*
+*/
function answer(id, url) {
$.ajax({
url: url,
@@ -241,4 +246,28 @@ function answer(id, url) {
});
$("#post_"+id).find(".answer_post").show();
+}
+
+/*
+*
+* Function to delete an answer
+*
+*/
+function delete_answer(url, answer, message) {
+ alertify.confirm(message, function(){
+ var csrftoken = getCookie('csrftoken');
+
+ $.ajax({
+ method: 'post',
+ beforeSend: function (request) {
+ request.setRequestHeader('X-CSRFToken', csrftoken);
+ },
+ url: url,
+ success: function(data) {
+ alertify.alert('Amadeus', data, function(){
+ $("#answer_"+answer).remove();
+ });
+ }
+ });
+ });
}
\ No newline at end of file
diff --git a/forum/templates/post_answers/post_answer_list.html b/forum/templates/post_answers/post_answer_list.html
index b634bd2..aeb80e7 100644
--- a/forum/templates/post_answers/post_answer_list.html
+++ b/forum/templates/post_answers/post_answer_list.html
@@ -2,7 +2,7 @@
{% if answers|length > 0 %}
{% for answer in answers %}
-
+
{{ answer.user }}
@@ -14,7 +14,7 @@
diff --git a/forum/templates/post_answers/post_answer_render.html b/forum/templates/post_answers/post_answer_render.html
index 69ea77a..6981968 100644
--- a/forum/templates/post_answers/post_answer_render.html
+++ b/forum/templates/post_answers/post_answer_render.html
@@ -1,6 +1,6 @@
{% load i18n permission_tags %}
-
+
{{ answer.user }}
@@ -12,7 +12,7 @@
diff --git a/forum/urls.py b/forum/urls.py
index a3ad25f..f5b07a6 100644
--- a/forum/urls.py
+++ b/forum/urls.py
@@ -19,5 +19,7 @@ urlpatterns = [
url(r'^post_answers/$', views.PostAnswerIndex.as_view(), name='post_answers'),
url(r'^reply_post/$', views.CreatePostAnswerView.as_view(), name='reply_post'),
url(r'^render_post_answer/([\w_-]+)/$', views.render_post_answer, name='render_post_answer'),
+ url(r'^delete_post_answer/(?P
[\w_-]+)/$', views.PostAnswerDeleteView.as_view(), name='delete_answer'),
+ url(r'^post_answer_deleted/$', views.answer_deleted, name='deleted_answer'),
url(r'^(?P[\w_-]+)/$', views.ForumDetailView.as_view(), name='view'),
]
diff --git a/forum/views.py b/forum/views.py
index 572da42..58c0ae1 100644
--- a/forum/views.py
+++ b/forum/views.py
@@ -208,4 +208,15 @@ def render_post_answer(request, answer):
context = {}
context['answer'] = last_answer
- return render(request, "post_answers/post_answer_render.html", context)
\ No newline at end of file
+ return render(request, "post_answers/post_answer_render.html", context)
+
+class PostAnswerDeleteView(LoginRequiredMixin, generic.DeleteView):
+ login_url = reverse_lazy("core:home")
+ redirect_field_name = 'next'
+
+ model = PostAnswer
+ pk_url_kwarg = 'pk'
+ success_url = reverse_lazy('course:forum:deleted_answer')
+
+def answer_deleted(request):
+ return HttpResponse(_("Post answer deleted successfully."))
\ No newline at end of file
--
libgit2 0.21.2