From c0a4fe5f39d0512d6228e860376d203a2ea2b65c 2024-03-15 07:21:59 From: Ben Sturmfels Date: 2024-03-15 07:21:59 Subject: [PATCH] usethesource: Add checkbox to opt-out of posting comment to mailing list --- diff --git a/conservancy/usethesource/forms.py b/conservancy/usethesource/forms.py index 9328b6d5a2d82ca0dd607febbb5eed119b3c95ff..3f1277f060987b5d07594542645ff11b07d70da2 100644 --- a/conservancy/usethesource/forms.py +++ b/conservancy/usethesource/forms.py @@ -4,9 +4,11 @@ from .models import Comment class CommentForm(forms.ModelForm): + post_to_list = forms.BooleanField(required=False) + class Meta: model = Comment - fields = ['time', 'message'] + fields = ['time', 'message', 'post_to_list'] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/conservancy/usethesource/templates/usethesource/add_comment_button_partial.html b/conservancy/usethesource/templates/usethesource/add_comment_button_partial.html index 806d6beadaf96a3b4394cdaf899f79982117f4b6..3e5240562047e1806d7e44cb9294c34925de86f8 100644 --- a/conservancy/usethesource/templates/usethesource/add_comment_button_partial.html +++ b/conservancy/usethesource/templates/usethesource/add_comment_button_partial.html @@ -1,3 +1,3 @@
- +
diff --git a/conservancy/usethesource/templates/usethesource/add_comment_form.html b/conservancy/usethesource/templates/usethesource/add_comment_form.html index a3228f604b4afca0cf6750dbcfd3ba4bfe402683..11e296662adce4baea11c13931fa72167763eb00 100644 --- a/conservancy/usethesource/templates/usethesource/add_comment_form.html +++ b/conservancy/usethesource/templates/usethesource/add_comment_form.html @@ -2,8 +2,9 @@ {% csrf_token %}
{{ form.time }}
{{ form.message }}
+
- +
diff --git a/conservancy/usethesource/views.py b/conservancy/usethesource/views.py index 33158f78d42b9ab14715592b326bf793dbd6fa6f..6b3c10d66963402a9ee309e356546071883fa4ea 100644 --- a/conservancy/usethesource/views.py +++ b/conservancy/usethesource/views.py @@ -35,7 +35,7 @@ def download_page(request, slug, download_type): def create_comment(request, slug): candidate = get_object_or_404(Candidate, slug=slug) if request.method == 'GET': - form = CommentForm() + form = CommentForm(initial={'post_to_list': True}) else: form = CommentForm(request.POST) if form.is_valid(): @@ -43,8 +43,9 @@ def create_comment(request, slug): comment.candidate = candidate comment.user = request.user comment.save() - email = make_comment_email(comment) - email.send() + if 'post_to_list' in request.POST: + email = make_comment_email(comment) + email.send() return redirect('usethesource:view_comment', comment_id=comment.id, show_add='true') return render(request, 'usethesource/add_comment_form.html', {'form': form, 'candidate': candidate})