• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python wagtailimages.get_image_model函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wagtail.wagtailimages.get_image_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_image_model函数的具体用法?Python get_image_model怎么用?Python get_image_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_filtering_tags

    def test_filtering_tags(self):
        get_image_model().objects.get(id=6).tags.add('test')

        response = self.get_response(tags='test')
        content = json.loads(response.content.decode('UTF-8'))

        image_id_list = self.get_image_id_list(content)
        self.assertEqual(image_id_list, [6])
开发者ID:timorieber,项目名称:wagtail,代码行数:8,代码来源:test_images.py


示例2: add

def add(request):
    ImageModel = get_image_model()
    ImageForm = get_image_form(ImageModel)

    if request.method == 'POST':
        image = ImageModel(uploaded_by_user=request.user)
        form = ImageForm(request.POST, request.FILES, instance=image, user=request.user)
        if form.is_valid():
            # Set image file size
            image.file_size = image.file.size

            form.save()

            # Reindex the image to make sure all tags are indexed
            search_index.insert_or_update_object(image)

            messages.success(request, _("Image '{0}' added.").format(image.title), buttons=[
                messages.button(reverse('wagtailimages:edit', args=(image.id,)), _('Edit'))
            ])
            return redirect('wagtailimages:index')
        else:
            messages.error(request, _("The image could not be created due to errors."))
    else:
        form = ImageForm(user=request.user)

    return render(request, "wagtailimages/images/add.html", {
        'form': form,
    })
开发者ID:timorieber,项目名称:wagtail,代码行数:28,代码来源:images.py


示例3: test_image_file_deleted_oncommit

 def test_image_file_deleted_oncommit(self):
     with transaction.atomic():
         image = get_image_model().objects.create(title="Test Image", file=get_test_image_file())
         self.assertTrue(image.file.storage.exists(image.file.name))
         image.delete()
         self.assertTrue(image.file.storage.exists(image.file.name))
     self.assertFalse(image.file.storage.exists(image.file.name))
开发者ID:timorieber,项目名称:wagtail,代码行数:7,代码来源:test_signal_handlers.py


示例4: image

def image(request, pk, specs):
    '''
    Request an image given some specs and redirects to it
    '''
    image = get_object_or_404(get_image_model(), pk=pk)
    rendition = get_rendition_or_not_found(image, specs)
    return redirect(rendition.url)
开发者ID:apihackers,项目名称:wapps,代码行数:7,代码来源:views.py


示例5: test_basic

    def test_basic(self):
        response = self.get_response()

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-type'], 'application/json')

        # Will crash if the JSON is invalid
        content = json.loads(response.content.decode('UTF-8'))

        # Check that the meta section is there
        self.assertIn('meta', content)
        self.assertIsInstance(content['meta'], dict)

        # Check that the total count is there and correct
        self.assertIn('total_count', content['meta'])
        self.assertIsInstance(content['meta']['total_count'], int)
        self.assertEqual(content['meta']['total_count'], get_image_model().objects.count())

        # Check that the items section is there
        self.assertIn('items', content)
        self.assertIsInstance(content['items'], list)

        # Check that each image has a meta section with type and detail_url attributes
        for image in content['items']:
            self.assertIn('meta', image)
            self.assertIsInstance(image['meta'], dict)
            self.assertEqual(set(image['meta'].keys()), {'type', 'detail_url', 'tags'})

            # Type should always be wagtailimages.Image
            self.assertEqual(image['meta']['type'], 'wagtailimages.Image')

            # Check detail url
            self.assertEqual(image['meta']['detail_url'], 'http://localhost/api/v2beta/images/%d/' % image['id'])
开发者ID:timorieber,项目名称:wagtail,代码行数:33,代码来源:test_images.py


示例6: register_signal_handlers

def register_signal_handlers():
    Image = get_image_model()
    Rendition = Image.get_rendition_model()

    pre_save.connect(pre_save_image_feature_detection, sender=Image)
    post_delete.connect(post_delete_file_cleanup, sender=Image)
    post_delete.connect(post_delete_file_cleanup, sender=Rendition)
开发者ID:didorothy,项目名称:wagtail,代码行数:7,代码来源:signal_handlers.py


示例7: image_chosen

def image_chosen(request, image_id):
    image = get_object_or_404(get_image_model(), id=image_id)

    return render_modal_workflow(
        request, None, 'wagtailimages/chooser/image_chosen.js',
        {'image_json': get_image_json(image)}
    )
开发者ID:chrxr,项目名称:wagtail,代码行数:7,代码来源:chooser.py


示例8: generate_url

def generate_url(request, image_id, filter_spec):
    # Get the image
    Image = get_image_model()
    try:
        image = Image.objects.get(id=image_id)
    except Image.DoesNotExist:
        return JsonResponse({"error": "Cannot find image."}, status=404)

    # Check if this user has edit permission on this image
    if not permission_policy.user_has_permission_for_instance(request.user, "change", image):
        return JsonResponse({"error": "You do not have permission to generate a URL for this image."}, status=403)

    # Parse the filter spec to make sure its valid
    try:
        Filter(spec=filter_spec).operations
    except InvalidFilterSpecError:
        return JsonResponse({"error": "Invalid filter spec."}, status=400)

    # Generate url
    signature = generate_signature(image_id, filter_spec)
    url = reverse("wagtailimages_serve", args=(signature, image_id, filter_spec))

    # Get site root url
    try:
        site_root_url = Site.objects.get(is_default_site=True).root_url
    except Site.DoesNotExist:
        site_root_url = Site.objects.first().root_url

    # Generate preview url
    preview_url = reverse("wagtailimages:preview", args=(image_id, filter_spec))

    return JsonResponse({"url": site_root_url + url, "preview_url": preview_url}, status=200)
开发者ID:robmoorman,项目名称:wagtail,代码行数:32,代码来源:images.py


示例9: test_rendition_file_deleted_oncommit

 def test_rendition_file_deleted_oncommit(self):
     with transaction.atomic():
         image = get_image_model().objects.create(title="Test Image", file=get_test_image_file())
         rendition = image.get_rendition('original')
         self.assertTrue(rendition.file.storage.exists(rendition.file.name))
         rendition.delete()
         self.assertTrue(rendition.file.storage.exists(rendition.file.name))
     self.assertFalse(rendition.file.storage.exists(rendition.file.name))
开发者ID:timorieber,项目名称:wagtail,代码行数:8,代码来源:test_signal_handlers.py


示例10: test_deprecated_get_image_model

    def test_deprecated_get_image_model(self):
        from wagtail.wagtailimages.models import get_image_model
        with warnings.catch_warnings(record=True) as ws:
            warnings.simplefilter('always')

            self.assertIs(Image, get_image_model())
            self.assertEqual(len(ws), 1)
            self.assertIs(ws[0].category, RemovedInWagtail110Warning)
开发者ID:anteatersa,项目名称:Wagtail-Image-Folders,代码行数:8,代码来源:tests.py


示例11: get_images

    def get_images(self, request):
        tags = self.tags.all()

        # Be compatible with swappable image model
        model = get_image_model()

        # Creating empty Queryset from Wagtail image model
        return model.objects.filter(tags__in=tags).distinct()
开发者ID:apihackers,项目名称:wapps,代码行数:8,代码来源:models.py


示例12: usage

def usage(request, image_id):
    image = get_object_or_404(get_image_model(), id=image_id)

    paginator, used_by = paginate(request, image.get_usage())

    return render(request, "wagtailimages/images/usage.html", {
        'image': image,
        'used_by': used_by
    })
开发者ID:timorieber,项目名称:wagtail,代码行数:9,代码来源:images.py


示例13: index

def index(request):
    Image = get_image_model()

    # Get images (filtered by user permission)
    images = permission_policy.instances_user_has_any_permission_for(request.user, ["change", "delete"]).order_by(
        "-created_at"
    )

    # Search
    query_string = None
    if "q" in request.GET:
        form = SearchForm(request.GET, placeholder=_("Search images"))
        if form.is_valid():
            query_string = form.cleaned_data["q"]

            images = images.search(query_string)
    else:
        form = SearchForm(placeholder=_("Search images"))

    # Filter by collection
    current_collection = None
    collection_id = request.GET.get("collection_id")
    if collection_id:
        try:
            current_collection = Collection.objects.get(id=collection_id)
            images = images.filter(collection=current_collection)
        except (ValueError, Collection.DoesNotExist):
            pass

    paginator, images = paginate(request, images)

    collections = permission_policy.collections_user_has_any_permission_for(request.user, ["add", "change"])
    if len(collections) < 2:
        collections = None

    # Create response
    if request.is_ajax():
        return render(
            request,
            "wagtailimages/images/results.html",
            {"images": images, "query_string": query_string, "is_searching": bool(query_string)},
        )
    else:
        return render(
            request,
            "wagtailimages/images/index.html",
            {
                "images": images,
                "query_string": query_string,
                "is_searching": bool(query_string),
                "search_form": form,
                "popular_tags": popular_tags_for_model(Image),
                "collections": collections,
                "current_collection": current_collection,
                "user_can_add": permission_policy.user_has_permission(request.user, "add"),
            },
        )
开发者ID:robmoorman,项目名称:wagtail,代码行数:57,代码来源:images.py


示例14: url_generator

def url_generator(request, image_id):
    image = get_object_or_404(get_image_model(), id=image_id)

    if not permission_policy.user_has_permission_for_instance(request.user, "change", image):
        return permission_denied(request)

    form = URLGeneratorForm(initial={"filter_method": "original", "width": image.width, "height": image.height})

    return render(request, "wagtailimages/images/url_generator.html", {"image": image, "form": form})
开发者ID:robmoorman,项目名称:wagtail,代码行数:9,代码来源:images.py


示例15: index

def index(request):
    Image = get_image_model()

    # Get images (filtered by user permission)
    images = permission_policy.instances_user_has_any_permission_for(
        request.user, ['change', 'delete']
    ).order_by('-created_at')

    # Search
    query_string = None
    if 'q' in request.GET:
        form = SearchForm(request.GET, placeholder=_("Search images"))
        if form.is_valid():
            query_string = form.cleaned_data['q']

            images = images.search(query_string)
    else:
        form = SearchForm(placeholder=_("Search images"))

    # Filter by collection
    current_collection = None
    collection_id = request.GET.get('collection_id')
    if collection_id:
        try:
            current_collection = Collection.objects.get(id=collection_id)
            images = images.filter(collection=current_collection)
        except (ValueError, Collection.DoesNotExist):
            pass

    paginator, images = paginate(request, images)

    collections = permission_policy.collections_user_has_any_permission_for(
        request.user, ['add', 'change']
    )
    if len(collections) < 2:
        collections = None

    # Create response
    if request.is_ajax():
        return render(request, 'wagtailimages/images/results.html', {
            'images': images,
            'query_string': query_string,
            'is_searching': bool(query_string),
        })
    else:
        return render(request, 'wagtailimages/images/index.html', {
            'images': images,
            'query_string': query_string,
            'is_searching': bool(query_string),

            'search_form': form,
            'popular_tags': popular_tags_for_model(Image),
            'collections': collections,
            'current_collection': current_collection,
            'user_can_add': permission_policy.user_has_permission(request.user, 'add'),
        })
开发者ID:timorieber,项目名称:wagtail,代码行数:56,代码来源:images.py


示例16: test_s3_files_use_secure_urls

    def test_s3_files_use_secure_urls(self):
        image_file = get_test_image_file(filename='test.png')

        Image = get_image_model()
        image = Image(file=image_file)

        self.assertEqual(
            image.file.url,
            'https://s3.amazonaws.com/test_s3_bucket/root/test.png'
        )
开发者ID:contolini,项目名称:cfgov-refresh,代码行数:10,代码来源:test_s3utils.py


示例17: preview

def preview(request, image_id, filter_spec):
    image = get_object_or_404(get_image_model(), id=image_id)

    try:
        response = HttpResponse()
        image = Filter(spec=filter_spec).run(image, response)
        response['Content-Type'] = 'image/' + image.format_name
        return response
    except InvalidFilterSpecError:
        return HttpResponse("Invalid filter spec: " + filter_spec, content_type='text/plain', status=400)
开发者ID:timorieber,项目名称:wagtail,代码行数:10,代码来源:images.py


示例18: test_tags

    def test_tags(self):
        image = get_image_model().objects.get(id=5)
        image.tags.add('hello')
        image.tags.add('world')

        response = self.get_response(5)
        content = json.loads(response.content.decode('UTF-8'))

        self.assertIn('tags', content['meta'])
        self.assertEqual(content['meta']['tags'], ['hello', 'world'])
开发者ID:timorieber,项目名称:wagtail,代码行数:10,代码来源:test_images.py


示例19: test_image_file_deleted

 def test_image_file_deleted(self):
     '''
         this test duplicates `test_image_file_deleted_oncommit` for
         django 1.8 support and can be removed once django 1.8 is no longer
         supported
     '''
     with transaction.atomic():
         image = get_image_model().objects.create(title="Test Image", file=get_test_image_file())
         self.assertTrue(image.file.storage.exists(image.file.name))
         image.delete()
     self.assertFalse(image.file.storage.exists(image.file.name))
开发者ID:timorieber,项目名称:wagtail,代码行数:11,代码来源:test_signal_handlers.py


示例20: test_custom_image_signal_handlers

    def test_custom_image_signal_handlers(self):
        #: Sadly signal receivers only get connected when starting django.
        #: We will re-attach them here to mimic the django startup behavior
        #: and get the signals connected to our custom model..
        signal_handlers.register_signal_handlers()

        image = get_image_model().objects.create(title="Test CustomImage", file=get_test_image_file())
        image_path = image.file.path
        image.delete()

        self.assertFalse(os.path.exists(image_path))
开发者ID:didorothy,项目名称:wagtail,代码行数:11,代码来源:test_signal_handlers.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python formats.get_image_format函数代码示例发布时间:2022-05-26
下一篇:
Python forms.FormBuilder类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap