File diff b8a626b955c5 → e340f18ec9fa
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)