Przeglądaj źródła

système de commentaires ok

omassot 7 lat temu
rodzic
commit
17056ec86f

+ 10 - 3
main/static/css/custom.css

@@ -52,6 +52,13 @@
     display: none;
     display: none;
 }
 }
 
 
+a.anchor {
+    display: block;
+    position: relative;
+    top: -100px;
+    visibility: hidden;
+}
+
 @media screen and (max-width: 1280px) {
 @media screen and (max-width: 1280px) {
 	.hide-on-small-screen {
 	.hide-on-small-screen {
 		display: none;
 		display: none;
@@ -275,11 +282,11 @@ select[multiple] option {
 	font-weight: 700;
 	font-weight: 700;
 }
 }
 
 
-.comment-section {
+#comment-section {
 	margin: 0 2.5%; 
 	margin: 0 2.5%; 
 }
 }
 
 
-.comment-section .martor-field-content {
+#comment-section .martor-field {
 	height: 50px;
 	height: 50px;
 }
 }
 
 
@@ -298,7 +305,7 @@ select[multiple] option {
 	padding: 0.5em 0;
 	padding: 0.5em 0;
 }
 }
 
 
-.comment-section .comment-display {
+#comment-section .comment-display {
 	border-left: solid 2px #d3c5c5;
 	border-left: solid 2px #d3c5c5;
 	padding: 5px 20px;
 	padding: 5px 20px;
 	margin: 10px;
 	margin: 10px;

+ 29 - 6
main/templates/_comment_div.html

@@ -3,28 +3,43 @@
 
 
 {% load martortags %}
 {% load martortags %}
 
 
-<div class="comment-section">
+<a class="anchor" id="a-comment-section"></a>
+<div id="comment-section">
 	<ul class="comment-list">
 	<ul class="comment-list">
-	{% for comment in obj.comments %}
-		<li class="comment flex-col" data-id="{{ comment.id }}">
+	{% for comment, frm in com_pack.comments.items %}
+		<li class="comment flex-col anchor" id="comment-{{ comment.id }}" data-id="{{ comment.id }}">
+			<a class="anchor" id="a-comment-{{ comment.id }}"></a>
 			<div class="flex-row">
 			<div class="flex-row">
 				<span class="comment-header"><i class="fa fa-comment"></i> {{ comment.author }}, le {{ comment.created }}</span>
 				<span class="comment-header"><i class="fa fa-comment"></i> {{ comment.author }}, le {{ comment.created }}</span>
 				{% if comment.author.id == request.user.id %}
 				{% if comment.author.id == request.user.id %}
-				    <a class="disabled comment-edit-btn" href="" style="margin-left: 20px;"><i class="fa fa-pencil"></i></a>
+				    <a class="comment-edit-btn" href="" style="margin-left: 20px;"><i class="fa fa-pencil"></i></a>
 					<a class="comment-del-btn" href="{% url 'comment_del' comment_id=comment.id %}" style="margin-left: 10px;"><i class="fa fa-trash"></i></a>
 					<a class="comment-del-btn" href="{% url 'comment_del' comment_id=comment.id %}" style="margin-left: 10px;"><i class="fa fa-trash"></i></a>
 				{% endif %}
 				{% endif %}
 			</div>
 			</div>
 			<div class="comment-display">
 			<div class="comment-display">
 				{{ comment.content|safe_markdown }}
 				{{ comment.content|safe_markdown }}
 			</div>
 			</div>
+			
+			<div class="comment-edition" style="display: none;">
+				<form action="{% url 'comment_edit' comment_id=comment.id %}" method="post" accept-charset="utf-8" enctype="multipart/form-data">
+					{% csrf_token %}
+					
+					{{ frm.content }}
+					
+			    	<div class="flex-row flex-end" style="margin-top: 10px;">
+			    		<a href="" class="comment-edition-cancel" style="margin-right: 20px;">Annuler</a>
+			    		<input type="submit">
+			    	</div>
+			    </form>
+			</div>
 	    </li>
 	    </li>
 	{% endfor %}
 	{% endfor %}
 	</ul>
 	</ul>
 	
 	
-	<form action="{% url 'comment_post' obj_uuid=obj.uuid %}" method="post" accept-charset="utf-8" enctype="multipart/form-data">
+	<form action="{% url 'comment_post' obj_uuid=com_pack.obj.uuid %}" method="post" accept-charset="utf-8" enctype="multipart/form-data">
 		{% csrf_token %}
 		{% csrf_token %}
 		
 		
-		{{ comment_form.as_p }}
+		{{ com_pack.empty_form.as_p }}
 		
 		
     	<div class="flex-row flex-end" style="margin-top: 10px;">
     	<div class="flex-row flex-end" style="margin-top: 10px;">
     		<input type="submit">
     		<input type="submit">
@@ -34,6 +49,14 @@
 </div>
 </div>
 
 
 <script>
 <script>
+	
+	$(".comment-edit-btn, .comment-edition-cancel").click(function (event) {
+		event.preventDefault();
+		var comment_li = $(this).closest('.comment');
+		comment_li.find('.comment-edition').toggle();
+		comment_li.find('.comment-display').toggle();
+	});
+	
 	$(".comment-del-btn").click(function (event) {
 	$(".comment-del-btn").click(function (event) {
 		if (confirm('Êtes vous sûr de vouloir supprimer le commentaire?')) {
 		if (confirm('Êtes vous sûr de vouloir supprimer le commentaire?')) {
 			return true;
 			return true;

+ 1 - 1
main/templates/epic_details.html

@@ -57,6 +57,6 @@
 
 
 	<hr>
 	<hr>
 	
 	
-	{% include '_comment_div.html' with obj=epic %}
+	{% include '_comment_div.html' with com_pack=com_pack %}
     
     
 {% endblock %}
 {% endblock %}

+ 1 - 0
main/urls.py

@@ -36,6 +36,7 @@ urlpatterns = [
     path('reports/sprints/', views.report_sprints, name='report_sprints'),
     path('reports/sprints/', views.report_sprints, name='report_sprints'),
     path('reports/projects/', views.report_projects, name='report_projects'),
     path('reports/projects/', views.report_projects, name='report_projects'),
     path('comment-post/<obj_uuid>/', views.comment_post, name='comment_post'),
     path('comment-post/<obj_uuid>/', views.comment_post, name='comment_post'),
+    path('comment-edit/<int:comment_id>/', views.comment_edit, name='comment_edit'),
     path('comment-del/<int:comment_id>/', views.comment_del, name='comment_del'),
     path('comment-del/<int:comment_id>/', views.comment_del, name='comment_del'),
     path('search/', views.search, name='search'),
     path('search/', views.search, name='search'),
 ]
 ]

+ 19 - 5
main/views.py

@@ -112,7 +112,7 @@ def story_index(request):
 @login_required
 @login_required
 def story_details(request, story_id):
 def story_details(request, story_id):
     story = get_object_or_404(Story, id=story_id)
     story = get_object_or_404(Story, id=story_id)
-    return render(request, 'story_details.html', {'story': story, 'comment_form': CommentForm()})
+    return render(request, 'story_details.html', {'story': story, 'com_pack': com_pack(story)})
 
 
 @login_required
 @login_required
 def story_create(request, epic_id=None):
 def story_create(request, epic_id=None):
@@ -187,7 +187,7 @@ def story_reopen(request, story_id):
 @login_required
 @login_required
 def epic_details(request, epic_id):
 def epic_details(request, epic_id):
     epic = get_object_or_404(Epic, id=epic_id)
     epic = get_object_or_404(Epic, id=epic_id)
-    return render(request, 'epic_details.html', {'epic': epic, 'comment_form': CommentForm()})
+    return render(request, 'epic_details.html', {'epic': epic, 'com_pack': com_pack(epic)})
 
 
 @login_required
 @login_required
 def epic_create(request):
 def epic_create(request):
@@ -269,20 +269,34 @@ def report_projects(request):
     epics = Epic.objects.all()
     epics = Epic.objects.all()
     return render(request, 'reports/report_projects.html', {'epics': epics})
     return render(request, 'reports/report_projects.html', {'epics': epics})
 
 
+def com_pack(obj):
+    pack = {}
+    pack['obj'] = obj
+    pack['comments'] = {c: CommentForm(instance=c, prefix="{}".format(c.id)) for c in obj.comments()}
+    pack['empty_form'] = CommentForm(prefix="new")
+    return pack
+
 @login_required
 @login_required
 def comment_post(request, obj_uuid):
 def comment_post(request, obj_uuid):
     comment = Comment()
     comment = Comment()
     comment.obj_uuid = obj_uuid
     comment.obj_uuid = obj_uuid
     comment.author = get_object_or_404(User, username=request.user)
     comment.author = get_object_or_404(User, username=request.user)
-    comment.content = request.POST["content"]
+    comment.content = request.POST["new-content"]
     comment.save()
     comment.save()
-    return redirect(request.META['HTTP_REFERER'])
+    return redirect(request.META['HTTP_REFERER'].split("#")[0] + "#a-comment-{}".format(comment.id))
 
 
+@login_required
+def comment_edit(request, comment_id):
+    comment = get_object_or_404(Comment, id=comment_id)
+    comment.content = request.POST["{}-content".format(comment_id)]
+    comment.save()
+    return redirect(request.META['HTTP_REFERER'].split("#")[0] + "#a-comment-{}".format(comment.id))
+    
 @login_required
 @login_required
 def comment_del(request, comment_id):
 def comment_del(request, comment_id):
     comment = get_object_or_404(Comment, id=comment_id)
     comment = get_object_or_404(Comment, id=comment_id)
     comment.delete()
     comment.delete()
-    return redirect(request.META['HTTP_REFERER'])
+    return redirect(request.META['HTTP_REFERER'].split("#")[0] + "#a-comment-section")
 
 
 @login_required
 @login_required
 def search(request):
 def search(request):