mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-01 12:04:47 +00:00
Move the snippet chooser HTML markup from snippet_chooser_panel.html entirely within the AdminSnippetChooser widget's render() method
This commit is contained in:
parent
435e4571b3
commit
63dafbe4b7
4 changed files with 24 additions and 9 deletions
|
|
@ -10,7 +10,6 @@ from .widgets import AdminSnippetChooser
|
|||
|
||||
|
||||
class BaseSnippetChooserPanel(BaseChooserPanel):
|
||||
field_template = "wagtailsnippets/edit_handlers/snippet_chooser_panel.html"
|
||||
object_type_name = 'item'
|
||||
|
||||
_content_type = None
|
||||
|
|
|
|||
|
|
@ -1,8 +1,2 @@
|
|||
{% extends "wagtailadmin/edit_handlers/chooser_panel.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block chooser_class %}snippet-chooser{% endblock %}
|
||||
|
||||
{% block chosen_state_view %}
|
||||
<span class="title">{{ item }}</span>
|
||||
{% endblock %}
|
||||
{# Snippet chooser is now implemented as an entirely standard form widget - snippet_chooser_panel.html is redundant #}
|
||||
{% include "wagtailadmin/shared/field.html" %}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
{% extends "wagtailadmin/widgets/chooser.html" %}
|
||||
|
||||
{% block chooser_class %}snippet-chooser{% endblock %}
|
||||
|
||||
{% block chosen_state_view %}
|
||||
<span class="title">{{ item }}</span>
|
||||
{% endblock %}
|
||||
|
|
@ -2,6 +2,7 @@ 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
|
||||
|
|
@ -20,6 +21,20 @@ class AdminSnippetChooser(AdminChooser):
|
|||
if content_type is not None:
|
||||
self.target_content_type = content_type
|
||||
|
||||
def render_html(self, name, value, attrs):
|
||||
original_field_html = super(AdminSnippetChooser, 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("wagtailsnippets/widgets/snippet_chooser.html", {
|
||||
'widget': self,
|
||||
'original_field_html': original_field_html,
|
||||
'attrs': attrs,
|
||||
'value': value,
|
||||
'item': instance,
|
||||
})
|
||||
|
||||
def render_js_init(self, id_, name, value):
|
||||
content_type = self.target_content_type
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue