Move the document chooser HTML markup from document_chooser_panel.html entirely within the AdminDocumentChooser widget's render() method

pull/976/head
Matt Westcott 2015-02-09 18:58:17 +00:00
rodzic fe797437e7
commit 41577759a1
5 zmienionych plików z 23 dodań i 10 usunięć

Wyświetl plik

@ -349,8 +349,6 @@
{% 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>
{% elif field.name == 'document_chooser' %}
<li>{% include "wagtaildocs/edit_handlers/document_chooser_panel.html" with field=field only %}</li>
{% else %}
{% include "wagtailadmin/shared/field_as_li.html" %}
{% endif %}

Wyświetl plik

@ -5,7 +5,6 @@ from .widgets import AdminDocumentChooser
class BaseDocumentChooserPanel(BaseChooserPanel):
field_template = "wagtaildocs/edit_handlers/document_chooser_panel.html"
object_type_name = "document"
@classmethod

Wyświetl plik

@ -1,7 +1,2 @@
{% extends "wagtailadmin/edit_handlers/chooser_panel.html" %}
{% load i18n %}
{% block chooser_class %}document-chooser{% endblock %}
{% block chosen_state_view %}
<span class="title">{{ document.title }}</span>
{% endblock %}
{# Document chooser is now implemented as an entirely standard form widget - document_chooser_panel.html is redundant #}
{% include "wagtailadmin/shared/field.html" %}

Wyświetl plik

@ -0,0 +1,6 @@
{% extends "wagtailadmin/widgets/chooser.html" %}
{% block chooser_class %}document-chooser{% endblock %}
{% block chosen_state_view %}
<span class="title">{{ document.title }}</span>
{% endblock %}

Wyświetl plik

@ -2,14 +2,29 @@ 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.wagtaildocs.models import Document
class AdminDocumentChooser(AdminChooser):
choose_one_text = _('Choose a document')
choose_another_text = _('Choose another document')
def render_html(self, name, value, attrs):
original_field_html = super(AdminDocumentChooser, self).render_html(name, value, attrs)
instance = self.get_instance(Document, value)
return render_to_string("wagtaildocs/widgets/document_chooser.html", {
'widget': self,
'original_field_html': original_field_html,
'attrs': attrs,
'value': value,
'document': instance,
})
def render_js_init(self, id_, name, value):
return "createDocumentChooser({0});".format(json.dumps(id_))