本文整理汇总了Python中wagtail.wagtailimages.utils.generate_signature函数的典型用法代码示例。如果您正苦于以下问题:Python generate_signature函数的具体用法?Python generate_signature怎么用?Python generate_signature使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了generate_signature函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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 json_response({"error": "Cannot find image."}, status=404)
# Check if this user has edit permission on this image
if not image.is_editable_by_user(request.user):
return json_response({"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 json_response({"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 json_response({"url": site_root_url + url, "preview_url": preview_url}, status=200)
开发者ID:pjdelport,项目名称:wagtail,代码行数:32,代码来源:images.py
示例2: test_get_invalid_signature
def test_get_invalid_signature(self):
"""
Test that an invalid signature returns a 403 response
"""
# Generate a signature for the incorrect image id
signature = generate_signature(self.image.id + 1, 'fill-800x600')
# Get the image
response = self.client.get(reverse('wagtailimages_serve', args=(signature, self.image.id, 'fill-800x600')))
# Check response
self.assertEqual(response.status_code, 403)
开发者ID:nrsimha,项目名称:wagtail,代码行数:12,代码来源:tests.py
示例3: generate_image_url
def generate_image_url(image, filter_spec):
signature = generate_signature(image.id, filter_spec)
url = reverse('wagtailimages_serve', args=(signature, image.id, filter_spec))
try:
site_root_url = Site.objects.get(is_default_site=True).root_url
except Site.DoesNotExist:
site_root_url = Site.objects.first().root_url
image_filename = image.file.name[len('original_images/'):]
return site_root_url + url + image_filename
开发者ID:simudream,项目名称:wagtailapidemo,代码行数:12,代码来源:utils.py
示例4: test_get
def test_get(self):
"""
Test a valid GET request to the view
"""
# Generate signature
signature = generate_signature(self.image.id, "fill-800x600")
# Get the image
response = self.client.get(reverse("wagtailimages_serve", args=(signature, self.image.id, "fill-800x600")))
# Check response
self.assertEqual(response.status_code, 200)
self.assertEqual(response["Content-Type"], "image/png")
开发者ID:carriercomm,项目名称:wagtail,代码行数:13,代码来源:tests.py
示例5: test_get_invalid_filter_spec
def test_get_invalid_filter_spec(self):
"""
Test that an invalid filter spec returns a 400 response
This is very unlikely to happen in reality. A user would have
to create signature for the invalid filter spec which can't be
done with Wagtails built in URL generator. We should test it
anyway though.
"""
# Generate a signature with the invalid filterspec
signature = generate_signature(self.image.id, 'bad-filter-spec')
# Get the image
response = self.client.get(reverse('wagtailimages_serve', args=(signature, self.image.id, 'bad-filter-spec')))
# Check response
self.assertEqual(response.status_code, 400)
开发者ID:nrsimha,项目名称:wagtail,代码行数:17,代码来源:tests.py
示例6: 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:Anlim,项目名称:wagtail,代码行数:38,代码来源:images.py
示例7: test_get
def test_get(self):
"""
This tests that the view responds correctly for a user with edit permissions on this image
"""
# Get
response = self.client.get(reverse('wagtailimages:generate_url', args=(self.image.id, 'fill-800x600')))
# Check response
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-Type'], 'application/json')
# Check JSON
content_json = json.loads(response.content.decode())
self.assertEqual(set(content_json.keys()), set(['url', 'preview_url']))
expected_url = 'http://localhost/images/%(signature)s/%(image_id)d/fill-800x600/' % {
'signature': urlquote(generate_signature(self.image.id, 'fill-800x600').decode(), safe=urlquote_safechars),
'image_id': self.image.id,
}
self.assertEqual(content_json['url'], expected_url)
expected_preview_url = reverse('wagtailimages:preview', args=(self.image.id, 'fill-800x600'))
self.assertEqual(content_json['preview_url'], expected_preview_url)
开发者ID:njamaleddine,项目名称:wagtail,代码行数:24,代码来源:test_admin_views.py
示例8: test_signature_generation
def test_signature_generation(self):
self.assertEqual(generate_signature(100, 'fill-800x600'), b'xnZOzQyUg6pkfciqcfRJRosOrGg=')
开发者ID:nrsimha,项目名称:wagtail,代码行数:2,代码来源:tests.py
注:本文中的wagtail.wagtailimages.utils.generate_signature函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论