mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-27 16:14:01 +00:00
Set choose_one_text, choose_another_text and clear_choice_text as overrideable properties on AdminChooser so that we don't have to do template inheritance gymnastics to pass them around
This commit is contained in:
parent
e8246f6c4b
commit
932f532b80
18 changed files with 55 additions and 52 deletions
|
|
@ -348,11 +348,11 @@
|
|||
{% if field.name == 'file' %}
|
||||
{% include "wagtailimages/images/_file_field.html" %}
|
||||
{% elif field.name == 'page_chooser' %}
|
||||
<li>{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=field choose_one_text_str="Choose a page" choose_another_text_str="Choose another page" only %}</li>
|
||||
<li>{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=field only %}</li>
|
||||
{% elif field.name == 'image_chooser' %}
|
||||
<li>{% include "wagtailimages/edit_handlers/image_chooser_panel.html" with field=field choose_one_text_str="Choose an image" choose_another_text_str="Choose another image" only %}</li>
|
||||
<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 choose_one_text_str="Choose a document" choose_another_text_str="Choose another document" only %}</li>
|
||||
<li>{% include "wagtaildocs/edit_handlers/document_chooser_panel.html" with field=field only %}</li>
|
||||
{% else %}
|
||||
{% include "wagtailadmin/shared/field_as_li.html" %}
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -494,14 +494,13 @@ class BaseChooserPanel(BaseFieldPanel):
|
|||
# like every other unpopulated field type. Yay consistency!
|
||||
return None
|
||||
|
||||
def render_as_field(self, extra_context={}):
|
||||
def render_as_field(self):
|
||||
instance_obj = self.get_chosen_item()
|
||||
context = {
|
||||
'field': self.bound_field,
|
||||
self.object_type_name: instance_obj,
|
||||
'is_chosen': bool(instance_obj),
|
||||
}
|
||||
context.update(extra_context)
|
||||
return mark_safe(render_to_string(self.field_template, context))
|
||||
|
||||
|
||||
|
|
@ -536,13 +535,6 @@ class BasePageChooserPanel(BaseChooserPanel):
|
|||
|
||||
return cls._target_content_type
|
||||
|
||||
def render_as_field(self):
|
||||
context = {
|
||||
'choose_another_text_str': ugettext_lazy("Choose another page"),
|
||||
'choose_one_text_str': ugettext_lazy("Choose a page"),
|
||||
}
|
||||
return super(BasePageChooserPanel, self).render_as_field(extra_context=context)
|
||||
|
||||
|
||||
class PageChooserPanel(object):
|
||||
def __init__(self, field_name, page_type=None):
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@
|
|||
|
||||
<div class="actions">
|
||||
{% if not field.field.required %}
|
||||
<input type="button" class="action-clear button-small button-secondary" value="{% block clear_button_label %}{% trans "Clear choice" %}{% endblock %}">
|
||||
<input type="button" class="action-clear button-small button-secondary" value="{{ field.field.widget.clear_choice_text }}">
|
||||
{% endif %}
|
||||
<input type="button" class="action-choose button-small button-secondary" value="{% block choose_another_button_label %}{% trans "Choose another item" %}{% endblock %}">
|
||||
<input type="button" class="action-choose button-small button-secondary" value="{{ field.field.widget.choose_another_text }}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="unchosen">
|
||||
<input type="button" class="action-choose button-small button-secondary" value="{% block choose_button_label %}{% trans "Choose an item" %}{% endblock %}">
|
||||
<input type="button" class="action-choose button-small button-secondary" value="{{ field.field.widget.choose_one_text }}">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,3 @@
|
|||
{% block chosen_state_view %}
|
||||
<span class="title">{{ page.title }}</span>
|
||||
{% endblock %}
|
||||
|
||||
{% block choose_another_button_label %}{{ choose_another_text_str }}{% endblock %}
|
||||
{% block choose_button_label %}{{ choose_one_text_str }}{% endblock %}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,7 @@
|
|||
{% include "wagtailadmin/shared/field_as_li.html" with field=form.new_slug %}
|
||||
|
||||
<li class="{% if form.new_parent_page.field.required %}required{% endif %}">
|
||||
{% trans "Change page" as choose_another_text_str %}
|
||||
{% trans "Choose page" as choose_one_text_str %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.new_parent_page page=parent_page is_chosen=True choose_one_text_str=choose_one_text_str choose_another_text_str=choose_another_text_str only %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.new_parent_page page=parent_page is_chosen=True only %}
|
||||
</li>
|
||||
|
||||
{% if form.copy_subpages %}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import json
|
|||
from django.core.urlresolvers import reverse
|
||||
from django.forms import widgets
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from wagtail.utils.widgets import WidgetWithScript
|
||||
from wagtail.wagtailcore.models import Page
|
||||
|
|
@ -36,10 +37,25 @@ class AdminTagWidget(WidgetWithScript, TagWidget):
|
|||
|
||||
class AdminChooser(WidgetWithScript, widgets.Input):
|
||||
input_type = 'hidden'
|
||||
choose_one_text = _("Choose an item")
|
||||
choose_another_text = _("Choose another item")
|
||||
clear_choice_text = _("Clear choice")
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
# allow choose_one_text / choose_another_text to be overridden per-instance
|
||||
if 'choose_one_text' in kwargs:
|
||||
self.choose_one_text = kwargs.pop('choose_one_text')
|
||||
if 'choose_another_text' in kwargs:
|
||||
self.choose_another_text = kwargs.pop('choose_another_text')
|
||||
if 'clear_choice_text' in kwargs:
|
||||
self.clear_choice_text = kwargs.pop('clear_choice_text')
|
||||
super(AdminChooser, self).__init__(**kwargs)
|
||||
|
||||
|
||||
class AdminPageChooser(AdminChooser):
|
||||
target_content_type = None
|
||||
choose_one_text = _('Choose a page')
|
||||
choose_another_text = _('Choose another page')
|
||||
|
||||
def __init__(self, content_type=None, **kwargs):
|
||||
super(AdminPageChooser, self).__init__(**kwargs)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,3 @@
|
|||
{% block chosen_state_view %}
|
||||
<span class="title">{{ document.title }}</span>
|
||||
{% endblock %}
|
||||
|
||||
{% block clear_button_label %}{% trans "Clear choice" %}{% endblock %}
|
||||
{% block choose_another_button_label %}{% trans "Choose another document" %}{% endblock %}
|
||||
{% block choose_button_label %}{% trans "Choose a document" %}{% endblock %}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,14 @@ from __future__ import absolute_import, unicode_literals
|
|||
|
||||
import json
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from wagtail.wagtailadmin.widgets import AdminChooser
|
||||
|
||||
|
||||
class AdminDocumentChooser(AdminChooser):
|
||||
choose_one_text = _('Choose a document')
|
||||
choose_another_text = _('Choose another document')
|
||||
|
||||
def render_js_init(self, id_, name, value):
|
||||
return "createDocumentChooser({0});".format(json.dumps(id_))
|
||||
|
|
|
|||
|
|
@ -13,7 +13,3 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block clear_button_label %}{% trans "Clear image" %}{% endblock %}
|
||||
{% block choose_another_button_label %}{% trans "Choose another image" %}{% endblock %}
|
||||
{% block choose_button_label %}{% trans "Choose an image" %}{% endblock %}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,15 @@ from __future__ import absolute_import, unicode_literals
|
|||
|
||||
import json
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from wagtail.wagtailadmin.widgets import AdminChooser
|
||||
|
||||
|
||||
class AdminImageChooser(AdminChooser):
|
||||
choose_one_text = _('Choose an image')
|
||||
choose_another_text = _('Choose another image')
|
||||
clear_choice_text = _('Clear image')
|
||||
|
||||
def render_js_init(self, id_, name, value):
|
||||
return "createImageChooser({0});".format(json.dumps(id_))
|
||||
|
|
|
|||
|
|
@ -10,12 +10,10 @@
|
|||
<legend>{% trans "Promoted search result" %}</legend>
|
||||
<ul class="fields">
|
||||
<li class="model_choice_field">
|
||||
{% trans "Choose another page" as choose_another_text_str %}
|
||||
{% trans "Choose a page" as choose_one_text_str %}
|
||||
{% if form.instance.page %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.page page=form.instance.page is_chosen=True choose_one_text_str=choose_one_text_str choose_another_text_str=choose_another_text_str only %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.page page=form.instance.page is_chosen=True only %}
|
||||
{% else %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.page is_chosen=False choose_one_text_str=choose_one_text_str choose_another_text_str=choose_another_text_str only %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.page is_chosen=False only %}
|
||||
{% endif %}
|
||||
</li>
|
||||
<li class="char_field">
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from wagtail.wagtailcore.models import Site
|
||||
from wagtail.wagtailadmin.widgets import AdminPageChooser
|
||||
|
|
@ -7,7 +8,9 @@ from wagtail.wagtailadmin.widgets import AdminPageChooser
|
|||
class SiteForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SiteForm, self).__init__(*args, **kwargs)
|
||||
self.fields['root_page'].widget = AdminPageChooser()
|
||||
self.fields['root_page'].widget = AdminPageChooser(
|
||||
choose_one_text=_('Choose a root page'), choose_another_text=_('Choose a different root page')
|
||||
)
|
||||
|
||||
required_css_class = "required"
|
||||
|
||||
|
|
|
|||
|
|
@ -17,12 +17,10 @@
|
|||
{% include "wagtailadmin/shared/field_as_li.html" with field=form.port %}
|
||||
|
||||
<li>
|
||||
{% trans "Choose a different root page" as choose_another_text_str %}
|
||||
{% trans "Choose a root page" as choose_one_text_str %}
|
||||
{% if form.instance.root_page %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.root_page page=form.instance.root_page is_chosen=True choose_one_text_str=choose_one_text_str choose_another_text_str=choose_another_text_str only %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.root_page page=form.instance.root_page is_chosen=True only %}
|
||||
{% else %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.root_page is_chosen=False choose_one_text_str=choose_one_text_str choose_another_text_str=choose_another_text_str only %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.root_page is_chosen=False only %}
|
||||
{% endif %}
|
||||
</li>
|
||||
|
||||
|
|
|
|||
|
|
@ -18,13 +18,10 @@
|
|||
{% include "wagtailadmin/shared/field_as_li.html" with field=form.port %}
|
||||
|
||||
<li>
|
||||
{% trans "Change page" as choose_another_text_str %}
|
||||
{% trans "Choose page" as choose_one_text_str %}
|
||||
|
||||
{% if form.instance.root_page %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.root_page page=form.instance.root_page is_chosen=True choose_one_text_str=choose_one_text_str choose_another_text_str=choose_another_text_str only %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.root_page page=form.instance.root_page is_chosen=True only %}
|
||||
{% else %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.root_page is_chosen=False choose_one_text_str=choose_one_text_str choose_another_text_str=choose_another_text_str only %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.root_page is_chosen=False only %}
|
||||
{% endif %}
|
||||
</li>
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class BaseSnippetChooserPanel(BaseChooserPanel):
|
|||
@classmethod
|
||||
def widget_overrides(cls):
|
||||
return {cls.field_name: AdminSnippetChooser(
|
||||
content_type=cls.content_type())}
|
||||
content_type=cls.content_type(), snippet_type_name=cls.snippet_type_name)}
|
||||
|
||||
@classmethod
|
||||
def content_type(cls):
|
||||
|
|
|
|||
|
|
@ -6,6 +6,3 @@
|
|||
{% block chosen_state_view %}
|
||||
<span class="title">{% if is_chosen %}{{ item }}{% endif %}</span>
|
||||
{% endblock %}
|
||||
|
||||
{% block choose_another_button_label %}{% blocktrans %}Choose another {{ snippet_type_name }}{% endblocktrans %}{% endblock %}
|
||||
{% block choose_button_label %}{% blocktrans %}Choose {{ snippet_type_name }}{% endblocktrans %}{% endblock %}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ from __future__ import absolute_import, unicode_literals
|
|||
|
||||
import json
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from wagtail.wagtailadmin.widgets import AdminChooser
|
||||
|
||||
|
||||
|
|
@ -9,6 +11,11 @@ class AdminSnippetChooser(AdminChooser):
|
|||
target_content_type = None
|
||||
|
||||
def __init__(self, content_type=None, **kwargs):
|
||||
if 'snippet_type_name' in kwargs:
|
||||
snippet_type_name = kwargs.pop('snippet_type_name')
|
||||
self.choose_one_text = _('Choose %s') % snippet_type_name
|
||||
self.choose_another_text = _('Choose another %s') % snippet_type_name
|
||||
|
||||
super(AdminSnippetChooser, self).__init__(**kwargs)
|
||||
if content_type is not None:
|
||||
self.target_content_type = content_type
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
{% load i18n %}
|
||||
|
||||
<td>
|
||||
{% trans "Edit page" as choose_another_text_str %}
|
||||
{% trans "Choose page" as choose_one_text_str %}
|
||||
|
||||
{% if form.instance.page %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.page page=form.instance.page is_chosen=True choose_one_text_str=choose_one_text_str choose_another_text_str=choose_another_text_str only %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.page page=form.instance.page is_chosen=True only %}
|
||||
{% else %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.page is_chosen=False choose_one_text_str=choose_one_text_str choose_another_text_str=choose_another_text_str only %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.page is_chosen=False only %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
|
|
|
|||
Loading…
Reference in a new issue