diff --git a/conservancy/usethesource/forms.py b/conservancy/usethesource/forms.py index 3fb9755f..9328b6d5 100644 --- a/conservancy/usethesource/forms.py +++ b/conservancy/usethesource/forms.py @@ -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): diff --git a/conservancy/usethesource/models.py b/conservancy/usethesource/models.py index 4f360dfe..2edb1206 100644 --- a/conservancy/usethesource/models.py +++ b/conservancy/usethesource/models.py @@ -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) diff --git a/conservancy/usethesource/templates/usethesource/comment_form.html b/conservancy/usethesource/templates/usethesource/add_comment_form.html similarity index 65% rename from conservancy/usethesource/templates/usethesource/comment_form.html rename to conservancy/usethesource/templates/usethesource/add_comment_form.html index 7c62ee33..a3228f60 100644 --- a/conservancy/usethesource/templates/usethesource/comment_form.html +++ b/conservancy/usethesource/templates/usethesource/add_comment_form.html @@ -1,8 +1,9 @@
{% csrf_token %} - {{ form.message }} +
{{ form.time }}
+
{{ form.message }}
- {% include 'usethesource/save_button_partial.html' %} +
diff --git a/conservancy/usethesource/templates/usethesource/candidate.html b/conservancy/usethesource/templates/usethesource/candidate.html index e4a20ca6..3c50de9d 100644 --- a/conservancy/usethesource/templates/usethesource/candidate.html +++ b/conservancy/usethesource/templates/usethesource/candidate.html @@ -15,7 +15,7 @@

{{ candidate.name }}

- + {% if user.is_staff or user.is_superuser %}{% endif %}

Vendor: {{ candidate.vendor }}

@@ -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 %} diff --git a/conservancy/usethesource/templates/usethesource/edit_comment_form.html b/conservancy/usethesource/templates/usethesource/edit_comment_form.html index 0bab29c4..9eb52cf5 100644 --- a/conservancy/usethesource/templates/usethesource/edit_comment_form.html +++ b/conservancy/usethesource/templates/usethesource/edit_comment_form.html @@ -1,8 +1,9 @@
{% csrf_token %} - {{ form.message }} +
{{ form.time }}
+
{{ form.message }}
- {% include 'usethesource/save_button_partial.html' %} +
diff --git a/conservancy/usethesource/templates/usethesource/save_button_partial.html b/conservancy/usethesource/templates/usethesource/save_button_partial.html deleted file mode 100644 index 5cc66948..00000000 --- a/conservancy/usethesource/templates/usethesource/save_button_partial.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/conservancy/usethesource/views.py b/conservancy/usethesource/views.py index 34bf684f..0cdf0816 100644 --- a/conservancy/usethesource/views.py +++ b/conservancy/usethesource/views.py @@ -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