Allow AdminPageChooser edit link to be hidden, and hide it on the page permissions interface

This commit is contained in:
Matt Westcott 2015-08-12 17:08:22 +01:00
parent 7c26217ea0
commit 7785beecc6
3 changed files with 8 additions and 2 deletions

View file

@ -17,7 +17,9 @@
<li><button type="button" class="action-clear button-small button-secondary">{{ widget.clear_choice_text }}</button></li>
{% endif %}
<li><button type="button" class="action-choose button-small button-secondary">{{ widget.choose_another_text }}</button></li>
<li><a href="{% block edit_chosen_item_url %}#{% endblock %}" class="edit-link button button-small button-secondary" target="_blank">{{ widget.link_to_chosen_text }}</a></li>
{% if widget.show_edit_link %}
<li><a href="{% block edit_chosen_item_url %}#{% endblock %}" class="edit-link button button-small button-secondary" target="_blank">{{ widget.link_to_chosen_text }}</a></li>
{% endif %}
</ul>
</div>

View file

@ -66,6 +66,7 @@ class AdminChooser(WidgetWithScript, widgets.Input):
choose_another_text = _("Choose another item")
clear_choice_text = _("Clear choice")
link_to_chosen_text = _("Edit this item")
show_edit_link = True
def get_instance(self, model_class, value):
# helper method for cleanly turning 'value' into an instance object
@ -106,6 +107,8 @@ class AdminChooser(WidgetWithScript, widgets.Input):
self.clear_choice_text = kwargs.pop('clear_choice_text')
if 'link_to_chosen_text' in kwargs:
self.link_to_chosen_text = kwargs.pop('link_to_chosen_text')
if 'show_edit_link' in kwargs:
self.show_edit_link = kwargs.pop('show_edit_link')
super(AdminChooser, self).__init__(**kwargs)

View file

@ -229,7 +229,8 @@ class GroupForm(forms.ModelForm):
class GroupPagePermissionForm(forms.ModelForm):
page = forms.ModelChoiceField(queryset=Page.objects.all(), widget=AdminPageChooser())
page = forms.ModelChoiceField(queryset=Page.objects.all(),
widget=AdminPageChooser(show_edit_link=False))
class Meta:
model = GroupPagePermission