usethesource: Add checkbox to opt-out of posting comment to mailing list
This commit is contained in:
parent
250db691e4
commit
c0a4fe5f39
4 changed files with 10 additions and 6 deletions
|
@ -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)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
<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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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,6 +43,7 @@ def create_comment(request, slug):
|
|||
comment.candidate = candidate
|
||||
comment.user = request.user
|
||||
comment.save()
|
||||
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')
|
||||
|
|
Loading…
Reference in a new issue