Changeset - 296f29c84bb2
[Not reviewed]
0 4 1
Ben Sturmfels (bsturmfels) - 2 months ago 2024-03-15 07:39:49
ben@sturm.com.au
usethesource: Add candidate option to show/hide download disclaimer
5 files changed with 34 insertions and 3 deletions:
0 comments (0 inline, 0 general)
conservancy/usethesource/admin.py
Show inline comments
...
 
@@ -13,24 +13,25 @@ class CommentInline(admin.TabularInline):
 
@admin.register(Candidate)
 
class CandidateAdmin(admin.ModelAdmin):
 
    list_display = ['name', 'vendor', 'device', 'release_date', 'ordering']
 
    list_editable = ['ordering']
 
    fields = [
 
        'name',
 
        'slug',
 
        'vendor',
 
        'device',
 
        'release_date',
 
        'source_url',
 
        'binary_url',
 
        'show_download_disclaimer',
 
        'description',
 
    ]
 
    inlines = [CommentInline]
 
    prepopulated_fields = {'slug': ['name']}
 
    view_on_site = True
 

	
 
    def save_model(self, request, obj, form, change):
 
        send_email = obj.id is None
 
        super().save_model(request, obj, form, change)
 
        if send_email:
 
            # Announce the new candidate
 
            email = make_candidate_email(obj, request.user)
conservancy/usethesource/migrations/0007_candidate_show_download_disclaimer.py
Show inline comments
 
new file 100644
 
# Generated by Django 3.2.19 on 2024-03-15 03:25
 

	
 
from django.db import migrations, models
 

	
 

	
 
class Migration(migrations.Migration):
 

	
 
    dependencies = [
 
        ('usethesource', '0006_alter_comment_time'),
 
    ]
 

	
 
    operations = [
 
        migrations.AddField(
 
            model_name='candidate',
 
            name='show_download_disclaimer',
 
            field=models.BooleanField(default=True),
 
        ),
 
    ]
conservancy/usethesource/models.py
Show inline comments
...
 
@@ -13,24 +13,25 @@ def gen_message_id():
 

	
 
class Candidate(models.Model):
 
    """A source/binary release we'd like to verify CCS status of."""
 

	
 
    name = models.CharField('Candidate name', max_length=50)
 
    slug = models.SlugField(max_length=50, unique=True)
 
    vendor = models.CharField('Vendor name', max_length=50)
 
    device = models.CharField('Device name', max_length=50)
 
    release_date = models.DateField(null=True, blank=True)
 
    description = models.TextField(blank=True)
 
    source_url = models.URLField()
 
    binary_url = models.URLField(blank=True)
 
    show_download_disclaimer = models.BooleanField(default=True)
 
    ordering = models.SmallIntegerField(default=0)
 
    email_message_id = models.CharField(max_length=255, default=gen_message_id)
 

	
 
    class Meta:
 
        ordering = ['ordering', 'name']
 

	
 
    def __str__(self):
 
        return self.name
 

	
 
    def get_absolute_url(self):
 
        return reverse('usethesource:candidate', kwargs={'slug': self.slug})
 

	
conservancy/usethesource/templates/usethesource/candidate.html
Show inline comments
...
 
@@ -14,26 +14,37 @@
 
    <div style="display: flex; justify-content: space-between">
 
      <div>
 
        <div class="flex items-center">
 
          <h2 class="f2 lh-title ttu mt0">{{ candidate.name }}</h2>
 
          {% 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>
 
      <div class="mt2">
 
        <div><a href="{% url 'usethesource:download' slug=candidate.slug download_type='source' %}" class="white bg-green db pv2 ph3 mb2">Download source</a></div>
 
        <div><a href="{% url 'usethesource:download' slug=candidate.slug download_type='binary' %}" class="white bg-green db pv2 ph3">Download image</a></div>
 
        {% if candidate.show_download_disclaimer %}
 
          <div><a href="{% url 'usethesource:download' slug=candidate.slug download_type='source' %}" class="white bg-green db pv2 ph3 mb2">Download source</a></div>
 
          <div><a href="{% url 'usethesource:download' slug=candidate.slug download_type='binary' %}" class="white bg-green db pv2 ph3">Download image</a></div>
 
        {% else %}
 
          <form method="post" action="{% url 'usethesource:download' slug=candidate.slug download_type='source' %}">
 
            {% csrf_token %}
 
            <button type="submit" class="white b bg-green db w-100 pv2 ph3 bn mb2">Download source</button>
 
          </form>
 
          <form method="post" action="{% url 'usethesource:download' slug=candidate.slug download_type='binary' %}">
 
            {% csrf_token %}
 
            <button type="submit" class="white b bg-green db w-100 pv2 ph3 bn mb2">Download image</button>
 
          </form>
 
        {% endif %}
 
      </div>
 
    </div>
 

	
 
    {{ candidate.description|urlize|linebreaksbr }}
 

	
 
    {% with comments=candidate.comment_set.all %}
 
      {% 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 %}
 

	
conservancy/usethesource/views.py
Show inline comments
...
 
@@ -13,25 +13,25 @@ def landing_page(request):
 

	
 
def candidate_page(request, slug):
 
    candidate = get_object_or_404(Candidate, slug=slug)
 
    return render(request, 'usethesource/candidate.html', {'candidate': candidate, 'add': True})
 

	
 

	
 
def download_page(request, slug, download_type):
 
    candidate = get_object_or_404(Candidate, slug=slug)
 
    form = DownloadForm()
 
    if request.method == 'POST':
 
        form = DownloadForm(request.POST)
 
        url = candidate.source_url if download_type == 'source' else candidate.binary_url
 
        if form.is_valid():
 
        if not candidate.show_download_disclaimer or form.is_valid():
 
            return redirect(url)
 
    return render(
 
        request,
 
        'usethesource/download.html',
 
        {'form': form, 'candidate': candidate, 'download_type': download_type},
 
    )
 

	
 

	
 
@staff_member_required
 
def create_comment(request, slug):
 
    candidate = get_object_or_404(Candidate, slug=slug)
 
    if request.method == 'GET':
0 comments (0 inline, 0 general)