mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-12 09:13:14 +00:00
Move the image chooser HTML markup from image_chooser_panel.html entirely within the AdminImageChooser widget's render() method
This commit is contained in:
parent
41577759a1
commit
435e4571b3
5 changed files with 35 additions and 18 deletions
|
|
@ -347,8 +347,6 @@
|
|||
{% for field in example_form %}
|
||||
{% if field.name == 'file' %}
|
||||
{% include "wagtailimages/images/_file_field.html" %}
|
||||
{% elif field.name == 'image_chooser' %}
|
||||
<li>{% include "wagtailimages/edit_handlers/image_chooser_panel.html" with field=field only %}</li>
|
||||
{% else %}
|
||||
{% include "wagtailadmin/shared/field_as_li.html" %}
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ from .widgets import AdminImageChooser
|
|||
|
||||
|
||||
class BaseImageChooserPanel(BaseChooserPanel):
|
||||
field_template = "wagtailimages/edit_handlers/image_chooser_panel.html"
|
||||
object_type_name = "image"
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -1,15 +1,2 @@
|
|||
{% extends "wagtailadmin/edit_handlers/chooser_panel.html" %}
|
||||
{% load wagtailimages_tags %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block chooser_class %}image-chooser{% endblock %}
|
||||
|
||||
{% block chosen_state_view %}
|
||||
<div class="preview-image">
|
||||
{% if image %}
|
||||
{% image image max-130x130 %}
|
||||
{% else %}
|
||||
<img>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
{# Image chooser is now implemented as an entirely standard form widget - image_chooser_panel.html is redundant #}
|
||||
{% include "wagtailadmin/shared/field.html" %}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
{% extends "wagtailadmin/widgets/chooser.html" %}
|
||||
{% load wagtailimages_tags %}
|
||||
|
||||
{% block chooser_class %}image-chooser{% endblock %}
|
||||
|
||||
{% block chosen_state_view %}
|
||||
<div class="preview-image">
|
||||
{% if image %}
|
||||
{% image image max-130x130 %}
|
||||
{% else %}
|
||||
<img>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -2,9 +2,11 @@ from __future__ import absolute_import, unicode_literals
|
|||
|
||||
import json
|
||||
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from wagtail.wagtailadmin.widgets import AdminChooser
|
||||
from wagtail.wagtailimages.models import get_image_model
|
||||
|
||||
|
||||
class AdminImageChooser(AdminChooser):
|
||||
|
|
@ -12,5 +14,22 @@ class AdminImageChooser(AdminChooser):
|
|||
choose_another_text = _('Choose another image')
|
||||
clear_choice_text = _('Clear image')
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(AdminImageChooser, self).__init__(**kwargs)
|
||||
self.image_model = get_image_model()
|
||||
|
||||
def render_html(self, name, value, attrs):
|
||||
original_field_html = super(AdminImageChooser, self).render_html(name, value, attrs)
|
||||
|
||||
instance = self.get_instance(self.image_model, value)
|
||||
|
||||
return render_to_string("wagtailimages/widgets/image_chooser.html", {
|
||||
'widget': self,
|
||||
'original_field_html': original_field_html,
|
||||
'attrs': attrs,
|
||||
'value': value,
|
||||
'image': instance,
|
||||
})
|
||||
|
||||
def render_js_init(self, id_, name, value):
|
||||
return "createImageChooser({0});".format(json.dumps(id_))
|
||||
|
|
|
|||
Loading…
Reference in a new issue