本文整理汇总了Python中wagtail.wagtailimages.forms.get_image_form函数的典型用法代码示例。如果您正苦于以下问题:Python get_image_form函数的具体用法?Python get_image_form怎么用?Python get_image_form使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_image_form函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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 image.is_editable_by_user(request.user):
raise PermissionDenied
if request.POST:
original_file = image.file
form = ImageForm(request.POST, request.FILES, instance=image)
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)
# 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(),
})
开发者ID:CorneliusIV,项目名称:wagtail,代码行数:60,代码来源: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:robmoorman,项目名称:wagtail,代码行数:28,代码来源:images.py
示例3: add
def add(request):
ImageForm = get_image_form()
ImageModel = get_image_model()
if request.POST:
image = ImageModel(uploaded_by_user=request.user)
form = ImageForm(request.POST, request.FILES, instance=image)
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)
messages.success(request, _("Image '{0}' added.").format(image.title))
return redirect('wagtailimages_index')
else:
messages.error(request, _("The image could not be created due to errors."))
else:
form = ImageForm()
return render(request, "wagtailimages/images/add.html", {
'form': form,
'max_filesize': MAX_UPLOAD_SIZE,
})
开发者ID:gilsondev,项目名称:wagtail,代码行数:25,代码来源:images.py
示例4: test_custom_image_model_without_admin_form_fields_raises_warning
def test_custom_image_model_without_admin_form_fields_raises_warning(self):
self.reset_warning_registry()
with warnings.catch_warnings(record=True) as raw_warnings:
form = get_image_form(CustomImageWithoutAdminFormFields)
# Check that a RemovedInWagtail12Warning has been triggered
# Ignore any ResourceWarnings. TODO: remove this when we've stopped ResourceWarnings from happening...
try:
clean_warnings = [w for w in raw_warnings if not issubclass(w.category, ResourceWarning)]
except NameError: # ResourceWarning only exists on Python >= 3.2
clean_warnings = raw_warnings
self.assertEqual(len(clean_warnings), 1)
self.assertTrue(issubclass(clean_warnings[-1].category, RemovedInWagtail12Warning))
self.assertTrue("Add admin_form_fields = (tuple of field names) to CustomImageWithoutAdminFormFields" in str(clean_warnings[-1].message))
# All fields, including the not editable one should be on the form
self.assertEqual(list(form.base_fields.keys()), [
'title',
'file',
'focal_point_x',
'focal_point_y',
'focal_point_width',
'focal_point_height',
'caption',
'not_editable_field',
'tags',
])
开发者ID:mope,项目名称:wagtail,代码行数:29,代码来源:tests.py
示例5: test_fields
def test_fields(self):
form = get_image_form(Image)
self.assertEqual(
list(form.base_fields.keys()),
["title", "file", "tags", "focal_point_x", "focal_point_y", "focal_point_width", "focal_point_height"],
)
开发者ID:carriercomm,项目名称:wagtail,代码行数:7,代码来源:tests.py
示例6: edit
def edit(request, image_id):
Image = get_image_model()
ImageForm = get_image_form()
image = get_object_or_404(Image, id=image_id)
if not image.is_editable_by_user(request.user):
raise PermissionDenied
if request.POST:
original_file = image.file
form = ImageForm(request.POST, request.FILES, instance=image)
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()
form.save()
messages.success(request, _("Image '{0}' updated.").format(image.title))
return redirect("wagtailimages_index")
else:
messages.error(request, _("The image could not be saved due to errors."))
else:
form = ImageForm(instance=image)
return render(request, "wagtailimages/images/edit.html", {"image": image, "form": form})
开发者ID:CreativeOutbreak,项目名称:wagtail,代码行数:28,代码来源:images.py
示例7: add
def add(request):
ImageModel = get_image_model()
ImageForm = get_image_form(ImageModel)
if request.POST:
image = ImageModel(uploaded_by_user=request.user)
form = ImageForm(request.POST, request.FILES, instance=image)
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
for backend in get_search_backends():
backend.add(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()
return render(request, "wagtailimages/images/add.html", {
'form': form,
})
开发者ID:WalterC87,项目名称:wagtail,代码行数:29,代码来源:images.py
示例8: test_custom_image_model_without_admin_form_fields_raises_warning
def test_custom_image_model_without_admin_form_fields_raises_warning(self):
self.reset_warning_registry()
with warnings.catch_warnings(record=True) as w:
form = get_image_form(CustomImageWithoutAdminFormFields)
# Check that a RemovedInWagtail12Warning has been triggered
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category, RemovedInWagtail12Warning))
self.assertTrue(
"Add admin_form_fields = (tuple of field names) to CustomImageWithoutAdminFormFields"
in str(w[-1].message)
)
# All fields, including the not editable one should be on the form
self.assertEqual(
list(form.base_fields.keys()),
[
"title",
"file",
"focal_point_x",
"focal_point_y",
"focal_point_width",
"focal_point_height",
"caption",
"not_editable_field",
"tags",
],
)
开发者ID:carriercomm,项目名称:wagtail,代码行数:28,代码来源:tests.py
示例9: chooser_upload
def chooser_upload(request):
Image = get_image_model()
ImageForm = get_image_form()
if request.POST:
image = Image(uploaded_by_user=request.user)
form = ImageForm(request.POST, request.FILES, instance=image)
if form.is_valid():
form.save()
if request.GET.get("select_format"):
form = ImageInsertionForm(initial={"alt_text": image.default_alt_text})
return render_modal_workflow(
request,
"wagtailimages/chooser/select_format.html",
"wagtailimages/chooser/select_format.js",
{"image": image, "form": form},
)
else:
# not specifying a format; return the image details now
return render_modal_workflow(
request, None, "wagtailimages/chooser/image_chosen.js", {"image_json": get_image_json(image)}
)
else:
form = ImageForm()
images = Image.objects.order_by("title")
return render_modal_workflow(
request,
"wagtailimages/chooser/chooser.html",
"wagtailimages/chooser/chooser.js",
{"images": images, "uploadform": form},
)
开发者ID:rthauby,项目名称:wagtail,代码行数:34,代码来源:chooser.py
示例10: chooser_upload
def chooser_upload(request):
Image = get_image_model()
ImageForm = get_image_form()
if request.POST:
image = Image(uploaded_by_user=request.user)
form = ImageForm(request.POST, request.FILES, instance=image)
if form.is_valid():
form.save()
if request.GET.get('select_format'):
form = ImageInsertionForm(initial={'alt_text': image.default_alt_text})
return render_modal_workflow(
request, 'wagtailimages/chooser/select_format.html', 'wagtailimages/chooser/select_format.js',
{'image': image, 'form': form}
)
else:
# not specifying a format; return the image details now
return render_modal_workflow(
request, None, 'wagtailimages/chooser/image_chosen.js',
{'image_json': get_image_json(image)}
)
else:
form = ImageForm()
images = Image.objects.order_by('title')
return render_modal_workflow(
request, 'wagtailimages/chooser/chooser.html', 'wagtailimages/chooser/chooser.js',
{'images': images, 'uploadform': form}
)
开发者ID:dvska,项目名称:wagtail,代码行数:31,代码来源:chooser.py
示例11: test_fields
def test_fields(self):
form = get_image_form(Image)
self.assertEqual(list(form.base_fields.keys()), [
'title',
'file',
'tags',
'focal_point_x',
'focal_point_y',
'focal_point_width',
'focal_point_height',
])
开发者ID:nrsimha,项目名称:wagtail,代码行数:12,代码来源:tests.py
示例12: test_focal_point_fields
def test_focal_point_fields(self):
form = get_image_form(WagtailImage)
self.assertIsInstance(form.base_fields['focal_point_x'], forms.IntegerField)
self.assertIsInstance(form.base_fields['focal_point_y'], forms.IntegerField)
self.assertIsInstance(form.base_fields['focal_point_width'], forms.IntegerField)
self.assertIsInstance(form.base_fields['focal_point_height'], forms.IntegerField)
self.assertIsInstance(form.base_fields['focal_point_x'].widget, forms.HiddenInput)
self.assertIsInstance(form.base_fields['focal_point_y'].widget, forms.HiddenInput)
self.assertIsInstance(form.base_fields['focal_point_width'].widget, forms.HiddenInput)
self.assertIsInstance(form.base_fields['focal_point_height'].widget, forms.HiddenInput)
开发者ID:nrsimha,项目名称:wagtail,代码行数:12,代码来源:tests.py
示例13: add
def add(request):
Image = get_image_model()
ImageForm = get_image_form(Image)
if request.method == 'POST':
if not request.is_ajax():
return HttpResponseBadRequest("Cannot POST to this view without AJAX")
if not request.FILES:
return HttpResponseBadRequest("Must upload a file")
# Build a form for validation
form = ImageForm({
'title': request.FILES['files[]'].name,
}, {
'file': request.FILES['files[]'],
})
if form.is_valid():
# Save it
image = form.save(commit=False)
image.uploaded_by_user = request.user
image.file_size = image.file.size
image.save()
# Success! Send back an edit form for this image to the user
return json_response({
'success': True,
'image_id': int(image.id),
'form': render_to_string('wagtailimages/multiple/edit_form.html', {
'image': image,
'form': get_image_edit_form(Image)(instance=image, prefix='image-%d' % image.id),
}, request=request),
})
else:
# Validation error
return json_response({
'success': False,
# https://github.com/django/django/blob/stable/1.6.x/django/forms/util.py#L45
'error_message': '\n'.join(['\n'.join([force_text(i) for i in v]) for k, v in form.errors.items()]),
})
else:
form = ImageForm()
return render(request, 'wagtailimages/multiple/add.html', {
'max_filesize': form.fields['file'].max_upload_size,
'help_text': form.fields['file'].help_text,
'allowed_extensions': ALLOWED_EXTENSIONS,
'error_max_file_size': form.fields['file'].error_messages['file_too_large_unknown_size'],
'error_accepted_file_types': form.fields['file'].error_messages['invalid_image'],
})
开发者ID:njamaleddine,项目名称:wagtail,代码行数:52,代码来源:multiple.py
示例14: chooser
def chooser(request):
Image = get_image_model()
if request.user.has_perm('wagtailimages.add_image'):
ImageForm = get_image_form(Image)
uploadform = ImageForm()
else:
uploadform = None
images = Image.objects.order_by('-created_at')
q = None
if 'q' in request.GET or 'p' in request.GET or 'tag' in request.GET:
# this request is triggered from search, pagination or 'popular tags';
# we will just render the results.html fragment
searchform = SearchForm(request.GET)
if searchform.is_valid():
q = searchform.cleaned_data['q']
images = images.search(q)
is_searching = True
else:
is_searching = False
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:
searchform = SearchForm()
paginator, images = paginate(request, images, per_page=12)
return render_modal_workflow(request, 'wagtailimages/chooser/chooser.html', 'wagtailimages/chooser/chooser.js', {
'images': images,
'uploadform': uploadform,
'searchform': searchform,
'is_searching': False,
'query_string': q,
'will_select_format': request.GET.get('select_format'),
'popular_tags': Image.popular_tags(),
})
开发者ID:qjardon,项目名称:wagtail,代码行数:52,代码来源:chooser.py
示例15: test_admin_form_fields_attribute
def test_admin_form_fields_attribute(self):
form = get_image_form(CustomImage)
self.assertEqual(list(form.base_fields.keys()), [
'title',
'file',
'tags',
'focal_point_x',
'focal_point_y',
'focal_point_width',
'focal_point_height',
'caption',
])
开发者ID:nrsimha,项目名称:wagtail,代码行数:13,代码来源:tests.py
示例16: test_admin_form_fields_attribute
def test_admin_form_fields_attribute(self):
form = get_image_form(CustomImageWithAdminFormFields)
self.assertEqual(
list(form.base_fields.keys()),
[
"title",
"file",
"tags",
"focal_point_x",
"focal_point_y",
"focal_point_width",
"focal_point_height",
"caption",
],
)
开发者ID:carriercomm,项目名称:wagtail,代码行数:16,代码来源:tests.py
示例17: get_image_edit_form
def get_image_edit_form(ImageModel):
ImageForm = get_image_form(ImageModel)
# Make a new form with the file and focal point fields excluded
class ImageEditForm(ImageForm):
class Meta(ImageForm.Meta):
model = ImageModel
exclude = (
'file',
'focal_point_x',
'focal_point_y',
'focal_point_width',
'focal_point_height',
)
return ImageEditForm
开发者ID:chrxr,项目名称:wagtail,代码行数:16,代码来源:multiple.py
示例18: poster_image_upload
def poster_image_upload(request, embed_id):
Image = get_image_model()
ImageForm = get_image_form()
searchform = SearchForm()
if request.POST:
image = Image(uploaded_by_user=request.user)
form = ImageForm(request.POST, request.FILES, instance=image)
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)
if request.GET.get('select_format'):
form = ImageInsertionForm(initial={'alt_text': image.default_alt_text})
return render_modal_workflow(
request, 'wagtailimages/chooser/select_format.html', 'wagtailimages/chooser/select_format.js',
{'image': image, 'form': form}
)
else:
# not specifying a format; return the image details now
embed = Embed.objects.get(id=embed_id)
embed_image = EmbedVideoPosterImage(embed=embed, image=image)
embed_image.save()
image_json = get_image_json(image)
return render_modal_workflow(
request, None, 'wagtailimages/chooser/poster_image_chosen.js',
{'image_json': image_json, 'posterimage_id': embed_image.id}
)
else:
form = ImageForm()
images = Image.objects.order_by('title')
return render_modal_workflow(
request, 'wagtailimages/chooser/chooser.html', 'wagtailimages/chooser/chooser.js', {
'images': images,
'uploadform': form,
'searchform': searchform,
'max_filesize': MAX_UPLOAD_SIZE,
'embed_id': embed_id
}
)
开发者ID:springload,项目名称:wagtailvideoposter,代码行数:47,代码来源:chooser.py
示例19: add
def add(request):
ImageForm = get_image_form()
ImageModel = get_image_model()
if request.POST:
image = ImageModel(uploaded_by_user=request.user)
form = ImageForm(request.POST, request.FILES, instance=image)
if form.is_valid():
form.save()
messages.success(request, _("Image '{0}' added.").format(image.title))
return redirect("wagtailimages_index")
else:
messages.error(request, _("The image could not be created due to errors."))
else:
form = ImageForm()
return render(request, "wagtailimages/images/add.html", {"form": form})
开发者ID:CreativeOutbreak,项目名称:wagtail,代码行数:17,代码来源:images.py
示例20: save_image
def save_image(self, file_path):
Image = get_image_model()
ImageForm = get_image_form(Image)
if self.is_bmp_format(file_path):
file_path = self.convert_bmp_image(file_path)
f=open(file_path, 'r')
myfile = File(f)
form = ImageForm({'title': self.title}, {'file': myfile})
#form.is_valid() == True
image = form.save(commit=False)
if self.user is not None:
image.uploaded_by_user = self.user
image.save()
return image
开发者ID:tobiase,项目名称:oc-wagtail-core,代码行数:20,代码来源:utils.py
注:本文中的wagtail.wagtailimages.forms.get_image_form函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论