<commit_before>from django.template import RequestContext
from django.core.urlresolvers import reverse
from django.core.files.storage import default_storage
from django.shortcuts import redirect, render_to_response
from django.views.generic import DeleteView
from django.core.files.base import ContentFile

from buddy.utils import datetime_string

from image.models import ImageRequest
from image.forms import ImageRequestForm, ImageOfferForm

class DeleteImageView(DeleteView):
    model = ImageRequest
    success_url = "/"  

def request_image(request):
    form = ImageRequestForm(request.POST or None)

    if form.is_valid():
        instance = form.instance
        instance.user = request.user
        instance.save()
        
        return redirect(reverse('index'))

    return render_to_response('image/imagerequest_form.html',
            {'form':form},
            context_instance=RequestContext(request))

def offer_image(request):
    if request.method == "POST":
        form = ImageOfferForm(request.POST, request.FILES)
        
        if form.is_valid():
            file = form.cleaned_data['image']

            instance = form.instance
            instance.request = ImageRequest.objects.get(pk=request.POST['request'])
            instance.user = request.user
            instance.image.save("%s-%s" % (datetime_string(), file.name), ContentFile(file.read()))
            io = instance.save()

            return redirect(reverse('index'))
        else:
            return render_to_response('image/imageoffer_form.html',
                {'form':form},
                context_instance=RequestContext(request))

    else:
        form = ImageOfferForm()
        return render_to_response('image/imageoffer_form.html',
            {'form':form},
            context_instance=RequestContext(request))
<commit_msg>require login<commit_after>from django.template import RequestContext
from django.views.generic import DeleteView
from django.core.urlresolvers import reverse
from django.core.files.base import ContentFile
from django.core.files.storage import default_storage
from django.shortcuts import redirect, render_to_response
from django.contrib.auth.decorators import login_required

from buddy.utils import datetime_string

from image.models import ImageRequest
from image.forms import ImageRequestForm, ImageOfferForm

class DeleteImageView(DeleteView):
    model = ImageRequest
    success_url = "/"  

@login_required
def request_image(request):
    form = ImageRequestForm(request.POST or None)

    if form.is_valid():
        instance = form.instance
        instance.user = request.user
        instance.save()
        
        return redirect(reverse('index'))

    return render_to_response('image/imagerequest_form.html',
            {'form':form},
            context_instance=RequestContext(request))

@login_required
def offer_image(request):
    if request.method == "POST":
        form = ImageOfferForm(request.POST, request.FILES)
        
        if form.is_valid():
            file = form.cleaned_data['image']

            instance = form.instance
            instance.request = ImageRequest.objects.get(pk=request.POST['request'])
            instance.user = request.user
            instance.image.save("%s-%s" % (datetime_string(), file.name), ContentFile(file.read()))
            io = instance.save()

            return redirect(reverse('index'))
        else:
            return render_to_response('image/imageoffer_form.html',
                {'form':form},
                context_instance=RequestContext(request))

    else:
        form = ImageOfferForm()
        return render_to_response('image/imageoffer_form.html',
            {'form':form},
            context_instance=RequestContext(request))

{'fraction_non_alphanumeric': 0.09697130712008502, 'fraction_numerical': 0.0, 'mean_word_length': 2.984126984126984, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '294567', 'n_tokens_mistral': 986, 'n_tokens_neox': 959, 'n_words': 207}