Changeset - 2a23a0a55ea0
[Not reviewed]
conservancy/usethesource/forms.py
Show inline comments
...
 
@@ -3,11 +3,15 @@ from django import forms
 
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):
 
    agree = forms.BooleanField(label="I promise and represent that I will not copy, distribute, modify, or otherwise use this source code candidate and/or firmware for any purpose other than to help SFC evaluate the source code candidate for compliance with the terms of the GNU General Public License (any version).")
conservancy/usethesource/models.py
Show inline comments
 
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():
 
    """Generate a time-based identifier for use in "In-Reply-To" header."""
 
    return f'<{uuid.uuid1()}@sfconservancy.org>'
 

	
...
 
@@ -36,13 +37,13 @@ class Candidate(models.Model):
 

	
 
class Comment(models.Model):
 
    """A comment about experiences or learnings building the candidate."""
 

	
 
    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)
 

	
 
    def __str__(self):
 
        return f'{self.id}: {self.candidate.name}, {self.user}, {self.time}'
 

	
conservancy/usethesource/templates/usethesource/add_comment_form.html
Show inline comments
 
file renamed from conservancy/usethesource/templates/usethesource/comment_form.html to conservancy/usethesource/templates/usethesource/add_comment_form.html
 
<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>
conservancy/usethesource/templates/usethesource/candidate.html
Show inline comments
...
 
@@ -12,13 +12,13 @@
 

	
 
  <section class="pa2 mt4 mb3">
 
    <div style="display: flex; justify-content: space-between">
 
      <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>
 
        <p><strong>Device</strong>: {{ candidate.device }}</p>
 
        <p><strong>Released</strong>: {{ candidate.release_date }}</p>
 
      </div>
...
 
@@ -34,11 +34,11 @@
 
      {% if comments or user.is_staff %}<h3 class="f3 lh-title mt4">Comments</h3>{% endif %}
 
      {% for comment in comments %}
 
        {% include "usethesource/comment_partial.html" %}
 
      {% endfor %}
 
    {% endwith %}
 

	
 
    {% if user.is_staff %}
 
    {% if user.is_staff or user.is_superuser %}
 
      {% include "usethesource/add_comment_button_partial.html" %}
 
    {% endif %}
 
  </section>
 
{% endblock content %}
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 %}
 
  {{ 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>
conservancy/usethesource/templates/usethesource/save_button_partial.html
Show inline comments
 
deleted file
conservancy/usethesource/views.py
Show inline comments
...
 
@@ -43,13 +43,13 @@ def create_comment(request, slug):
 
            comment.candidate = candidate
 
            comment.user = request.user
 
            comment.save()
 
            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
 
def edit_comment(request, comment_id):
 
    comment = get_object_or_404(Comment, id=comment_id)
 
    if request.method == 'GET':
0 comments (0 inline, 0 general)