当前位置: 首页>>代码示例>>Python>>正文


Python Image.is_primary方法代码示例

本文整理汇总了Python中models.Image.is_primary方法的典型用法代码示例。如果您正苦于以下问题:Python Image.is_primary方法的具体用法?Python Image.is_primary怎么用?Python Image.is_primary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Image的用法示例。


在下文中一共展示了Image.is_primary方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_uploading

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import is_primary [as 别名]
    def test_uploading(self):
        """
        Test that uploading an image works
        """
        
        test_site = Site.objects.all()[0]
        test_site_ct = ContentType.objects.get_for_model(test_site)
        test_site_id = test_site.id
        
        # check that there are no images
        self.assertEqual( Image.objects.all().count(), 0 )
        
        # create an image
        first = Image(
            content_type = test_site_ct,
            object_id    = test_site_id,
            source       = 'test directory',            
        )
        first.image.save(
            name    = 'foo.png',
            content = self.get_test_file_content('foo.png'),
        )
        
        # check that the is_primary is true
        self.assertTrue( first.is_primary )
        
        # create another image
        second = Image(
            content_type = test_site_ct,
            object_id    = test_site_id,
            source       = 'test directory',            
        )
        second.image.save(
            name    = 'bar.png',
            content = self.get_test_file_content('bar.png'),
        )
        
        # check that is_primary is false
        self.assertTrue( self.reload_image(first).is_primary )
        self.assertFalse( self.reload_image(second).is_primary )

        # change is_primary on second image
        second.is_primary = True
        second.save()
        
        # check that it changed on first too
        self.assertFalse( self.reload_image(first).is_primary )
        self.assertTrue( self.reload_image(second).is_primary )
        
        # create a third image with is_primary true at the start
        third = Image(
            content_type = test_site_ct,
            object_id    = test_site_id,
            source       = 'test directory',            
            is_primary   = True,
        )
        third.image.save(
            name    = 'baz.png',
            content = self.get_test_file_content('baz.png'),
        )
        
        # check that is_primary is updated for all
        self.assertFalse( self.reload_image(first).is_primary )
        self.assertFalse( self.reload_image(second).is_primary )
        self.assertTrue(  self.reload_image(third).is_primary )
        
        # Now try to create an thumbnail with sorl.  If this fails
        # with "IOError: decoder zip not available", then probably
        # this is a problem with an old version of PIL, or one that
        # wasn't installed when the right build dependencies were
        # present.  The simplest solution in most solutions is:
        #   pip uninstall PIL
        #   pip install pillow

        im = get_thumbnail(third.image, '100x100', crop='center', quality=99)
开发者ID:Code4SA,项目名称:pombola,代码行数:77,代码来源:tests.py

示例2: test_uploading

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import is_primary [as 别名]
    def test_uploading(self):
        """
        Test that uploading an image works
        """
        
        test_site = Site.objects.all()[0]
        test_site_ct = ContentType.objects.get_for_model(test_site)
        test_site_id = test_site.id
        
        # check that there are no images
        self.assertEqual( Image.objects.all().count(), 0 )
        
        # create an image
        first = Image(
            content_type = test_site_ct,
            object_id    = test_site_id,
            source       = 'test directory',            
        )
        first.image.save(
            name    = 'foo.png',
            content = self.get_test_file_content('foo.png'),
        )
        
        # check that the is_primary is true
        self.assertTrue( first.is_primary )
        
        # create another image
        second = Image(
            content_type = test_site_ct,
            object_id    = test_site_id,
            source       = 'test directory',            
        )
        second.image.save(
            name    = 'bar.png',
            content = self.get_test_file_content('bar.png'),
        )
        
        # check that is_primary is false
        self.assertTrue( self.reload_image(first).is_primary )
        self.assertFalse( self.reload_image(second).is_primary )

        # change is_primary on second image
        second.is_primary = True
        second.save()
        
        # check that it changed on first too
        self.assertFalse( self.reload_image(first).is_primary )
        self.assertTrue( self.reload_image(second).is_primary )
        
        # create a third image with is_primary true at the start
        third = Image(
            content_type = test_site_ct,
            object_id    = test_site_id,
            source       = 'test directory',            
            is_primary   = True,
        )
        third.image.save(
            name    = 'baz.png',
            content = self.get_test_file_content('baz.png'),
        )
        
        # check that is_primary is updated for all
        self.assertFalse( self.reload_image(first).is_primary )
        self.assertFalse( self.reload_image(second).is_primary )
        self.assertTrue(  self.reload_image(third).is_primary )
        
        
        
        
开发者ID:Dzidudu,项目名称:mzalendo,代码行数:67,代码来源:tests.py


注:本文中的models.Image.is_primary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。