本文整理汇总了Python中wagtail.images.get_image_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_image_model函数的具体用法?Python get_image_model怎么用?Python get_image_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_image_model函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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])
示例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,
})
示例3: 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, None,
None, json_data={'step': 'image_chosen', 'result': get_image_result_data(image)}
)
示例4: 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))
示例5: chooser
def chooser(request):
Image = get_image_model()
if permission_policy.user_has_permission(request.user, 'add'):
ImageForm = get_image_form(Image)
uploadform = ImageForm(user=request.user)
else:
uploadform = None
images = Image.objects.order_by('-created_at')
# allow hooks to modify the queryset
for hook in hooks.get_hooks('construct_image_chooser_queryset'):
images = hook(images, request)
if (
'q' in request.GET or 'p' in request.GET or 'tag' in request.GET or
'collection_id' in request.GET
):
# this request is triggered from search, pagination or 'popular tags';
# we will just render the results.html fragment
collection_id = request.GET.get('collection_id')
if collection_id:
images = images.filter(collection=collection_id)
searchform = SearchForm(request.GET)
if searchform.is_valid():
q = searchform.cleaned_data['q']
images = images.search(q)
is_searching = True
else:
is_searching = False
q = None
tag_name = request.GET.get('tag')
if tag_name:
images = images.filter(tags__name=tag_name)
# Pagination
paginator, images = paginate(request, images, per_page=12)
return render(request, "wagtailimages/chooser/results.html", {
'images': images,
'is_searching': is_searching,
'query_string': q,
'will_select_format': request.GET.get('select_format')
})
else:
paginator, images = paginate(request, images, per_page=12)
context = get_chooser_context(request)
context.update({
'images': images,
'uploadform': uploadform,
})
return render_modal_workflow(
request, 'wagtailimages/chooser/chooser.html', None, context,
json_data=get_chooser_js_data()
)
示例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)
示例7: test_compare_imagechooserblock
def test_compare_imagechooserblock(self):
image_model = get_image_model()
test_image_1 = image_model.objects.create(
title="Test image 1",
file=get_test_image_file(),
)
test_image_2 = image_model.objects.create(
title="Test image 2",
file=get_test_image_file(),
)
field = StreamPage._meta.get_field('body')
comparison = self.comparison_class(
field,
StreamPage(body=StreamValue(field.stream_block, [
('image', test_image_1, '1'),
])),
StreamPage(body=StreamValue(field.stream_block, [
('image', test_image_2, '1'),
])),
)
result = comparison.htmldiff()
self.assertIn('<div class="preview-image deletion">', result)
self.assertIn('alt="Test image 1"', result)
self.assertIn('<div class="preview-image addition">', result)
self.assertIn('alt="Test image 2"', result)
self.assertIsInstance(result, SafeText)
self.assertTrue(comparison.has_changed())
示例8: 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)}
)
示例9: 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', 'download_url'})
# 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'])
示例10: chooser_upload
def chooser_upload(request):
Image = get_image_model()
ImageForm = get_image_form(Image)
if request.method == 'POST':
image = Image(uploaded_by_user=request.user)
form = ImageForm(
request.POST, request.FILES, instance=image, user=request.user, prefix='image-chooser-upload'
)
if form.is_valid():
# Set image file size
image.file_size = image.file.size
# Set image file hash
image.file.seek(0)
image._set_file_hash(image.file.read())
image.file.seek(0)
form.save()
# Reindex the image to make sure all tags are indexed
search_index.insert_or_update_object(image)
if request.GET.get('select_format'):
form = ImageInsertionForm(
initial={'alt_text': image.default_alt_text}, prefix='image-chooser-insertion'
)
return render_modal_workflow(
request, 'wagtailimages/chooser/select_format.html', None,
{'image': image, 'form': form}, json_data={'step': 'select_format'}
)
else:
# not specifying a format; return the image details now
return render_modal_workflow(
request, None, None,
None, json_data={'step': 'image_chosen', 'result': get_image_result_data(image)}
)
else:
form = ImageForm(user=request.user, prefix='image-chooser-upload')
images = Image.objects.order_by('-created_at')
# allow hooks to modify the queryset
for hook in hooks.get_hooks('construct_image_chooser_queryset'):
images = hook(images, request)
paginator = Paginator(images, per_page=12)
images = paginator.get_page(request.GET.get('p'))
context = get_chooser_context(request)
context.update({
'images': images,
'uploadform': form,
})
return render_modal_workflow(
request, 'wagtailimages/chooser/chooser.html', None, context,
json_data=get_chooser_js_data()
)
示例11: 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 = Paginator(images, per_page=20)
images = paginator.get_page(request.GET.get('p'))
collections = permission_policy.collections_user_has_any_permission_for(
request.user, ['add', 'change']
)
if len(collections) < 2:
collections = None
else:
collections = Collection.order_for_display(collections)
# 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'),
})
示例12: 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))
示例13: 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
})
示例14: usage
def usage(request, image_id):
image = get_object_or_404(get_image_model(), id=image_id)
paginator = Paginator(image.get_usage(), per_page=20)
used_by = paginator.get_page(request.GET.get('p'))
return render(request, "wagtailimages/images/usage.html", {
'image': image,
'used_by': used_by
})
示例15: 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)