-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2049 from laws-africa/comments
Comments in admin area for documents
- Loading branch information
Showing
9 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ | |
"corsheaders", | ||
"django_htmx", | ||
"django_recaptcha", | ||
"django_comments", | ||
] | ||
|
||
MIDDLEWARE = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{% load comments %} | ||
{% get_comment_form for object as comment_form %} | ||
<form action="{% comment_form_target %}" | ||
method="post" | ||
id="comment-form" | ||
hx-post="{% comment_form_target %}" | ||
hx-target="#comments-list"> | ||
{% csrf_token %} | ||
<input type="hidden" | ||
name="next" | ||
value="{% url 'comment_form' app_label model_name object.pk %}"/> | ||
{{ comment_form.content_type }} | ||
{{ comment_form.object_pk }} | ||
{{ comment_form.timestamp }} | ||
{{ comment_form.security_hash }} | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{% include 'admin/_comments_list.html' %} | ||
<div hx-swap-oob="comments-form-wrapper">{% include 'admin/_comments_form.html' %}</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{% load comments i18n humanize %} | ||
<ol class="list-unstyled"> | ||
{% get_comment_list for object as comment_list %} | ||
{% for comment in comment_list %} | ||
<li class="mb-3"> | ||
<div> | ||
<b>{{ comment.user }}</b> {{ comment.submit_date|naturaltime }}: | ||
</div> | ||
<div>{{ comment.comment|linebreaks }}</div> | ||
</li> | ||
{% endfor %} | ||
</ol> | ||
<textarea name="comment" | ||
rows="3" | ||
maxlength="3000" | ||
required | ||
class="form-control mt-3 mb-2" | ||
form="comment-form"></textarea> | ||
<button type="submit" class="btn btn-primary" form="comment-form">{% trans "Add comment" %}</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
{% extends "admin/change_form.html" %} | ||
{% load i18n %} | ||
{% load i18n comments humanize static %} | ||
{% block extra_actions %} | ||
{{ block.super }} | ||
{% if PEACHJAM_SETTINGS.editor_help_link and adminform.model_admin.help_topic %} | ||
<a target="_blank" | ||
href="{{ PEACHJAM_SETTINGS.editor_help_link }}{{ adminform.model_admin.help_topic }}" | ||
class="btn btn-block btn-info">{% trans 'Help' %}</a> | ||
{% endif %} | ||
{% block comments %} | ||
{% if original %} | ||
<hr/> | ||
<!-- actual comments, this is updated with hx-swap when a comment is posted --> | ||
<div id="comments-list">{% include 'admin/_comments_list.html' with object=original %}</div> | ||
{% endif %} | ||
{% endblock %} | ||
{% endblock %} | ||
{% block content %} | ||
<script defer src="{% static 'js/app-prod.js' %}"></script> | ||
{{ block.super }} | ||
{% if original %} | ||
<!-- actual comment form, outside of main form; this will be updated with hx-oob-swap when a comment is posted --> | ||
<div id="comments-form-wrapper"> | ||
{% include 'admin/_comments_form.html' with object=original app_label=opts.app_label model_name=opts.model_name %} | ||
</div> | ||
{% endif %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.http import Http404 | ||
from django.shortcuts import get_object_or_404, render | ||
|
||
|
||
def comment_form_view(request, app_label, model_name, pk): | ||
"""Renders a list of comments for the admin view, refreshed using htmx after posting a comment.""" | ||
if not request.user.is_authenticated or not request.user.is_staff: | ||
raise Http404() | ||
|
||
content_type = get_object_or_404(ContentType, app_label=app_label, model=model_name) | ||
obj = get_object_or_404(content_type.model_class(), pk=pk) | ||
return render( | ||
request, | ||
"admin/_comments_form_combo.html", | ||
{ | ||
"object": obj, | ||
"model_name": model_name, | ||
"app_label": app_label, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters