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


Python files.ImageFieldFile方法代码示例

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


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

示例1: init_platform

# 需要导入模块: from django.db.models.fields import files [as 别名]
# 或者: from django.db.models.fields.files import ImageFieldFile [as 别名]
def init_platform(sender, **kwargs):
    platforms = (
        {'name':u'斗鱼', 'url':'http://www.douyu.com/', 'intro':u'当下最火的游戏直播平台', 'logo':'platform_logos/1.jpg'},
        {'name':u'虎牙', 'url':'http://www.huya.com/', 'intro':u'YY旗下直播网站', 'logo':'platform_logos/2.jpg'},
        {'name':u'战旗', 'url':'http://www.zhanqi.com/', 'intro':u'浙报传媒与边锋网络共同打造', 'logo':'platform_logos/3.jpg'},
        {'name':u'龙珠', 'url':'http://www.longzhu.com/', 'intro':u'腾讯旗下', 'logo':'platform_logos/4.jpg'},
        {'name':u'熊猫', 'url':'http://www.panda.tv/', 'intro':u'王思聪投资', 'logo':'platform_logos/5.jpg'},
    )
    for item in platforms:
        my_module = sender.get_model('Platform')
        try:
            p = get_object_or_404(my_module, name=item['name'])
        except Http404:
            p = my_module()
            p.name = item['name']
            p.url = item['url']
            p.introduce = item['intro']
            p.logo = ImageFieldFile(p, p.logo, item['logo'])
            p.save() 
开发者ID:infinity1207,项目名称:thirtylol,代码行数:21,代码来源:apps.py

示例2: render

# 需要导入模块: from django.db.models.fields import files [as 别名]
# 或者: from django.db.models.fields.files import ImageFieldFile [as 别名]
def render(self, context):
        try:
            self.value = self.value.resolve(context)
            if not isinstance(self.value, ImageFieldFile):
                raise template.VariableDoesNotExist(
                    'Image argument should be an ImageField')
            images = context.dicts[0].setdefault('ootemplate_imgs', {})

            id = len(images)
            z_index = id + 3  # Magic
            width = self.value.width * PIXEL_TO_CM
            height = self.value.height * PIXEL_TO_CM
            filename = os.path.basename(self.value.name)
            basename = os.path.splitext(filename)[0]

            images[self.value.path] = self.value
            return ('<draw:frame draw:style-name="gr%(z_index)s" '
                    'draw:name="%(basename)s" '
                    'draw:id="id%(id)s" '
                    'text:anchor-type="char" svg:width="%(width)fcm" '
                    'svg:height="%(height)fcm" draw:z-index="%(z_index)s">'
                    '<draw:image xlink:href="Pictures/%(filename)s" '
                    'xlink:type="simple" xlink:show="embed" '
                    'xlink:actuate="onLoad"/></draw:frame>') % locals()
        except template.VariableDoesNotExist:
            return '' 
开发者ID:alexmorozov,项目名称:templated-docs,代码行数:28,代码来源:templated_docs_tags.py

示例3: progressive

# 需要导入模块: from django.db.models.fields import files [as 别名]
# 或者: from django.db.models.fields.files import ImageFieldFile [as 别名]
def progressive(image_field, alt_text=''):
    """
    Used as a Jinja2 filter, this function returns a safe HTML chunk.

    Usage (in the HTML template):

        {{ obj.image|progressive }}

    :param django.db.models.fields.files.ImageFieldFile image_field: image
    :param str alt_text: str
    :return: a safe HTML template ready to be rendered
    """
    if not isinstance(image_field, ImageFieldFile):
        raise ValueError('"image_field" argument must be an ImageField.')

    for engine in engines.all():
        if isinstance(engine, BaseEngine) and hasattr(engine, 'env'):
            env = engine.env
            if isinstance(env, Environment):
                context = render_progressive_field(image_field, alt_text)
                template = env.get_template(
                    'progressiveimagefield/render_field.html'
                )
                rendered = template.render(**context)
                return Markup(rendered)
    return '' 
开发者ID:manikos,项目名称:django-progressiveimagefield,代码行数:28,代码来源:filters.py

示例4: test_django_image_files

# 需要导入模块: from django.db.models.fields import files [as 别名]
# 或者: from django.db.models.fields.files import ImageFieldFile [as 别名]
def test_django_image_files(self):
        from django.db.models.fields import files
        field = files.FileField()
        f = SourceFile(files.FieldFile(field=field, instance=None, name=self.FILE_PATH))
        self.assertEqual(f.file, self.FILE_PATH)
        f = SourceFile(files.ImageFieldFile(field=field, instance=None, name=self.FILE_PATH))
        self.assertEqual(f.file, self.FILE_PATH) 
开发者ID:python-thumbnails,项目名称:python-thumbnails,代码行数:9,代码来源:test_images.py

示例5: value_from_datadict

# 需要导入模块: from django.db.models.fields import files [as 别名]
# 或者: from django.db.models.fields.files import ImageFieldFile [as 别名]
def value_from_datadict(self, data, files, name):
        value = super(CustomClearableFileInput, self).value_from_datadict(data, files, name)

        # value is false if the clear image check box is set
        if value is False:
            userModelAvatarField = get_user_model().avatar.field
            value = self.__class__.defaultAvatar = ImageFieldFile(instance=None,
                                                                  field=userModelAvatarField, name=defaultAvatar)

        return value 
开发者ID:iguana-project,项目名称:iguana,代码行数:12,代码来源:widgets.py

示例6: default

# 需要导入模块: from django.db.models.fields import files [as 别名]
# 或者: from django.db.models.fields.files import ImageFieldFile [as 别名]
def default(self, obj):
        if isinstance(obj, datetime):
            #return obj.__str__()
            return "{}-{}-{} {}:{}:{}".format(obj.year, obj.month, obj.day,obj.hour,obj.minute,obj.second)
        elif isinstance(obj,  uuid.UUID):
            return str(obj)
        elif isinstance(obj, ImageFieldFile):
            return str(obj)
        return json.JSONEncoder.default(self, obj) 
开发者ID:fengjinqi,项目名称:website,代码行数:11,代码来源:jsonserializable.py

示例7: test_add_indoor_new_location_new_floorplan

# 需要导入模块: from django.db.models.fields import files [as 别名]
# 或者: from django.db.models.fields.files import ImageFieldFile [as 别名]
def test_add_indoor_new_location_new_floorplan(self):
        self._login_as_admin()
        p = self._get_prefix()
        params = self.params
        floorplan_file = open(self._floorplan_path, 'rb')
        params.update(
            {
                'name': 'test-add-indoor-new-location-new-floorplan',
                '{0}-0-type'.format(p): 'indoor',
                '{0}-0-location_selection'.format(p): 'new',
                '{0}-0-location'.format(p): '',
                '{0}-0-floorplan_selection'.format(p): 'new',
                '{0}-0-floorplan'.format(p): '',
                '{0}-0-floor'.format(p): '1',
                '{0}-0-image'.format(p): floorplan_file,
                '{0}-0-indoor'.format(p): '-100,100',
                '{0}-0-id'.format(p): '',
            }
        )
        r = self.client.post(reverse(self.add_url), params, follow=True)
        floorplan_file.close()
        self.assertNotContains(r, 'errors')
        loc = self.location_model.objects.get(name=params['{0}-0-name'.format(p)])
        self.assertEqual(loc.address, params['{0}-0-address'.format(p)])
        self.assertEqual(
            loc.geometry.coords, GEOSGeometry(params['{0}-0-geometry'.format(p)]).coords
        )
        self.assertEqual(loc.objectlocation_set.count(), 1)
        self.assertEqual(self.location_model.objects.count(), 1)
        self.assertEqual(self.floorplan_model.objects.count(), 1)
        ol = loc.objectlocation_set.first()
        self.assertEqual(ol.content_object.name, params['name'])
        self.assertEqual(ol.location.type, 'indoor')
        self.assertEqual(ol.floorplan.floor, 1)
        self.assertIsInstance(ol.floorplan.image, ImageFieldFile)
        self.assertEqual(ol.indoor, '-100,100') 
开发者ID:openwisp,项目名称:django-loci,代码行数:38,代码来源:test_admin_inline.py

示例8: _get_json_for_families

