<commit_before>import time
from django.shortcuts import render, get_object_or_404, redirect
from codefisher_apps.pastelsvg.models import Icon, PastelSVGDonation, ProtectedDownload, IconRequest, IconRequestComment, UseExample
from haystack.query import SearchQuerySet
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.http import Http404, HttpResponse
from djangopress.donate.views import DonationPayPalPaymentsForm
from django.core.urlresolvers import reverse
from django.conf import settings
from djangopress.core.util import has_permission, get_client_ip, choose_form
from codefisher_apps.downloads.models import Download, DownloadGroup
from django import forms
from django.contrib import messages
# we use the same fields so this works
from djangopress.forum.views import check_askmet_spam

from upvotes.views import MakeRequest, RequestList, RequestView, RequestVote, RequestFollow
from upvotes.forms import get_request_form, get_anon_request_form, get_request_comment_form, get_anon_request_comment_form

IconRequestForm = get_request_form(IconRequest, ('concept_icon', ))
IconRequestAnonymousForm = get_anon_request_form(IconRequest, ('concept_icon', ))
IconRequestCommentForm = get_request_comment_form(IconRequestComment)
IconRequestCommentAnonymousForm = get_anon_request_comment_form(IconRequestComment)

def index(request):
    icon_group, icons = get_download('<EMAIL>')
    icon_group_large, icons_large = get_download('<EMAIL>')
    data = {
            "icon_group": icon_group,
            "icons": icons,
            "icon_group_large": icon_group_large,
            "icons_large": icons_large,
        "title": "Pastel SVG Icon Set"
    }
    return render(request, 'pastelsvg/index.html' , data)
      
class UseExampleForm(forms.ModelForm):
    class Meta(object):
        fields = ("title", "url", "description")
        model = UseExample
       
class UseExampleAnonymousForm(UseExampleForm):
    class Meta(object):
        fields = ("title", "poster_name", "poster_email", "url", "description")
        model = UseExample
    
    def __init__(self, *args, **kwargs):
        super(UseExampleAnonymousForm, self).__init__(*args, **kwargs)
        self.fields['poster_name'].required = True
        self.fields['poster_email'].required = True
        
def who_uses(request, page=1):
    if request.method == "POST":
        form = choose_form(request, UseExampleForm, UseExampleAnonymousForm, request.POST)
        if form.is_valid():
            use_example = form.save(commit=False)
            use_example.ip = get_client_ip(request)
            if request.user.is_authenticated():
                use_example.poster = request.user
            use_example.save()
            messages.add_message(request, messages.SUCCESS, "Your project has been submitted, it will be made public after being reviewed.")
            return redirect(reverse('pastel-svg-who-uses'))
    else:
        form = choose_form(request, UseExampleForm, UseExampleAnonymousForm)
    use_example = UseExample.objects.filter(validated=True).order_by('-posted')  
    paginator = Paginator(use_example, 20)    
    try:
        use_page = paginator.page(page)
    except (EmptyPage, InvalidPage):
        if page != 1 and use_example:
            return redirect(use_example[0].get_absolute_url(paginator.num_pages))
    data = {
        "title": "Who Uses Pastel SVG Icons",
        "form": form,
        "page": use_page,
        "use_example": use_example[0] if use_example else None,
    }
    return render(request, 'pastelsvg/use_example.html' , data)

class MakeIconRequet(MakeRequest):
    template = 'pastelsvg/request/make.html'
    title = "Make Pastel SVG Icon Request"
    request_url = 'pastel-svg-request'
    spam_url = 'pastel-svg-request-spam'
    request_form = IconRequestForm
    request_anonymous_form = IconRequestAnonymousForm
    
class IconRequestView(RequestView):
    template = 'pastelsvg/request/request.html'
    request_class = IconRequest
    spam_url = 'pastel-svg-request-comment-spam'
    request_url = 'pastel-svg-request'
    comment_form = IconRequestCommentForm
    comment_anonymous_form = IconRequestCommentAnonymousForm
   
