Changeset - e340f18ec9fa
[Not reviewed]
0 2 1
Ben Sturmfels (bsturmfels) - 5 months ago 2023-11-10 05:35:46
ben@sturm.com.au
usethesource: Require agreement to download
3 files changed with 34 insertions and 16 deletions:
0 comments (0 inline, 0 general)
conservancy/usethesource/forms.py
Show inline comments
 
new file 100644
 
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).")
conservancy/usethesource/templates/usethesource/download.html
Show inline comments
...
 
@@ -5,13 +5,19 @@
 

	
 
  <section class="pa2 mt4 mb5">
 
    <h2 class="f2 lh-title ttu mt0">Download</h2>
 
    <p><strong>File</strong>: {{ download_url }}</p>
 

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

	
 
    <div style="display: flex">
 
      <a href="{% url 'usethesource:candidate' slug=candidate.slug %}" class="white bg-silver dib pv2 ph3 mb2 mr2">Back</a>
 
      <a href="{{ download_url }}" class="white bg-green dib pv2 ph3 mb2">Download</a>
 
    </div>
 
    <form method="post" action="{% url 'usethesource:download' slug=candidate.slug download_type=download_type %}">
 
      {% csrf_token %}
 
      {% if form.agree.errors %}
 
        <div class="br2 bg-washed-red ph4 pv3 mb2">{{ form.agree.errors }}</div>
 
      {% endif %}
 
      <div class="mb3" style="display: flex; align-items: start">
 
        <span class="mr2">{{ form.agree }}</span> {{ form.agree.label_tag }}
 
      </div>
 
      <div style="display: flex">
 
        <a href="{% url 'usethesource:candidate' slug=candidate.slug %}" class="b white bg-silver dib pv2 ph3 mb2 mr2">Back</a>
 
        <button type="submit" class="b white bg-green dib pv2 ph3 bn mb2">Download</button>
 
      </div>
 
    </form>
 
  </section>
 
{% endblock content %}
conservancy/usethesource/views.py
Show inline comments
 
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)
0 comments (0 inline, 0 general)