Quellcode durchsuchen

factorisation de la section commentaire

omassot vor 7 Jahren
Ursprung
Commit
051a632b7e

+ 26 - 0
main/templates/_comment_div.html

@@ -0,0 +1,26 @@
+{# section commentaire. prends en parametre un objet Story ou Epic #}
+{# l'objet en parametre doit avoir une propriete 'comments' et une propriete 'uuid' #}
+
+{% load martortags %}
+
+<div class="comment-section">
+	<ul class="alt">
+	{% for comment in obj.comments.all %}
+		<li class="flex-col">
+			<div><h5><i class="fa fa-comment"></i> {{ comment.author }}, le {{ comment.created }}:</h5></b></div>
+			<div class="comment-display">
+				{{ comment.content|safe_markdown }}
+			</div>
+		</li>
+	{% endfor %}
+	</ul>
+	
+	<form action="{% url 'comment' obj_uuid=obj.uuid %}" method="post" accept-charset="utf-8">
+		{% csrf_token %}
+		{{ comment_form.as_p }}
+		
+    	<div class="flex-row flex-end" style="margin-top: 10px;">
+    		<input type="submit">
+    	</div>
+    </form>
+</div>

+ 1 - 21
main/templates/epic_details.html

@@ -57,26 +57,6 @@
 
 	<hr>
 	
-	<div class="comment-section">
-		<ul class="alt">
-		{% for comment in epic.comments.all %}
-			<li class="flex-col">
-				<div><h5><i class="fa fa-comment"></i> {{ comment.author }}, le {{ comment.created }}:</h5></b></div>
-				<div class="comment-display">
-					{{ comment.content|safe_markdown }}
-				</div>
-			</li>
-		{% endfor %}
-		</ul>
-		
-		<form action="{% url 'epic_comment' epic_id=epic.id %}" method="post" accept-charset="utf-8">
-			{% csrf_token %}
-			{{ comment_form.as_p }}
-			
-	    	<div class="flex-row flex-end" style="margin-top: 10px;">
-	    		<input type="submit">
-	    	</div>
-	    </form>
-    </div>
+	{% include '_comment_div.html' with obj=epic %}
     
 {% endblock %}

+ 1 - 21
main/templates/story_details.html

@@ -84,26 +84,6 @@
 	
 	<hr>
 	
-	<div class="comment-section">
-		<ul class="alt">
-		{% for comment in story.comments.all %}
-			<li class="flex-col">
-				<div><h5><i class="fa fa-comment"></i> {{ comment.author }}, le {{ comment.created }}:</h5></b></div>
-				<div class="comment-display">
-					{{ comment.content|safe_markdown }}
-				</div>
-			</li>
-		{% endfor %}
-		</ul>
-		
-		<form action="{% url 'story_comment' story_id=story.id %}" method="post" accept-charset="utf-8">
-			{% csrf_token %}
-			{{ comment_form.as_p }}
-			
-	    	<div class="flex-row flex-end" style="margin-top: 10px;">
-	    		<input type="submit">
-	    	</div>
-	    </form>
-    </div>
+	{% include '_comment_div.html' with obj=story %}
 	
 {% endblock %}

+ 1 - 2
main/urls.py

@@ -22,7 +22,6 @@ urlpatterns = [
     path('stories/delete/<int:story_id>/', views.story_delete, name='story_delete'),
     path('stories/close/<int:story_id>/', views.story_close, name='story_close'),
     path('stories/reopen/<int:story_id>/', views.story_reopen, name='story_reopen'),
-    path('stories/comment/<int:story_id>/', views.story_comment, name='story_comment'),
     path('epics/<int:epic_id>', views.epic_details, name='epic_details'),
     path('epics/create/', views.epic_create, name='epic_create'),
     path('epics/edit/<int:epic_id>/', views.epic_edit, name='epic_edit'),
@@ -31,9 +30,9 @@ urlpatterns = [
     path('epics/newval/<int:epic_id>/', views.epic_value_update, name='epic_value_update'),
     path('epics/close/<int:epic_id>/', views.epic_close, name='epic_close'),
     path('epics/reopen/<int:epic_id>/', views.epic_reopen, name='epic_reopen'),
-    path('epics/comment/<int:epic_id>/', views.epic_comment, name='epic_comment'),
     path('reports/', views.reports, name='reports'),
     path('reports/sprints/', views.report_sprints, name='report_sprints'),
     path('reports/projects/', views.report_projects, name='report_projects'),
+    path('comment/<obj_uuid>/', views.comment, name='comment'),
     path('search/', views.search, name='search'),
 ]

+ 9 - 20
main/views.py

@@ -157,16 +157,6 @@ def story_reopen(request, story_id):
     story.save()
     return render(request, 'story_details.html', {'story': story})
 
-@login_required
-def story_comment(request, story_id):
-    story = get_object_or_404(Story, id=story_id)
-    comment = Comment()
-    comment.obj_uuid = story.uuid
-    comment.author = get_object_or_404(User, username=request.user)
-    comment.content = request.POST["content"]
-    comment.save()
-    return redirect('story_details', story_id)
-
 @login_required
 def epic_details(request, epic_id):
     epic = get_object_or_404(Epic, id=epic_id)
@@ -239,16 +229,6 @@ def epic_reopen(_, epic_id):
     epic.save()
     return redirect("backlog_edition")
 
-@login_required
-def epic_comment(request, epic_id):
-    epic = get_object_or_404(Epic, id=epic_id)
-    comment = Comment()
-    comment.obj_uuid = epic.uuid
-    comment.author = get_object_or_404(User, username=request.user)
-    comment.content = request.POST["content"]
-    comment.save()
-    return redirect('epic_details', epic_id)
-
 @login_required
 def reports(request):
     return render(request, 'reports/report_index.html')
@@ -263,6 +243,15 @@ def report_projects(request):
     epics = Epic.objects.all()
     return render(request, 'reports/report_projects.html', {'epics': epics})
 
+@login_required
+def comment(request, obj_uuid):
+    comment = Comment()
+    comment.obj_uuid = obj_uuid
+    comment.author = get_object_or_404(User, username=request.user)
+    comment.content = request.POST["content"]
+    comment.save()
+    return redirect(request.META['HTTP_REFERER'])
+
 @login_required
 def search(request):
     qstr = request.GET["q"]