From e340f18ec9fa11d10aa091debb7b60ba02c4d8f3 Mon Sep 17 00:00:00 2001 From: Ben Sturmfels Date: Fri, 10 Nov 2023 16:35:22 +1100 Subject: [PATCH] usethesource: Require agreement to download --- conservancy/usethesource/forms.py | 13 ++++++++++++ .../templates/usethesource/download.html | 20 ++++++++++++------- conservancy/usethesource/views.py | 17 ++++++++-------- 3 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 conservancy/usethesource/forms.py diff --git a/conservancy/usethesource/forms.py b/conservancy/usethesource/forms.py new file mode 100644 index 00000000..8e3349c5 --- /dev/null +++ b/conservancy/usethesource/forms.py @@ -0,0 +1,13 @@ +from django import forms + +from .models import Comment + + +class CommentForm(forms.ModelForm): + class Meta: + model = Comment + fields = ['message'] + + +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) (unless and until it is determined that the source code candidate and firmware are entirely governed by one or more software licenses that permit such use beyond such purpose).") diff --git a/conservancy/usethesource/templates/usethesource/download.html b/conservancy/usethesource/templates/usethesource/download.html index 792441c5..a58c0ad2 100644 --- a/conservancy/usethesource/templates/usethesource/download.html +++ b/conservancy/usethesource/templates/usethesource/download.html @@ -5,13 +5,19 @@

Download

-

File: {{ download_url }}

-

By downloading this, you agree to use it only for the purposes of GPL compliance checking, unless otherwise permitted by the license.

- -
- Back - Download -
+
+ {% csrf_token %} + {% if form.agree.errors %} +
{{ form.agree.errors }}
+ {% endif %} +
+ {{ form.agree }} {{ form.agree.label_tag }} +
+
+ Back + +
+
{% endblock content %} diff --git a/conservancy/usethesource/views.py b/conservancy/usethesource/views.py index e9740178..d2acba9d 100644 --- a/conservancy/usethesource/views.py +++ b/conservancy/usethesource/views.py @@ -1,8 +1,8 @@ -from django import forms from django.contrib.admin.views.decorators import staff_member_required from django.shortcuts import get_object_or_404, redirect, render from .models import Candidate, Comment +from .forms import CommentForm, DownloadForm def landing_page(request): @@ -17,20 +17,19 @@ def candidate_page(request, slug): def download_page(request, slug, download_type): candidate = get_object_or_404(Candidate, slug=slug) - url = candidate.source_url if download_type == 'source' else candidate.binary_url + 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(): + return redirect(url) return render( request, 'usethesource/download.html', - {'candidate': candidate, 'download_url': url}, + {'form': form, 'candidate': candidate, 'download_type': download_type}, ) -class CommentForm(forms.ModelForm): - class Meta: - model = Comment - fields = ['message'] - - @staff_member_required def create_comment(request, slug): candidate = get_object_or_404(Candidate, slug=slug)