kopia lustrzana https://github.com/wagtail/wagtail
Move the page chooser HTML markup from page_chooser_panel.html entirely within the AdminPageChooser widget's render() method
rodzic
8f655cd74d
commit
6e2faa0b66
|
@ -1,5 +1,2 @@
|
|||
{% extends "wagtailadmin/edit_handlers/chooser_panel.html" %}
|
||||
|
||||
{% block chosen_state_view %}
|
||||
<span class="title">{{ page.title }}</span>
|
||||
{% endblock %}
|
||||
{# Page chooser is now implemented as an entirely standard form widget - page_chooser_panel.html is redundant #}
|
||||
{% include "wagtailadmin/shared/field.html" %}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
{% load i18n %}
|
||||
{% comment %}
|
||||
Either the chosen or unchosen div will be shown, depending on the presence
|
||||
of the 'blank' class on the container.
|
||||
|
||||
Any element with the 'action-choose' class will open the page chooser modal
|
||||
when clicked.
|
||||
{% endcomment %}
|
||||
|
||||
<div id="{{ attrs.id }}-chooser" class="chooser {% block chooser_class %}page-chooser{% endblock %} {% if not value %}blank{% endif %}">
|
||||
|
||||
<div class="chosen">
|
||||
{% block chosen_state_view %}{% endblock %}
|
||||
|
||||
<div class="actions">
|
||||
{% if not widget.is_required %}
|
||||
<input type="button" class="action-clear button-small button-secondary" value="{{ widget.clear_choice_text }}">
|
||||
{% endif %}
|
||||
<input type="button" class="action-choose button-small button-secondary" value="{{ widget.choose_another_text }}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="unchosen">
|
||||
<input type="button" class="action-choose button-small button-secondary" value="{{ widget.choose_one_text }}">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{{ original_field_html }}
|
|
@ -0,0 +1,5 @@
|
|||
{% extends "wagtailadmin/widgets/chooser.html" %}
|
||||
|
||||
{% block chosen_state_view %}
|
||||
<span class="title">{{ page.title }}</span>
|
||||
{% endblock %}
|
|
@ -42,6 +42,16 @@ class AdminChooser(WidgetWithScript, widgets.Input):
|
|||
choose_another_text = _("Choose another item")
|
||||
clear_choice_text = _("Clear choice")
|
||||
|
||||
def get_instance(self, model_class, value):
|
||||
# helper method for cleanly turning 'value' into an instance object
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
try:
|
||||
return model_class.objects.get(pk=value)
|
||||
except model_class.DoesNotExist:
|
||||
return None
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
# allow choose_one_text / choose_another_text to be overridden per-instance
|
||||
if 'choose_one_text' in kwargs:
|
||||
|
@ -65,9 +75,15 @@ class AdminPageChooser(AdminChooser):
|
|||
def render_html(self, name, value, attrs):
|
||||
original_field_html = super(AdminPageChooser, self).render_html(name, value, attrs)
|
||||
|
||||
model_class = self.target_content_type.model_class()
|
||||
instance = self.get_instance(model_class, value)
|
||||
|
||||
return render_to_string("wagtailadmin/widgets/page_chooser.html", {
|
||||
'original_field_html': original_field_html,
|
||||
'widget': self,
|
||||
'original_field_html': original_field_html,
|
||||
'attrs': attrs,
|
||||
'value': value,
|
||||
'page': instance,
|
||||
})
|
||||
|
||||
def render_js_init(self, id_, name, value):
|
||||
|
|
Ładowanie…
Reference in New Issue