usethesource: Add comment time field

This commit is contained in:
Ben Sturmfels 2024-02-01 10:05:11 +11:00
parent 9158aff702
commit 2a23a0a55e
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0
7 changed files with 16 additions and 10 deletions

View file

@ -6,7 +6,11 @@ from .models import Comment
class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ['message']
fields = ['time', 'message']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['time'].widget.input_type = 'datetime-local'
class DownloadForm(forms.Form):

View file

@ -3,6 +3,7 @@ import uuid
from django.contrib.auth.models import User
from django.db import models
from django.urls import reverse
from django.utils import timezone
def gen_message_id():
@ -39,7 +40,7 @@ class Comment(models.Model):
candidate = models.ForeignKey(Candidate, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.PROTECT)
time = models.DateTimeField(auto_now_add=True)
time = models.DateTimeField(default=timezone.now)
message = models.TextField()
email_message_id = models.CharField(max_length=255, default=gen_message_id)

View file

@ -1,8 +1,9 @@
<form hx-target="this" hx-swap="outerHTML" hx-post="{% url 'usethesource:add_comment' slug=candidate.slug %}">
{% csrf_token %}
{{ form.message }}
<div>{{ form.time }}</div>
<div class="mt2">{{ form.message }}</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>
{% include 'usethesource/save_button_partial.html' %}
<button type="submit" class="b white bg-green pv2 ph3" style="border: none">Save and email</button>
</div>
</form>

View file

@ -15,7 +15,7 @@
<div>
<div class="flex items-center">
<h2 class="f2 lh-title ttu mt0">{{ candidate.name }}</h2>
<a href="{% url 'admin:usethesource_candidate_change' object_id=candidate.id %}" title="Edit candidate" class="f3 white bg-light-silver db ph2 mh2 mb3" style="transform: scaleX(-1); text-decoration: none !important"></a>
{% if user.is_staff or user.is_superuser %}<a href="{% url 'admin:usethesource_candidate_change' object_id=candidate.id %}" title="Edit candidate" class="f3 white bg-light-silver db ph2 mh2 mb3" style="transform: scaleX(-1); text-decoration: none !important"></a>{% endif %}
</div>
<p><strong>Vendor</strong>: {{ candidate.vendor }}</p>
@ -37,7 +37,7 @@
{% endfor %}
{% endwith %}
{% if user.is_staff %}
{% if user.is_staff or user.is_superuser %}
{% include "usethesource/add_comment_button_partial.html" %}
{% endif %}
</section>

View file

@ -1,8 +1,9 @@
<form class="mb3" hx-target="this" hx-swap="outerHTML" hx-post="{% url 'usethesource:edit_comment' comment_id=comment.id %}">
{% csrf_token %}
{{ form.message }}
<div>{{ form.time }}</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>
{% include 'usethesource/save_button_partial.html' %}
<button type="submit" class="b white bg-green pv2 ph3" style="border: none">Save</button>
</div>
</form>

View file

@ -1 +0,0 @@
<button type="submit" class="b white bg-green pv2 ph3" style="border: none">Save and email</button>

View file

@ -46,7 +46,7 @@ def create_comment(request, slug):
email = make_comment_email(comment)
email.send()
return redirect('usethesource:view_comment', comment_id=comment.id, show_add='true')
return render(request, 'usethesource/comment_form.html', {'form': form, 'candidate': candidate})
return render(request, 'usethesource/add_comment_form.html', {'form': form, 'candidate': candidate})
@staff_member_required