コード例 #1
0
ファイル: tests.py プロジェクト: aaronrenner/django-imagecrop
 def testChangeCoordsNoSave(self):
     test_coords = CropCoords(40,20,500,300)
     
     file = CroppedImageFile(open('static/images/test.jpg'))
     file.crop_coords=test_coords
     # Save file
     img = models.TestImage(image=file,name="My Test")
     img.image.crop_coords = None
     self.assertEqual(img.image.crop_coords, None)
     img.save()
     
        
     #Fetch model
     new_img = models.TestImage.objects.get(name="My Test")
     
     self.assertEqual(img.image, new_img.image)
     self.assertEqual(None, new_img.image.crop_coords)
     
     #Try changing coords on fetched model and see if it takes
     new_coords = CropCoords(10,10,20,20)
     new_img.image.crop_coords=new_coords
     self.assertEqual(new_coords,new_img.image.crop_coords)
     
     #Delete to cleanup
     new_img.delete()
コード例 #2
0
    def value_from_datadict(self, data, files, name):

        values = super(CroppedImageFileInput, self).value_from_datadict(data, files, name)
        if isinstance(values[0], File):
            file = CroppedImageFile(values[0])
        else:
            file = CroppedImageFile(None)
            # return None
        file.crop_coords = values[1]
        return file
コード例 #3
0
ファイル: tests.py プロジェクト: aaronrenner/django-imagecrop
 def testSimpleCoordStorage(self):
     test_coords = CropCoords(40,20,500,300)
     
     file = CroppedImageFile(open('static/images/test.jpg'))
     file.crop_coords=test_coords
     # Save file
     img = models.TestImage(image=file,name="My Test")
     img.save()
     
     
     
     #Fetch model
     new_img = models.TestImage.objects.get(name="My Test")
     
     self.assertNotEqual(new_img,None)
     self.assertEqual(img.image, new_img.image)
     self.assertEqual(test_coords, new_img.image.crop_coords)
     
     #Delete to cleanup
     new_img.delete()