Changeset - 9ff46824209a
[Not reviewed]
0 5 1
Ben Sturmfels (bsturmfels) - 1 month ago 2024-03-15 07:49:48
ben@sturm.com.au
usethesource: Allow comments to be attributed to non-account holders
6 files changed with 25 insertions and 4 deletions:
0 comments (0 inline, 0 general)
conservancy/usethesource/forms.py
Show inline comments
...
 
@@ -8,7 +8,7 @@ class CommentForm(forms.ModelForm):
 

	
 
    class Meta:
 
        model = Comment
 
        fields = ['time', 'message', 'post_to_list']
 
        fields = ['time', 'attribute_to', 'message', 'post_to_list']
 

	
 
    def __init__(self, *args, **kwargs):
 
        super().__init__(*args, **kwargs)
conservancy/usethesource/migrations/0008_comment_attribute_to.py
Show inline comments
 
new file 100644
 
# Generated by Django 3.2.19 on 2024-03-15 03:43
 

	
 
from django.db import migrations, models
 

	
 

	
 
class Migration(migrations.Migration):
 

	
 
    dependencies = [
 
        ('usethesource', '0007_candidate_show_download_disclaimer'),
 
    ]
 

	
 
    operations = [
 
        migrations.AddField(
 
            model_name='comment',
 
            name='attribute_to',
 
            field=models.CharField(blank=True, max_length=50),
 
        ),
 
    ]
conservancy/usethesource/models.py
Show inline comments
...
 
@@ -41,6 +41,7 @@ class Comment(models.Model):
 

	
 
    candidate = models.ForeignKey(Candidate, on_delete=models.CASCADE)
 
    user = models.ForeignKey(User, on_delete=models.PROTECT)
 
    attribute_to = models.CharField(max_length=50, blank=True)
 
    time = models.DateTimeField(default=timezone.now)
 
    message = models.TextField()
 
    email_message_id = models.CharField(max_length=255, default=gen_message_id)
conservancy/usethesource/templates/usethesource/add_comment_form.html
Show inline comments
 
<form hx-target="this" hx-swap="outerHTML" hx-post="{% url 'usethesource:add_comment' slug=candidate.slug %}">
 
  {% csrf_token %}
 
  <div>{{ form.time }}</div>
 
  <div><label>Time: {{ form.time }}</label></div>
 
  <div class="mt2"><label>Attribute to: {{ form.attribute_to }}</label></div>
 
  <div class="mt2">{{ form.message }}</div>
 
  <div class="mt2"><label>{{ form.post_to_list }} Post to the mailing list</div>
 
  <div class="mt2">
conservancy/usethesource/templates/usethesource/comment_partial.html
Show inline comments
 
<div class="mb4" hx-target="this" hx-swap="outerHTML"><strong>{{ comment.user }} — {{ comment.time }}</strong>
 
<div class="mb4" hx-target="this" hx-swap="outerHTML"><strong>{% if comment.attribute_to %}{{ comment.attribute_to }}{% else %}{{ comment.user }}{% endif %} — {{ comment.time }}</strong>
 
  {% if user.is_staff %}
 
    <a href="#" class="f7 white bg-light-silver ph2" hx-get="{% url 'usethesource:edit_comment' comment_id=comment.id %}">edit</a>
 
    <a href="#" class="f7 white bg-light-red ph2" hx-delete="{% url 'usethesource:delete_comment' comment_id=comment.id show_add='false' %}" hx-confirm="Are you sure you want to delete this comment?">delete</a>
conservancy/usethesource/templates/usethesource/edit_comment_form.html
Show inline comments
 
<form class="mb3" hx-target="this" hx-swap="outerHTML" hx-post="{% url 'usethesource:edit_comment' comment_id=comment.id %}">
 
  {% csrf_token %}
 
  <div>{{ form.time }}</div>
 
  <div><label>Time: {{ form.time }}</label></div>
 
  <div class="mt2"><label>Attribute to: {{ form.attribute_to }}</label></div>
 
  <div class="mt2">{{ form.message }}</div>
 
  <div class="mt2">
 
    <button type="submit" hx-get="{% url 'usethesource:view_comment' comment_id=comment.id show_add='false' %}" class="b pointer white bg-light-silver pv2 ph3" style="border: none">Cancel</button>
0 comments (0 inline, 0 general)