本文整理汇总了Python中wagtail.wagtailimages.permissions.permission_policy.user_has_permission_for_instance函数的典型用法代码示例。如果您正苦于以下问题:Python user_has_permission_for_instance函数的具体用法?Python user_has_permission_for_instance怎么用?Python user_has_permission_for_instance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了user_has_permission_for_instance函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 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:tomdyson,项目名称:wagtail,代码行数:32,代码来源:images.py
示例2: edit
def edit(request, image_id, callback=None):
Image = get_image_model()
ImageForm = get_image_edit_form(Image)
image = get_object_or_404(Image, id=image_id)
if not request.is_ajax():
return HttpResponseBadRequest("Cannot POST to this view without AJAX")
if not permission_policy.user_has_permission_for_instance(request.user, 'change', image):
raise PermissionDenied
form = ImageForm(request.POST, request.FILES, instance=image, prefix='image-' + image_id)
if form.is_valid():
form.save()
# Reindex the image to make sure all tags are indexed
for backend in get_search_backends():
backend.add(image)
return JsonResponse({
'success': True,
'image_id': int(image_id),
})
else:
return JsonResponse({
'success': False,
'image_id': int(image_id),
'form': render_to_string('wagtailimages/multiple/edit_form.html', {
'image': image,
'form': form,
}, request=request),
})
开发者ID:AdamBolfik,项目名称:wagtail,代码行数:34,代码来源:multiple.py
示例3: 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:tomdyson,项目名称:wagtail,代码行数:9,代码来源:images.py
示例4: delete
def delete(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, "delete", image):
return permission_denied(request)
if request.POST:
image.delete()
messages.success(request, _("Image '{0}' deleted.").format(image.title))
return redirect("wagtailimages:index")
return render(request, "wagtailimages/images/confirm_delete.html", {"image": image})
开发者ID:tomdyson,项目名称:wagtail,代码行数:12,代码来源:images.py
示例5: delete
def delete(request, image_id):
image = get_object_or_404(get_image_model(), id=image_id)
if not request.is_ajax():
return HttpResponseBadRequest("Cannot POST to this view without AJAX")
if not permission_policy.user_has_permission_for_instance(request.user, 'delete', image):
raise PermissionDenied
image.delete()
return JsonResponse({
'success': True,
'image_id': int(image_id),
})
开发者ID:chrxr,项目名称:wagtail,代码行数:15,代码来源:multiple.py
示例6: 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:DimiC,项目名称:wagtail,代码行数:16,代码来源:images.py
示例7: delete
def delete(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, 'delete', image):
return permission_denied(request)
if image.folder:
parent_folder = image.folder
else:
parent_folder = False
if request.method == 'POST':
image.delete()
messages.success(request, _("Image '{0}' deleted.").format(image.title))
response = redirect('wagtailimages:index')
if parent_folder:
response['Location'] += '?folder={0}'.format(parent_folder.id)
return response
return render(request, "wagtailimages/images/confirm_delete.html", {
'image': image,
})
开发者ID:anteatersa,项目名称:Wagtail-Image-Folders,代码行数:23,代码来源:images.py
示例8: is_editable_by_user
def is_editable_by_user(self, user):
from wagtail.wagtailimages.permissions import permission_policy
return permission_policy.user_has_permission_for_instance(user, 'change', self)
开发者ID:InnovaCo,项目名称:wagtail,代码行数:3,代码来源:models.py
示例9: edit
def edit(request, image_id):
Image = get_image_model()
ImageForm = get_image_form(Image)
image = get_object_or_404(Image, id=image_id)
if not permission_policy.user_has_permission_for_instance(request.user, 'change', image):
return permission_denied(request)
if request.method == 'POST':
original_file = image.file
form = ImageForm(request.POST, request.FILES, instance=image, user=request.user)
if form.is_valid():
if 'file' in form.changed_data:
# if providing a new image file, delete the old one and all renditions.
# NB Doing this via original_file.delete() clears the file field,
# which definitely isn't what we want...
original_file.storage.delete(original_file.name)
image.renditions.all().delete()
# Set new image file size
image.file_size = image.file.size
form.save()
# Reindex the image to make sure all tags are indexed
for backend in get_search_backends():
backend.add(image)
messages.success(request, _("Image '{0}' updated.").format(image.title), buttons=[
messages.button(reverse('wagtailimages:edit', args=(image.id,)), _('Edit again'))
])
return redirect('wagtailimages:index')
else:
messages.error(request, _("The image could not be saved due to errors."))
else:
form = ImageForm(instance=image, user=request.user)
# Check if we should enable the frontend url generator
try:
reverse('wagtailimages_serve', args=('foo', '1', 'bar'))
url_generator_enabled = True
except NoReverseMatch:
url_generator_enabled = False
if image.is_stored_locally():
# Give error if image file doesn't exist
if not os.path.isfile(image.file.path):
messages.error(request, _(
"The source image file could not be found. Please change the source or delete the image."
).format(image.title), buttons=[
messages.button(reverse('wagtailimages:delete', args=(image.id,)), _('Delete'))
])
return render(request, "wagtailimages/images/edit.html", {
'image': image,
'form': form,
'url_generator_enabled': url_generator_enabled,
'filesize': image.get_file_size(),
'user_can_delete': permission_policy.user_has_permission_for_instance(
request.user, 'delete', image
),
})
开发者ID:DimiC,项目名称:wagtail,代码行数:63,代码来源:images.py
注:本文中的wagtail.wagtailimages.permissions.permission_policy.user_has_permission_for_instance函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论