Ejemplo n.º 1
0
def add_multiformats(request):
    """Submit image using form where format can be chosen"""
    if request.method == 'POST':
        form = MultipleFormatImageForm(
            Image.formats(),
            request.POST,
            request.FILES
        )
        if form.is_valid():
            form.save()
            return redirect('/')
    else:
        form = MultipleFormatImageForm(Image.formats())
    return render(request, 'django_images.html', dict(form=form))
Ejemplo n.º 2
0
def add_multiformats(request):
    """Submit image using form where format can be chosen"""
    if request.method == 'POST':
        form = MultipleFormatImageForm(Image.formats(), request.POST,
                                       request.FILES)
        if form.is_valid():
            form.save()
            return redirect('/')
    else:
        form = MultipleFormatImageForm(Image.formats())
    return render(request, 'django_images.html', dict(form=form))
Ejemplo n.º 3
0
    def test_multi_format_validation(self):
        """Validate an image against a complex format"""
        filepath = os.path.join(settings.BASE_DIR, 'big.jpeg')

        with open(filepath) as f:
            # prepare form data
            image = InMemoryUploadedFile(
                f,
                'image',
                'big.jpeg',
                'image/jpeg',
                42,  # not significant for the test
                'utf-8')
            files = MultiValueDict()
            files['image'] = image
            post = MultiValueDict()
            post['name'] = 'test image'
            post['fmt'] = 'TestImage'
            # create form
            form = MultipleFormatImageForm(Image.formats(), post, files)
            # validate resize operation
            v = form.is_valid()
            self.assertTrue(v)
Ejemplo n.º 4
0
    def test_multi_format_validation(self):
        """Validate an image against a complex format"""
        filepath = os.path.join(settings.BASE_DIR, 'big.jpeg')

        with open(filepath) as f:
            # prepare form data
            image = InMemoryUploadedFile(
                f,
                'image',
                'big.jpeg',
                'image/jpeg',
                42,  # not significant for the test
                'utf-8'
            )
            files = MultiValueDict()
            files['image'] = image
            post = MultiValueDict()
            post['name'] = 'test image'
            post['fmt'] = 'TestImage'
            # create form
            form = MultipleFormatImageForm(Image.formats(), post, files)
            # validate resize operation
            v = form.is_valid()
            self.assertTrue(v)