# 需要导入模块: from django.db.models.fields import files [as 别名]
# 或者: from django.db.models.fields.files import ImageFieldFile [as 别名]
def _get_json_for_families(families, user=None, add_individual_guids_field=False, project_guid=None, skip_nested=False):
    """Returns a JSON representation of the given Family.

    Args:
        families (array): array of django models representing the family.
        user (object): Django User object for determining whether to include restricted/internal-only fields
        add_individual_guids_field (bool): whether to add an 'individualGuids' field. NOTE: this will require a database query.
        project_guid (boolean): An optional field to use as the projectGuid instead of querying the DB
    Returns:
        array: json objects
    """

    def _get_pedigree_image_url(pedigree_image):
        if isinstance(pedigree_image, ImageFieldFile):
            try:
                pedigree_image = pedigree_image.url
            except Exception:
                pedigree_image = None
        return os.path.join("/media/", pedigree_image) if pedigree_image else None

    def _process_result(result, family):
        result['analysedBy'] = [{
            'createdBy': {'fullName': ab.created_by.get_full_name(), 'email': ab.created_by.email, 'isStaff': ab.created_by.is_staff},
            'lastModifiedDate': ab.last_modified_date,
        } for ab in family.familyanalysedby_set.all()]
        pedigree_image = _get_pedigree_image_url(result.pop('pedigreeImage'))
        result['pedigreeImage'] = pedigree_image
        if add_individual_guids_field:
            result['individualGuids'] = [i.guid for i in family.individual_set.all()]
        if not result['displayName']:
            result['displayName'] = result['familyId']
        if result['assignedAnalyst']:
            result['assignedAnalyst'] = {
                'fullName': result['assignedAnalyst'].get_full_name(),
                'email': result['assignedAnalyst'].email,
            }
        else:
            result['assignedAnalyst'] = None

    prefetch_related_objects(families, 'assigned_analyst')
    prefetch_related_objects(families, 'familyanalysedby_set__created_by')
    if add_individual_guids_field:
        prefetch_related_objects(families, 'individual_set')

    if project_guid or not skip_nested:
        kwargs = {'nested_fields': [{'fields': ('project', 'guid'), 'value': project_guid}]}
    else:
        kwargs = {'additional_model_fields': ['project_id']}

    return _get_json_for_models(families, user=user, process_result=_process_result, **kwargs) 
开发者ID:macarthur-lab,项目名称:seqr,代码行数:52,代码来源:orm_to_json_utils.py

示例9: test_add_indoor_existing_location_new_floorplan

# 需要导入模块: from django.db.models.fields import files [as 别名]
# 或者: from django.db.models.fields.files import ImageFieldFile [as 别名]
def test_add_indoor_existing_location_new_floorplan(self):
        self._login_as_admin()
        pre_loc = self._create_location(type='indoor')
        p = self._get_prefix()
        params = self.params
        floorplan_file = open(self._floorplan_path, 'rb')
        name = 'test-add-indoor-existing-location-new-floorplan'
        params.update(
            {
                'name': name,
                '{0}-0-type'.format(p): 'indoor',
                '{0}-0-location_selection'.format(p): 'existing',
                '{0}-0-location'.format(p): pre_loc.id,
                '{0}-0-name'.format(p): pre_loc.name,
                '{0}-0-address'.format(p): pre_loc.address,
                '{0}-0-geometry'.format(p): pre_loc.geometry.geojson,
                '{0}-0-floorplan_selection'.format(p): 'new',
                '{0}-0-floorplan'.format(p): '',
                '{0}-0-floor'.format(p): '0',
                '{0}-0-image'.format(p): floorplan_file,
                '{0}-0-indoor'.format(p): '-100,100',
                '{0}-0-id'.format(p): '',
            }
        )
        r = self.client.post(reverse(self.add_url), params, follow=True)
        floorplan_file.close()
        # with open('test.html', 'w') as f:
        #     f.write(r.content.decode())
        self.assertNotContains(r, 'errors')
        loc = self.location_model.objects.get(name=params['{0}-0-name'.format(p)])
        self.assertEqual(loc.address, params['{0}-0-address'.format(p)])
        self.assertEqual(
            loc.geometry.coords, GEOSGeometry(params['{0}-0-geometry'.format(p)]).coords
        )
        self.assertEqual(loc.objectlocation_set.count(), 1)
        self.assertEqual(self.location_model.objects.count(), 1)
        self.assertEqual(self.floorplan_model.objects.count(), 1)
        ol = loc.objectlocation_set.first()
        self.assertEqual(ol.content_object.name, params['name'])
        self.assertEqual(ol.location.type, 'indoor')
        self.assertEqual(ol.floorplan.floor, 0)
        self.assertIsInstance(ol.floorplan.image, ImageFieldFile)
        self.assertEqual(ol.indoor, '-100,100') 
开发者ID:openwisp,项目名称:django-loci,代码行数:45,代码来源:test_admin_inline.py

示例10: test_add_indoor_existing_location_existing_floorplan

# 需要导入模块: from django.db.models.fields import files [as 别名]
# 或者: from django.db.models.fields.files import ImageFieldFile [as 别名]
def test_add_indoor_existing_location_existing_floorplan(self):
        self._login_as_admin()
        pre_loc = self._create_location(type='indoor')
        pre_fl = self._create_floorplan(location=pre_loc, floor=2)
        p = self._get_prefix()
        params = self.params
        name = 'test-add-indoor-existing-location-new-floorplan'
        params.update(
            {
                'name': name,
                '{0}-0-type'.format(p): 'indoor',
                '{0}-0-location_selection'.format(p): 'existing',
                '{0}-0-location'.format(p): pre_loc.id,
                '{0}-0-name'.format(p): name,
                '{0}-0-address'.format(p): pre_loc.address,
                '{0}-0-location-geometry'.format(p): pre_loc.geometry,
                '{0}-0-floorplan_selection'.format(p): 'existing',
                '{0}-0-floorplan'.format(p): pre_fl.id,
                '{0}-0-floor'.format(p): 3,  # floor
                '{0}-0-image'.format(p): '',
                '{0}-0-indoor'.format(p): '-110,110',
                '{0}-0-id'.format(p): '',
            }
        )
        r = self.client.post(reverse(self.add_url), params, follow=True)
        self.assertNotContains(r, 'errors')
        loc = self.location_model.objects.get(name=name)
        self.assertEqual(loc.id, pre_loc.id)
        self.assertEqual(loc.address, params['{0}-0-address'.format(p)])
        self.assertEqual(
            loc.geometry.coords, GEOSGeometry(params['{0}-0-geometry'.format(p)]).coords
        )
        self.assertEqual(loc.objectlocation_set.count(), 1)
        self.assertEqual(self.location_model.objects.count(), 1)
        self.assertEqual(self.floorplan_model.objects.count(), 1)
        ol = loc.objectlocation_set.first()
        self.assertEqual(ol.content_object.name, params['name'])
        self.assertEqual(ol.location.type, 'indoor')
        self.assertEqual(ol.floorplan.id, pre_fl.id)
        self.assertEqual(ol.floorplan.floor, 3)
        self.assertIsInstance(ol.floorplan.image, ImageFieldFile)
        self.assertEqual(ol.indoor, '-110,110') 
开发者ID:openwisp,项目名称:django-loci,代码行数:44,代码来源:test_admin_inline.py

示例11: test_change_indoor

# 需要导入模块: from django.db.models.fields import files [as 别名]
# 或者: from django.db.models.fields.files import ImageFieldFile [as 别名]
def test_change_indoor(self):
        self._login_as_admin()
        p = self._get_prefix()
        obj = self._create_object(name='test-change-indoor')
        pre_loc = self._create_location(type='indoor')
        pre_fl = self._create_floorplan(location=pre_loc)
        ol = self._create_object_location(
            content_object=obj, location=pre_loc, floorplan=pre_fl, indoor='-100,100'
        )
        # -- ensure change form doesn't raise any exception
        r = self.client.get(reverse(self.change_url, args=[obj.pk]))
        self.assertContains(r, obj.name)
        # -- post changes
        params = self.params
        floorplan_file = open(self._floorplan_path, 'rb')
        changed_name = '{0} changed'.format(pre_loc.name)
        params.update(
            {
                'name': obj.name,
                '{0}-0-type'.format(p): 'indoor',
                '{0}-0-location_selection'.format(p): 'existing',
                '{0}-0-location'.format(p): pre_loc.id,
                '{0}-0-name'.format(p): changed_name,
                '{0}-0-address'.format(p): 'changed-address',
                '{0}-0-location-geometry'.format(p): pre_loc.geometry,
                '{0}-0-floorplan_selection'.format(p): 'existing',
                '{0}-0-floorplan'.format(p): pre_fl.id,
                '{0}-0-floor'.format(p): 3,  # floor
                '{0}-0-image'.format(p): floorplan_file,
                '{0}-0-indoor'.format(p): '-110,110',
                '{0}-0-id'.format(p): ol.id,
                '{0}-INITIAL_FORMS'.format(p): '1',
            }
        )
        r = self.client.post(
            reverse(self.change_url, args=[obj.pk]), params, follow=True
        )
        floorplan_file.close()
        self.assertNotContains(r, 'errors')
        loc = self.location_model.objects.get(name=changed_name)
        self.assertEqual(loc.id, pre_loc.id)
        self.assertEqual(loc.address, 'changed-address')
        self.assertEqual(
            loc.geometry.coords, GEOSGeometry(params['{0}-0-geometry'.format(p)]).coords
        )
        self.assertEqual(loc.objectlocation_set.count(), 1)
        self.assertEqual(self.location_model.objects.count(), 1)
        self.assertEqual(self.floorplan_model.objects.count(), 1)
        ol = loc.objectlocation_set.first()
        self.assertEqual(ol.content_object.name, params['name'])
        self.assertEqual(ol.location.type, 'indoor')
        self.assertEqual(ol.floorplan.id, pre_fl.id)
        self.assertEqual(ol.floorplan.floor, 3)
        self.assertIsInstance(ol.floorplan.image, ImageFieldFile)
        self.assertEqual(ol.indoor, '-110,110') 
开发者ID:openwisp,项目名称:django-loci,代码行数:57,代码来源:test_admin_inline.py


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