Changeset - 296f29c84bb2
[Not reviewed]
0 4 1
Ben Sturmfels (bsturmfels) - 1 month 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
...
 
@@ -22,6 +22,7 @@ class CandidateAdmin(admin.ModelAdmin):
 
        'release_date',
 
        'source_url',
 
        'binary_url',
 
        'show_download_disclaimer',
 
        'description',
 
    ]
 
    inlines = [CommentInline]
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
...
 
@@ -22,6 +22,7 @@ class Candidate(models.Model):
 
    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)
 

	
conservancy/usethesource/templates/usethesource/candidate.html
Show inline comments
...
 
@@ -23,8 +23,19 @@
 
        <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>
 

	
conservancy/usethesource/views.py
Show inline comments
...
 
@@ -22,7 +22,7 @@ def download_page(request, slug, download_type):
 
    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,
0 comments (0 inline, 0 general)