Beispiel #1
0
    def test_form_is_valid(self):
        user = self._create_user('buddy','password')
        ir = self._create_image_request()

        iof = ImageOfferForm(data={"user":user.id, "request":ir.id, "image":"image.jpg"})

        self.assertEqual(True, iof.is_valid())
Beispiel #2
0
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))