本文整理汇总了Python中wagtail.wagtailimages.models.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:Jimmy570,项目名称:wagtail,代码行数:8,代码来源:test_images.py
示例2: 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
示例3: get_dict_for_field
def get_dict_for_field(self, field_name):
try:
field = self.model._meta.get_field(field_name)
label = getattr(field, 'verbose_name', None)
value = getattr(self.instance, field_name, None)
if label is None:
label = field.name
try:
fieldtype = field.get_internal_type()
if fieldtype == 'ForeignKey':
if field.related_model == get_image_model():
fieldtype = 'image'
value = self.get_value_for_image_field(field_name)
if field.related_model == Document:
fieldtype = 'document'
value = self.get_value_for_document_field(field_name)
except AttributeError:
fieldtype = 'related'
value = self.get_value_for_relationship_field(field_name)
except FieldDoesNotExist:
label = field_name
fieldtype = ''
return {
'label': label.capitalize(),
'type': fieldtype,
'value': value
}
开发者ID:quru,项目名称:wagtailmodeladmin,代码行数:28,代码来源:views.py
示例4: chooser_select_format
def chooser_select_format(request, image_id):
image = get_object_or_404(get_image_model(), id=image_id)
if request.POST:
form = ImageInsertionForm(request.POST, initial={'alt_text': image.default_alt_text})
if form.is_valid():
format = get_image_format(form.cleaned_data['format'])
preview_image = image.get_rendition(format.filter_spec)
image_json = json.dumps({
'id': image.id,
'title': image.title,
'format': format.name,
'alt': form.cleaned_data['alt_text'],
'class': format.classnames,
'preview': {
'url': preview_image.url,
'width': preview_image.width,
'height': preview_image.height,
},
'html': format.image_to_editor_html(image, form.cleaned_data['alt_text']),
})
return render_modal_workflow(
request, None, 'wagtailimages/chooser/image_chosen.js',
{'image_json': image_json}
)
else:
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}
)
开发者ID:jalourenco,项目名称:wagtail,代码行数:35,代码来源:chooser.py
示例5: get_image_form
def get_image_form():
return modelform_factory(
get_image_model(),
# set the 'file' widget to a FileInput rather than the default ClearableFileInput
# so that when editing, we don't get the 'currently: ...' banner which is
# a bit pointless here
widgets={'file': forms.FileInput()})
开发者ID:100Shapes,项目名称:wagtail,代码行数:7,代码来源:forms.py
示例6: 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
示例7: 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
示例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 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
if not Filter(spec=filter_spec).is_valid():
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
return json_response({'url': site_root_url + url, 'local_url': url}, status=200)
开发者ID:100Shapes,项目名称:wagtail,代码行数:33,代码来源:images.py
示例9: preview
def preview(request, image_id, filter_spec):
image = get_object_or_404(get_image_model(), id=image_id)
try:
return Filter(spec=filter_spec).run(image, HttpResponse(content_type='image/jpeg'))
except InvalidFilterSpecError:
return HttpResponse("Invalid filter spec: " + filter_spec, content_type='text/plain', status=400)
开发者ID:EricSchles,项目名称:wagtail,代码行数:7,代码来源:images.py
示例10: preview
def preview(request, image_id, filter_spec):
image = get_object_or_404(get_image_model(), id=image_id)
try:
return Filter(spec=filter_spec).process_image(image.file.file, HttpResponse(content_type='image/jpeg'), focal_point=image.get_focal_point())
except Filter.InvalidFilterSpecError:
return HttpResponse("Invalid filter spec: " + filter_spec, content_type='text/plain', status=400)
开发者ID:Magzhan123,项目名称:TabysKTS,代码行数:7,代码来源:images.py
示例11: create_thumbnail
def create_thumbnail(model_instance):
# http://stackoverflow.com/a/25648427/1179222
from wagtail.wagtailimages.models import get_image_model
WagtailImage = get_image_model()
# CREATING IMAGE FROM THUMBNAIL
backend = detect_backend(model_instance.url)
thumbnail_url = backend.get_thumbnail_url()
if backend.__class__.__name__ == 'YoutubeBackend':
if thumbnail_url.endswith('hqdefault.jpg'):
for resolution in YOUTUBE_RESOLUTIONS:
temp_thumbnail_url = thumbnail_url.replace(
'hqdefault.jpg', resolution)
if checkUrl(temp_thumbnail_url):
thumbnail_url = temp_thumbnail_url
break
img_temp = NamedTemporaryFile(delete=True)
try:
img_temp.write(urllib2.urlopen(thumbnail_url).read())
except:
http = urllib3.PoolManager()
img_temp.write(http.request('GET', thumbnail_url).data)
img_temp.flush()
image = WagtailImage(title=model_instance.title)
image.file.save(model_instance.title + '.jpg', File(img_temp))
model_instance.thumbnail = image
model_instance.thumbnail.tags.add('video-thumbnail')
model_instance.save()
开发者ID:SalahAdDin,项目名称:wagtail-embedvideos,代码行数:31,代码来源:models.py
示例12: chooser_select_format
def chooser_select_format(request, image_id):
image = get_object_or_404(get_image_model(), id=image_id)
if request.POST:
form = ImageInsertionForm(request.POST, initial={"alt_text": image.default_alt_text})
if form.is_valid():
format = get_image_format(form.cleaned_data["format"])
preview_image = image.get_rendition(format.filter_spec)
image_json = json.dumps(
{
"id": image.id,
"title": image.title,
"format": format.name,
"alt": form.cleaned_data["alt_text"],
"class": format.classnames,
"preview": {"url": preview_image.url, "width": preview_image.width, "height": preview_image.height},
"html": format.image_to_editor_html(image, form.cleaned_data["alt_text"]),
}
)
return render_modal_workflow(
request, None, "wagtailimages/chooser/image_chosen.js", {"image_json": image_json}
)
else:
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},
)
开发者ID:rthauby,项目名称:wagtail,代码行数:34,代码来源:chooser.py
示例13: 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
示例14: 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
示例15: search
def search(request):
Image = get_image_model()
images = []
q = None
is_searching = False
if 'q' in request.GET:
form = SearchForm(request.GET)
if form.is_valid():
q = form.cleaned_data['q']
# page number
p = request.GET.get("p", 1)
is_searching = True
images = Image.search(q, results_per_page=20, page=p)
else:
form = SearchForm()
if request.is_ajax():
return render(request, "wagtailimages/images/results.html", {
'images': images,
'is_searching': is_searching,
'search_query': q,
})
else:
return render(request, "wagtailimages/images/index.html", {
'form': form,
'images': images,
'is_searching': is_searching,
'popular_tags': Image.popular_tags(),
'search_query': q,
})
开发者ID:AppDevy,项目名称:wagtail,代码行数:32,代码来源:images.py
示例16: 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:Jimmy570,项目名称:wagtail,代码行数:33,代码来源:test_images.py
示例17: edit
def edit(request, image_id, callback=None):
Image = get_image_model()
ImageForm = get_image_edit_form()
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 image.is_editable_by_user(request.user):
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 json_response({
'success': True,
'image_id': int(image_id),
})
else:
return json_response({
'success': False,
'image_id': int(image_id),
'form': render_to_string('wagtailimages/multiple/edit_form.html', {
'image': image,
'form': form,
}, context_instance=RequestContext(request)),
})
开发者ID:Magzhan123,项目名称:TabysKTS,代码行数:34,代码来源:multiple.py
示例18: render
def render(self):
return render_to_string('wagtailadmin/home/site_summary.html', {
'total_pages': Page.objects.count() - 1, # subtract 1 because the root node is not a real page
'total_images': get_image_model().objects.count(),
'total_docs': Document.objects.count(),
'search_form': SearchForm(),
}, RequestContext(self.request))
开发者ID:sixpearls,项目名称:wagtail,代码行数:7,代码来源:home.py
示例19: 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
示例20: 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:mope,项目名称:wagtail,代码行数:7,代码来源:chooser.py
注:本文中的wagtail.wagtailimages.models.get_image_model函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论