From 296f29c84bb210aaa14b81412fe34cf54cf2e786 Mon Sep 17 00:00:00 2001 From: Ben Sturmfels Date: Fri, 15 Mar 2024 18:39:49 +1100 Subject: [PATCH] usethesource: Add candidate option to show/hide download disclaimer --- conservancy/usethesource/admin.py | 1 + .../0007_candidate_show_download_disclaimer.py | 18 ++++++++++++++++++ conservancy/usethesource/models.py | 1 + .../templates/usethesource/candidate.html | 15 +++++++++++++-- conservancy/usethesource/views.py | 2 +- 5 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 conservancy/usethesource/migrations/0007_candidate_show_download_disclaimer.py diff --git a/conservancy/usethesource/admin.py b/conservancy/usethesource/admin.py index 8d131dc1..6a886813 100644 --- a/conservancy/usethesource/admin.py +++ b/conservancy/usethesource/admin.py @@ -22,6 +22,7 @@ class CandidateAdmin(admin.ModelAdmin): 'release_date', 'source_url', 'binary_url', + 'show_download_disclaimer', 'description', ] inlines = [CommentInline] diff --git a/conservancy/usethesource/migrations/0007_candidate_show_download_disclaimer.py b/conservancy/usethesource/migrations/0007_candidate_show_download_disclaimer.py new file mode 100644 index 00000000..cb15982d --- /dev/null +++ b/conservancy/usethesource/migrations/0007_candidate_show_download_disclaimer.py @@ -0,0 +1,18 @@ +# 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), + ), + ] diff --git a/conservancy/usethesource/models.py b/conservancy/usethesource/models.py index 2edb1206..8de4e74a 100644 --- a/conservancy/usethesource/models.py +++ b/conservancy/usethesource/models.py @@ -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) diff --git a/conservancy/usethesource/templates/usethesource/candidate.html b/conservancy/usethesource/templates/usethesource/candidate.html index d38444bc..b31a11f2 100644 --- a/conservancy/usethesource/templates/usethesource/candidate.html +++ b/conservancy/usethesource/templates/usethesource/candidate.html @@ -23,8 +23,19 @@

Released: {{ candidate.release_date }}

-
Download source
-
Download image
+ {% if candidate.show_download_disclaimer %} +
Download source
+
Download image
+ {% else %} +
+ {% csrf_token %} + +
+
+ {% csrf_token %} + +
+ {% endif %}
diff --git a/conservancy/usethesource/views.py b/conservancy/usethesource/views.py index 6b3c10d6..4b7a6be9 100644 --- a/conservancy/usethesource/views.py +++ b/conservancy/usethesource/views.py @@ -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,