class IconRequestVote(RequestVote):
    request_class = IconRequest
    session_id = 'pastel-svg-voted-%s'
    request_url = 'pastel-svg-request'
    duplicate_vote_message = "You can not up vote an icon request multiple times."

class IconRequestFollow(RequestFollow):
    request_class = IconRequest
    request_url = 'pastel-svg-request'

    def get_subscriptions(self, request):
        return request.user.icon_request_subscriptions

class RequestIconList(RequestList):
    template = 'pastelsvg/request/index.html'
    title = "Pastel SVG Icon Requests"
    request_class = IconRequest
    
def donate_thanks(request):
    data = {
        "title": "Thanks for your Donation"
    }
    return render(request, 'pastelsvg/donate_thanks.html' , data)

def donate(request):
    form = None
    if request.user.is_authenticated():
        try:
            donation = PastelSVGDonation.objects.get(user=request.user, validated=False)
        except PastelSVGDonation.DoesNotExist:
            invoice_id = 'pastel-svg-%s-%s' % (time.strftime("%y%m%d"), request.user.pk)
            donation = PastelSVGDonation(user=request.user, invoice_id=invoice_id)
            donation.save()
        paypal_dict = {
            "business": settings.PAYPAL_RECEIVER_EMAIL,
            "item_name": "Donation to Codefisher.org",
            "invoice": donation.invoice_id,
            "notify_url": "http://%s" % request.get_host() + reverse('paypal-ipn'),
            "return_url": "http://%s" % request.get_host() + reverse('pastel-svg-donate-thanks'),
            "cancel_return": "http://%s" % request.get_host() + reverse('pastel-svg-donate'),
        }<commit_msg>Adding csrf_exempt to the donation thank you page.<commit_after>import time
from django.shortcuts import render, get_object_or_404, redirect
from codefisher_apps.pastelsvg.models import Icon, PastelSVGDonation, ProtectedDownload, IconRequest, IconRequestComment, UseExample
from haystack.query import SearchQuerySet
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.http import Http404, HttpResponse
from django.views.decorators.csrf import csrf_exempt
from djangopress.donate.views import DonationPayPalPaymentsForm
from django.core.urlresolvers import reverse
from django.conf import settings
from djangopress.core.util import has_permission, get_client_ip, choose_form
from codefisher_apps.downloads.models import Download, DownloadGroup
from django import forms
from django.contrib import messages
# we use the same fields so this works
from djangopress.forum.views import check_askmet_spam

from upvotes.views import MakeRequest, RequestList, RequestView, RequestVote, RequestFollow
from upvotes.forms import get_request_form, get_anon_request_form, get_request_comment_form, get_anon_request_comment_form

IconRequestForm = get_request_form(IconRequest, ('concept_icon', ))
IconRequestAnonymousForm = get_anon_request_form(IconRequest, ('concept_icon', ))
IconRequestCommentForm = get_request_comment_form(IconRequestComment)
IconRequestCommentAnonymousForm = get_anon_request_comment_form(IconRequestComment)

def index(request):
    icon_group, icons = get_download('<EMAIL>')
    icon_group_large, icons_large = get_download('<EMAIL>')
    data = {
            "icon_group": icon_group,
            "icons": icons,
            "icon_group_large": icon_group_large,
            "icons_large": icons_large,
        "title": "Pastel SVG Icon Set"
    }
    return render(request, 'pastelsvg/index.html' , data)
      
class UseExampleForm(forms.ModelForm):
    class Meta(object):
        fields = ("title", "url", "description")
        model = UseExample
       
class UseExampleAnonymousForm(UseExampleForm):
    class Meta(object):
        fields = ("title", "poster_name", "poster_email", "url", "description")
        model = UseExample
    
    def __init__(self, *args, **kwargs):
        super(UseExampleAnonymousForm, self).__init__(*args, **kwargs)
        self.fields['poster_name'].required = True
        self.fields['poster_email'].required = True
        
