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):
|
class CommentForm(forms.ModelForm):
|
||||||
|
post_to_list = forms.BooleanField(required=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Comment
|
model = Comment
|
||||||
fields = ['time', 'message']
|
fields = ['time', 'message', 'post_to_list']
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
<div class="mt2" hx-target="this" hx-swap="outerHTML">
|
<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>
|
</div>
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div>{{ form.time }}</div>
|
<div>{{ form.time }}</div>
|
||||||
<div class="mt2">{{ form.message }}</div>
|
<div class="mt2">{{ form.message }}</div>
|
||||||
|
<div class="mt2"><label>{{ form.post_to_list }} Post to the mailing list</div>
|
||||||
<div class="mt2">
|
<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" 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>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -35,7 +35,7 @@ def download_page(request, slug, download_type):
|
||||||
def create_comment(request, slug):
|
def create_comment(request, slug):
|
||||||
candidate = get_object_or_404(Candidate, slug=slug)
|
candidate = get_object_or_404(Candidate, slug=slug)
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
form = CommentForm()
|
form = CommentForm(initial={'post_to_list': True})
|
||||||
else:
|
else:
|
||||||
form = CommentForm(request.POST)
|
form = CommentForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
@ -43,8 +43,9 @@ def create_comment(request, slug):
|
||||||
comment.candidate = candidate
|
comment.candidate = candidate
|
||||||
comment.user = request.user
|
comment.user = request.user
|
||||||
comment.save()
|
comment.save()
|
||||||
email = make_comment_email(comment)
|
if 'post_to_list' in request.POST:
|
||||||
email.send()
|
email = make_comment_email(comment)
|
||||||
|
email.send()
|
||||||
return redirect('usethesource:view_comment', comment_id=comment.id, show_add='true')
|
return redirect('usethesource:view_comment', comment_id=comment.id, show_add='true')
|
||||||
return render(request, 'usethesource/add_comment_form.html', {'form': form, 'candidate': candidate})
|
return render(request, 'usethesource/add_comment_form.html', {'form': form, 'candidate': candidate})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue