Changeset - c0a4fe5f39d0
[Not reviewed]
0 4 0
Ben Sturmfels (bsturmfels) - 1 month ago 2024-03-15 07:21:59
ben@sturm.com.au
usethesource: Add checkbox to opt-out of posting comment to mailing list
4 files changed with 10 insertions and 6 deletions:
0 comments (0 inline, 0 general)
conservancy/usethesource/forms.py
Show inline comments
...
 
@@ -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)
conservancy/usethesource/templates/usethesource/add_comment_button_partial.html
Show inline comments
 
<div class="mt2" hx-target="this" hx-swap="outerHTML">
 
  <button type="submit" title="Add comment" class="f3 b white bg-light-silver ph2" style="border: none" hx-get="{% url 'usethesource:add_comment' slug=candidate.slug %}">+</button>
 
  <button type="submit" title="Add comment" class="f3 b white bg-light-silver pointer ph2" style="border: none" hx-get="{% url 'usethesource:add_comment' slug=candidate.slug %}">+</button>
 
</div>
conservancy/usethesource/templates/usethesource/add_comment_form.html
Show inline comments
...
 
@@ -2,8 +2,9 @@
 
  {% csrf_token %}
 
  <div>{{ form.time }}</div>
 
  <div class="mt2">{{ form.message }}</div>
 
  <div class="mt2"><label>{{ form.post_to_list }} Post to the mailing list</div>
 
  <div class="mt2">
 
    <button type="submit" hx-get="{% url 'usethesource:add_button' slug=candidate.slug %}" class="b pointer white bg-light-silver pv2 ph3" style="border: none">Cancel</button>
 
    <button type="submit" class="b white bg-green pv2 ph3" style="border: none">Save and email</button>
 
    <button type="submit" class="b white bg-green pv2 ph3" style="border: none">Save</button>
 
  </div>
 
</form>
conservancy/usethesource/views.py
Show inline comments
...
 
@@ -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})
 

	
0 comments (0 inline, 0 general)