def who_uses(request, page=1):
    if request.method == "POST":
        form = choose_form(request, UseExampleForm, UseExampleAnonymousForm, request.POST)
        if form.is_valid():
            use_example = form.save(commit=False)
            use_example.ip = get_client_ip(request)
            if request.user.is_authenticated():
                use_example.poster = request.user
            use_example.save()
            messages.add_message(request, messages.SUCCESS, "Your project has been submitted, it will be made public after being reviewed.")
            return redirect(reverse('pastel-svg-who-uses'))
    else:
        form = choose_form(request, UseExampleForm, UseExampleAnonymousForm)
    use_example = UseExample.objects.filter(validated=True).order_by('-posted')  
    paginator = Paginator(use_example, 20)    
    try:
        use_page = paginator.page(page)
    except (EmptyPage, InvalidPage):
        if page != 1 and use_example:
            return redirect(use_example[0].get_absolute_url(paginator.num_pages))
    data = {
        "title": "Who Uses Pastel SVG Icons",
        "form": form,
        "page": use_page,
        "use_example": use_example[0] if use_example else None,
    }
    return render(request, 'pastelsvg/use_example.html' , data)

class MakeIconRequet(MakeRequest):
    template = 'pastelsvg/request/make.html'
    title = "Make Pastel SVG Icon Request"
    request_url = 'pastel-svg-request'
    spam_url = 'pastel-svg-request-spam'
    request_form = IconRequestForm
    request_anonymous_form = IconRequestAnonymousForm
    
class IconRequestView(RequestView):
    template = 'pastelsvg/request/request.html'
    request_class = IconRequest
    spam_url = 'pastel-svg-request-comment-spam'
    request_url = 'pastel-svg-request'
    comment_form = IconRequestCommentForm
    comment_anonymous_form = IconRequestCommentAnonymousForm
   
class IconRequestVote(RequestVote):
    request_class = IconRequest
    session_id = 'pastel-svg-voted-%s'
    request_url = 'pastel-svg-request'
    duplicate_vote_message = "You can not up vote an icon request multiple times."

class IconRequestFollow(RequestFollow):
    request_class = IconRequest
    request_url = 'pastel-svg-request'

    def get_subscriptions(self, request):
        return request.user.icon_request_subscriptions

class RequestIconList(RequestList):
    template = 'pastelsvg/request/index.html'
    title = "Pastel SVG Icon Requests"
    request_class = IconRequest

@csrf_exempt
def donate_thanks(request):
    data = {
        "title": "Thanks for your Donation"
    }
    return render(request, 'pastelsvg/donate_thanks.html' , data)

def donate(request):
    form = None
    if request.user.is_authenticated():
        try:
            donation = PastelSVGDonation.objects.get(user=request.user, validated=False)
        except PastelSVGDonation.DoesNotExist:
            invoice_id = 'pastel-svg-%s-%s' % (time.strftime("%y%m%d"), request.user.pk)
            donation = PastelSVGDonation(user=request.user, invoice_id=invoice_id)
            donation.save()
        paypal_dict = {
            "business": settings.PAYPAL_RECEIVER_EMAIL,
            "item_name": "Donation to Codefisher.org",
            "invoice": donation.invoice_id,
            "notify_url": "http://%s" % request.get_host() + reverse('paypal-ipn'),
            "return_url": "http://%s" % request.get_host() + reverse('pastel-svg-donate-thanks'),
            "cancel_return": "http://%s" % request.get_host() + reverse('pastel-svg-donate'),
        }
{'fraction_non_alphanumeric': 0.09888992458266249, 'fraction_numerical': 0.0020337259554275063, 'mean_word_length': 3.726471766119343, 'pattern_counts': {'":': 34, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6770391', 'n_tokens_mistral': 3623, 'n_tokens_neox': 3487, 'n_words': 748}